Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sauy7 opened this issue Jun 12, 2018 · 31 comments
Closed

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

sauy7 opened this issue Jun 12, 2018 · 31 comments

Comments

@sauy7
Copy link

sauy7 commented Jun 12, 2018

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
Copy link

mhbsti commented Jun 19, 2018

Hi. I have the same problem.

@sauy7 , got any solutions?

Thanks.

@sauy7
Copy link
Author

sauy7 commented Jun 19, 2018

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

@mhbsti
Copy link

mhbsti commented Jun 19, 2018

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

@andreynering
Copy link

Same problem here, but outside Docker

@jemminger
Copy link

Same problem, deploying to Heroku

@dylangrafmyre
Copy link

Same problem with running rails in my docker local development.

@amiuhle
Copy link

amiuhle commented Nov 14, 2018

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:

  • Delete node_modules before building (also delete relevant volumes, eg docker-compose down && docker volume prune)
  • If already on linux-x64, use matching node versions

@lucasdeassis
Copy link

same problem outside docker

@IlkhamGaysin
Copy link

👍 same on dev without docker

@kulte
Copy link

kulte commented Jan 25, 2019

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

@schodevio
Copy link

schodevio commented Feb 1, 2019

Try: docker-compose run <service_name_here> yarn

@connorshea
Copy link
Contributor

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
Copy link

zhengpd commented Aug 3, 2019

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
Copy link

thephw commented Aug 15, 2019

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
Copy link

zhengpd commented Aug 15, 2019

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

  • When creating a new Rails application and run yarn install, a node_modules folder is created according to the host environment.
  • And for the first time to run docker-compose up --build, the node_modules folder inside docker container would be overlaid by the one from host machine, because of the volume mount:
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
Copy link

thephw commented Aug 16, 2019

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
Copy link

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
Copy link

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
Copy link

@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
Copy link

Any solutions???

@jmadkins
Copy link

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

@rafaeljcadena
Copy link

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
Copy link

@rafaeljcadena That seemed to do the trick!

@viktorianer
Copy link

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
Copy link

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
Copy link

Uin-Lee commented May 12, 2020

thanks. i love you

@nachoal
Copy link

nachoal commented May 30, 2020

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"

@nachoal
Copy link

nachoal commented May 31, 2020

This also fails when deploying to production ended up modifying the image like this:

FROM ruby:2.6

LABEL maintainer="ignacio@codia.co"

# Allow apt to work with https-based sources
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
  apt-transport-https


# Ensure we install an up-to-date version of Node
# see https://github.com/yarnpkg/yarn/issues/2888
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -

# Ensure latest packages for Yarn
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

ENV BUNDLE_PATH /gems

RUN bundle install

COPY package.json yarn.lock ./
RUN yarn install --check-files

COPY . /usr/src/app/



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

the workaround is the COPY package.json yarn.lock ./
and RUN yarn install --check-files

@rossta
Copy link
Member

rossta commented Aug 28, 2020

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

@sauy7
Copy link
Author

sauy7 commented Aug 28, 2020

go for it

@stevecondylios
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests