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

No such file or directory - bs_fetch:atomic_write_cache_file:chmod - Error building app with Docker in development #262

Closed
mayordwells opened this issue Jun 14, 2019 · 9 comments

Comments

@mayordwells
Copy link

mayordwells commented Jun 14, 2019

I've used the latest version 1.4.4 and even the edge version on master but my app refuses to successfully build or startup.
Here's my Dockerfile:

FROM phusion/passenger-ruby26:1.0.5

RUN curl -sL https://deb.nodesource.com/setup_11.x | bash
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

# Set correct environment variables.
ENV HOME /root

# Additional packages
RUN apt-get update && apt-get install -y -o Dpkg::Options::="--force-confold" openssl \
  build-essential \
  xorg \
  libssl-dev \
  nodejs \
  yarn \
  libxrender-dev \
  wget \
  postgresql-client \
  tzdata \
  xvfb \
  libfontconfig \
  libjpeg-turbo8 \
  xfonts-75dpi \
  fontconfig \
  nano \
  wkhtmltopdf

# Enable Nginx and Passenger
RUN rm -f /etc/service/nginx/down

# Add virtual host entry for the application
RUN rm /etc/nginx/sites-enabled/default
ADD welds.conf /etc/nginx/sites-enabled/welds.conf

# In case we need some environmental variables in Nginx
ADD rails-env.conf /etc/nginx/main.d/rails-env.conf

# Extra config
ADD nginx-extra.conf /etc/nginx/conf.d/nginx-extra.conf

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8

# RUN whoami
# RUN su app
# USER app
# Install gems: it's better to build an independent layer for the gems
# so they are cached during builds unless Gemfile changes
RUN gem install bundler && gem install foreman
WORKDIR /tmp
ADD Gemfile* /tmp/
RUN bundle install --jobs 20 --retry 5

EXPOSE 80

# Copy application into the container and use right permissions: passenger
# uses the app user for running the application
RUN mkdir /home/app/welds
COPY --chown=app:app . /home/app/welds
WORKDIR /home/app/welds

ARG RAILS_ENV
ARG RAILS_MASTER_KEY=xxxx
RUN bundle exec rake assets:precompile

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN chmod -R go+w /home/app/welds/tmp/cache

# Use baseimage-docker's init process.
CMD bundle exec foreman start -f Procfile.prod

And here's my docker-compose.yml file:

version: '3'
volumes:
  bundle_cache:
    driver: local
  node_modules_cache:
    driver: local
  redis:
    driver: local

services:
  db:
    image: postgres:11.2
    environment:
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_USER=postgres
      - DATABASE_PORT=5432
      - POSTGRES_DB=welds_development
      - DATABASE_HOST=db
    volumes:
      - db_data

  db_data:
    image: postgres:11.2
    volumes:
      - /var/lib/postgresql/data
    command: /bin/true

  redis:
    image: redis:latest
    ports:
      - '6379:6379'
    volumes:
      - redis:/data

  db_migrate:
    build:
      context: .
    depends_on:
      - db
    environment:
      - PASSENGER_APP_ENV=development
    command: ['./wait-for-postgres.sh', 'db', 'bin/rails', 'db:migrate db:seed']

 web:
    build: .
    image: web:latest
    entrypoint: ['/home/app/welds/docker-web-entrypoint-dev.sh']
    command: bundle exec foreman start -f Procfile
    depends_on:
      - redis
      - db
      - db_migrate
    ports:
      - '80:80'
    env_file:
      - '.env'
    environment:
      - PASSENGER_APP_ENV=development
      - RAILS_LOG_TO_STDOUT=true
      - WEBPACKER_DEV_SERVER_HOST=webpacker
      - RAILS_ENV=development
    volumes:
      - bundle_cache:/usr/local/bundle
      - node_modules_cache:/home/app/welds/node_modules
      - .:/home/app/welds:cached
    tty: true
    stdin_open: true

  webpacker:
    build:
      context: .
      dockerfile: Dockerfile-webpacker
    entrypoint: ['/home/app/welds/docker-webpacker-entrypoint-dev.sh']
    command: bundle exec ./bin/webpack-dev-server
    volumes:
      - bundle_cache:/usr/local/bundle
      - node_modules_cache:/home/app/welds/node_modules
      - .:/home/app/welds:cached
    ports:
      - '3035:3035'
    env_file:
      - '.env'
    environment:
      - WEBPACKER_DEV_SERVER_HOST=0.0.0.0

My Gemfile:
Tried this:
gem 'bootsnap', '>= 1.4.4', require: false
And this in my Gemfile but both are producing the same error
gem 'bootsnap', :git => 'https://github.com/Shopify/bootsnap', :branch => 'master',

And here's the error i've been getting for a few days:

web_1         | 11:31:39 worker.1 | No such file or directory - bs_fetch:atomic_write_cache_file:chmod
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/compile_cache/iseq.rb:37:in `fetch'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/compile_cache/iseq.rb:37:in `load_iseq'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `block in require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:268:in `load_dependency'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/nokogiri-1.10.3/lib/nokogiri/xml.rb:18:in `<main>'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `block in require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:268:in `load_dependency'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/nokogiri-1.10.3/lib/nokogiri.rb:36:in `<main>'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `block in require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:268:in `load_dependency'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/actiontext-6.0.0.rc1/lib/action_text.rb:6:in `<main>'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `block in require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:268:in `load_dependency'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/actiontext-6.0.0.rc1/lib/action_text/engine.rb:8:in `<main>'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `block in require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:268:in `load_dependency'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/railties-6.0.0.rc1/lib/rails/all.rb:21:in `block in <main>'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/railties-6.0.0.rc1/lib/rails/all.rb:19:in `each'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/railties-6.0.0.rc1/lib/rails/all.rb:19:in `<main>'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bundler/gems/bootsnap-b4def902b6fc/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `block in require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:268:in `load_dependency'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `require'
web_1         | 11:31:39 worker.1 | /home/app/welds/config/application.rb:3:in `<top (required)>'
web_1         | 11:31:39 worker.1 | /home/app/welds/config/environment.rb:2:in `require_relative'
web_1         | 11:31:39 worker.1 | /home/app/welds/config/environment.rb:2:in `<top (required)>'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `block in require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:268:in `load_dependency'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `require'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/sidekiq-5.2.7/lib/sidekiq/cli.rb:288:in `boot_system'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/sidekiq-5.2.7/lib/sidekiq/cli.rb:46:in `run'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/gems/sidekiq-5.2.7/bin/sidekiq:12:in `<top (required)>'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bin/sidekiq:23:in `load'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bin/sidekiq:23:in `<main>'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bin/ruby_executable_hooks:24:in `eval'
web_1         | 11:31:39 worker.1 | /usr/local/rvm/gems/ruby-2.6.2/bin/ruby_executable_hooks:24:in `<main>'
web_1         | 11:31:39 worker.1 | exited with code 1
web_1         | 11:31:39 system   | sending SIGTERM to all processes
web_1         | 11:31:39 web.1    | terminated by SIGTERM
welds_web_1 exited with code 0

Any idea how to fix this error, please?

@burke
Copy link
Member

burke commented Jun 14, 2019

It likely has something to do with the application source (and therefore ./tmp/bootsnap*) being in a volume. This looks like a bug, but even so, performance would probably suck in this situation. Try passing cache_dir to Bootsnap.setup to map it to somewhere that isn't in a volume, maybe /tmp/cache.

@amitsaxena
Copy link

I am getting this error as well, and it most likely is because the volume shared with docker container isn't available to write yet (to tmp/cache), and probably takes some time after container start to be available. Haven't found a solution yet.

@amitsaxena
Copy link

As a temporary fix, I am using the following strategy to disable it in the docker container where is fails. I have changed the require to:

if ENV.fetch("ENABLE_BOOTSNAP", "true") == "true"
  require "bootsnap/setup"
end

And then in my docker compose file, I pass the environment variable for the affected container using:

  sidekiq:
    container_name: sidekiq
    build: .
    volumes:
      - .:/apps/myapp
    command: bundle exec eye l -f ./config/sidekiq.eye
    depends_on:
      - db
      - redis
      - elasticsearch
      - web
    environment:
      - ENABLE_BOOTSNAP=false

@EnziinSystem
Copy link

As a temporary fix, I am using the following strategy to disable it in the docker container where is fails. I have changed the require to:

if ENV.fetch("ENABLE_BOOTSNAP", "true") == "true"
  require "bootsnap/setup"
end

And then in my docker compose file, I pass the environment variable for the affected container using:

  sidekiq:
    container_name: sidekiq
    build: .
    volumes:
      - .:/apps/myapp
    command: bundle exec eye l -f ./config/sidekiq.eye
    depends_on:
      - db
      - redis
      - elasticsearch
      - web
    environment:
      - ENABLE_BOOTSNAP=false

Why you not remove the bootsnap gem in Gemfile and require command?

@amitsaxena
Copy link

amitsaxena commented Jan 24, 2020

@EnziinSystem because the codebase is used by others who have local dev environments set up (without docker) and I didn't want to mess it up for them. Also we didn't want to lose the benefits of bootsnap for production environment.

@EnziinSystem
Copy link

@EnziinSystem because the codebase is used by others who have local dev environments set up (without docker) and I didn't want to mess it up for them. Also we didn't want to lose the benefits of bootsnap for production environment.

I understand you disable in the sidekiq container and you still enable it in the main application, isn't it?

@ckornaros
Copy link

I have the same issue and it's very annoying... Someone is working on a fix about this issue ?

@EnziinSystem
Copy link

I have the same issue and it's very annoying... Someone is working on a fix about this issue ?

I solved the problem.

  project_service_dev:
...
    environment:
      - RAILS_ENV=development
      - RAKE_ENV=development
      - PORT=3000
      - ENABLE_BOOTSNAP=true
...
  sidekiq_project_dev:
...
    environment:
      - RAILS_ENV=development
      - RAKE_ENV=development
      - ENABLE_BOOTSNAP=false
...

In the boot .rb config

require 'bootsnap/setup' if ENV.fetch("ENABLE_BOOTSNAP", "true") == "true"

@casperisfine
Copy link
Contributor

Closing in favor of #353, more investigation happened there, and at this point we believe it is caused by a race conditions when multiple process use the same cache directory.

That other issue also include an experimental fix, that I'd appreciate if people suffering from this problem could experiment with and report back.

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

No branches or pull requests

6 participants