简体   繁体   English

bin / rails不尊重RAILS_ENV(Rails 5.2)

[英]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... 我几乎完全可以肯定,我对Rails和/或捆绑器环境的内部运作的无知是应该归咎于...

So I have a rather simplistic Rails production setup with a Dockerfile that looks like this: 因此,我使用了一个如下所示的Dockerfile来简化Rails生产设置:

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? 我可以重写它们以在没有初始化程序的情况下启动rails看看是否是问题所在吗?

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 在这里找到答案: 捆绑程序错误地尝试在生产中安装“开发”和“测试”组gem

In short, the 简而言之,

COPY . .

line in the Dockerfile overwrote the .bundle/config file which hosts all bundler options for this project: Dockerfile中的一行覆盖了.bundle/config文件,该文件托管了该项目的所有捆绑程序选项:

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

So I just added it to my .dockerignore - now everything works. 所以我只是将其添加到我的.dockerignore现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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