rails / webpacker

Use Webpack to manage app-like JavaScript modules in Rails
MIT License
5.3k stars 1.47k forks source link

Railtie yarn check --integrity fails running in development under docker #1568

Closed sauy7 closed 4 years ago

sauy7 commented 6 years ago

Software versions:

Docker for Mac: 18.03.1-ce-mac65 (24312)
ruby: 2.5.1
rails: 5.2.0
webpacker: 3.5.3

Expected behaviour:

I would expect a new containerised Rails 5.2 application to pass the yarn integrity check when starting the application.

Note: Running puma -C config/puma.rb natively on the host Mac OS X does not trigger this issue.

Actual behaviour:

Same error as reported in #1374. When running the rails development server:

========================================
  Your Yarn packages are out of date!
  Please run `yarn install` to update.
========================================

Steps to reproduce:

  1. Create a new Rails 5.2 application, specifying --webpack (other options used in example to reduce the number of moving parts)
$ rails new webpacker-example --webpack --skip-active-record --skip-action-mailer --skip-active-storage --skip-action-cable --skip-turbolinks --skip-test --skip-system-test --no-rc
$ cd webpacker-example
$ yarn install
  1. Add .dockerignore, Dockerfile, .env.docker and docker-compose.yml files as per this gist: https://gist.github.com/sauy7/d5c732faad876fde8b2d16672b29a992

  2. Run:

    docker-compose up --build

Note in the output that:

RUN yarn check --integrity

shows:

yarn check v1.7.0
success Folder in sync.
Done in 0.XXs.
  1. Wait for Rails to try to fully start up.

  2. Observe in server output:

========================================
  Your Yarn packages are out of date!
  Please run `yarn install` to update.
========================================
  1. Note in config/environments/development.rb:

    config.webpacker.check_yarn_integrity = true

  2. Edit to:

    config.webpacker.check_yarn_integrity = false

  3. Re-run:

    docker-compose up --build

  4. Browse to http://localhost:3000 to see the default Rails home page.

mhbsti commented 6 years ago

Hi. I have the same problem.

@sauy7 , got any solutions?

Thanks.

sauy7 commented 6 years ago

@mhbsti None, other than running with config.webpacker.check_yarn_integrity = false in development.rb as a workaround.

mhbsti commented 6 years ago

Thank you @sauy7 . If my find any public solution here.

andreynering commented 6 years ago

Same problem here, but outside Docker

jemminger commented 6 years ago

Same problem, deploying to Heroku

dylangrafmyre commented 6 years ago

Same problem with running rails in my docker local development.

amiuhle commented 5 years ago

Seems like the problem are different bindings for node-sass (and possibly other packages that depend on native libs).

docker exec container yarn check --integrity fails for me with the message "warning Integrity check: Linked modules don't match".

ls node_modules/node-sass/vendor
linux-x64-67

docker exec container ls node_modules/node-sass/vendor/
linux-x64-64
linux-x64-67

Edit: Possible workarounds:

lucasdeassis commented 5 years ago

same problem outside docker

IlkhamGaysin commented 5 years ago

:+1: same on dev without docker

kulte commented 5 years ago

What have people done to solve this. It literally just showed up today and I have no idea what I should do!

schodevio commented 5 years ago

Try: docker-compose run <service_name_here> yarn

connorshea commented 5 years ago

I had this problem but config.webpacker.check_yarn_integrity = false didn't seem to fix it. For anyone else that's an idiot like me, the check_yarn_integrity config needs to be changed in config/environments/development.rb, not config/webpacker.yml. 🤦‍♂️

zhengpd commented 5 years ago

~I put /node_modules into .dockerignore file and the problem is gone. Not sure if this is a general solution.~

Edited: not a solution since docker compose ignores .dockerignore for volume mount. The problem gone by coincidence at that time.

thephw commented 5 years ago

The command it runs if you want to shell into the running container is yarn check --integrity && yarn check --verify-tree. I removed RUN ./bin/webpack from my Dockerfile and this error went away, but I'm confused as to why that would happen.

zhengpd commented 5 years ago

The integrity failure comes because docker compose ignores .dockerignore for volume mount, which includes node_modules.

volumes:
  - '.:/usr/src/app'

Error occurs this time since the node modules are not for container environment.

After you run docker-compose run <service_name_here> yarn, the node_modules on host machine would be updated according to the container environment since yarn is run inside container. The error would be gone when trying docker-compose up --build again.

A solution could be to avoid node_modules overlay by using anonymous volume:

volumes:
  - '.:/usr/src/app'
  - '/usr/src/app/node_modules'
thephw commented 5 years ago

It still occurs with volume overlays is the baffling part. Our workflow also doesn't involve a local node install so there isn't a local ./app/node_modules folder anyways. Ended up disabling it because the later deployed version is installed with yarn install --frozen-lock and doesn't have any issues 🤷‍♂

volumes:
      - ./app:/app:cached
      - /app/node_modules
omarsotillo commented 5 years ago

It still happens 😢

As @connorshea suggested removing the check_yarn_integrity in development fixed, but I don't think is the best way to go.

dmolesUC commented 5 years ago

What are the down sides of setting config.webpacker.check_yarn_integrity = false in development? Assuming @zpdsky's explanation is correct, is this likely to lead to a situation where yarn on the host OS (e.g. macOS) installs JS modules that won't behave properly on the container OS, or vice versa?

omarsotillo commented 5 years ago

@dmolesUC It often saved me already when running bin/webpacker or rails server with outdated dependencies, so in general it makes sense to have it enabled on development.

etiennevvv commented 4 years ago

Any solutions???

jmadkins commented 4 years ago

Thanks @zhengpd! Your suggestion worked with rails 5.2.4.1, docker 19.03.8, and yarn 1.17.3.

rafaeljcadena commented 4 years ago

What worked for me is not to COPY the yarn.lock to the image by Dockerfile.

yarn.lock must be generate after Dockerfile execute "RUN yarn install". Try remove yarn.lock from your project too and run the "docker-compose up --build" again.

jmadkins commented 4 years ago

@rafaeljcadena That seemed to do the trick!

viktorianer commented 4 years ago

What worked for me is not to COPY the yarn.lock to the image by Dockerfile.

yarn.lock must be generate after Dockerfile execute "RUN yarn install". Try remove yarn.lock from your project too and run the "docker-compose up --build" again.

But, then you install not the same Versions. Which may not be what you want.

rafaeljcadena commented 4 years ago

What worked for me is not to COPY the yarn.lock to the image by Dockerfile. yarn.lock must be generate after Dockerfile execute "RUN yarn install". Try remove yarn.lock from your project too and run the "docker-compose up --build" again.

But, then you install not the same Versions. Which may not be what you want.

Yes, you can't guarantee the exactly version as in yarn.lock, but in package.json you have the lib versions with safe range.

Uin-Lee commented 4 years ago

thanks. i love you

nachoal commented 4 years ago

Trying @rafaelfranca suggestion did the trick, here's the end result for my Dockerfile

FROM ruby:2.6

LABEL maintainer="i@codia.co"

# YARN repository
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

# Convention to use update and install on same line to actually install new packages
# We also use the line separation to make this easier to change
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
nodejs \
yarn

COPY Gemfile* /usr/src/app/
COPY package.json /usr/src/app/

WORKDIR /usr/src/app
RUN bundle install
RUN yarn install
COPY yarn.lock /usr/src/app/
COPY . /usr/src/app/

CMD ["bin/rails", "s", "-b", "0.0.0.0"]

And the docker-compose:

version: '3'

services:
  web:
    build: .
    ports:
    - "3000:3000"
rossta commented 4 years ago

@sauy7 Can this issue be closed? The integrity check was removed in #2518

sauy7 commented 4 years ago

go for it

stevecondylios commented 3 years ago

What does the yarn integrity check do? Are there consequences/risks for disabling it?