简体   繁体   中英

bin/rails doesn't respect RAILS_ENV (Rails 5.2)

I am looking for pointers at what appears to be some sort of configuration problems. Please also point me to duplicate questions that I wasn't able to find.

I'm almost entirely sure my own ignorance of the inner workings of the Rails and/or bundler environment is to blame...

So I have a rather simplistic Rails production setup with a Dockerfile that looks like this:

FROM ruby

ENV RAILS_ENV production
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev curl ffmpeg mupdf gcc g++ make git imagemagick
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
RUN apt-get update -qq && apt-get install -y nodejs

RUN bundle config --global frozen 1
RUN npm install -g yarn

WORKDIR /usr/src/app

COPY Gemfile Gemfile.lock ./
RUN bundle install --without development test --path vendor/bundle

COPY . .

EXPOSE 3000

When I run this with

$ docker run --rm -ti -e RAILS_MASTER_KEY=$RAILS_MASTER_KEY my-rails-image bash

and try to open a console, it complains about missing gems from the development and test groups. I honestly don't know where to start looking for debugging this... Can some initializer be the cause? Can I override them to start rails without initializers to see if that is the problem?

root@d23a9edca766:/usr/src/app# echo $RAILS_ENV
production
root@d23a9edca766:/usr/src/app# bin/rails c
Could not find abstract_type-0.0.7 in any of the sources
Run `bundle install` to install missing gems.

Found the answer here: bundler incorrectly trying to install "development" and "test" group gems in production

In short, the

COPY . .

line in the Dockerfile overwrote the .bundle/config file which hosts all bundler options for this project:

---
BUNDLE_FROZEN: "true"
BUNDLE_PATH: "vendor/bundle"
BUNDLE_WITHOUT: "development:test"

So I just added it to my .dockerignore - now everything works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM