I have a Rails app that works fine in ElasticBeanstalk. I am now trying to run in in the Docker Phusion Passenger Container.
My Dockerfile is pretty simple:
FROM phusion/passenger-ruby21:0.9.13
# Set correct environment variables.
ENV HOME /root
# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]
RUN rm -f /etc/service/nginx/down
RUN rm /etc/nginx/sites-enabled/default
ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf
#Preserver Env Vars set at run time
ADD passenger-envvars.conf /etc/nginx/main.d/passenger-envvars.conf
ENV APP_HOME /home/app/webapp/
RUN mkdir $APP_HOME
WORKDIR /tmp
ADD Gemfile /tmp/
ADD Gemfile.lock /tmp/
RUN bundle install
ADD . $APP_HOME
When I run the container, Passenger gives me the following error:
undefined method `[]' for nil:NilClass (NoMethodError)
/home/app/webapp/config/environment.rb:11:in `<top (required)>'
config.ru:3:in `require'
config.ru:3:in `block in <main>'
/var/lib/gems/2.1.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `instance_eval'
/var/lib/gems/2.1.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `eval'
/usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `preload_app'
/usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:App>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'
My environment.rb file is:
require File.expand_path('../application', __FILE__)
if ENV['C_ENVIRONMENT']
%w(RACK_ENV RAILS_ENV).each do |key|
ENV[key] = ENV['C_ENVIRONMENT']
end
Rails.env = ENV['C_ENVIRONMENT'] if defined?(Rails)
end
CONFIG = YAML.load(ERB.new(File.read("config/config.yml")).result)[Rails.env]
T_CONFIG = CONFIG["tableau"]
CM_CONFIG = CONFIG["customer_metadata"]
LDAP_CONFIG = CONFIG["ldap"]
# Initialize the rails application
Ecommerce::Application.initialize!
I've confirmed that NGinx is preserving all the Environment Variables that I need. The difficultly seems to be with this line (line 11):
CONFIG = YAML.load(ERB.new(File.read("config/config.yml")).result)[Rails.env]
The config/config.yml file exists, and had the necessary config to match the RAILS_ENV variable that is being passed to it.
My suspicion is that the Docker container is having difficultly reading a file into memory, perhaps due to the way bundle install is being run as root, and is not creating the necessary CONFIG object for Rails to read.
I am not a Ruby developer (I'm Operations), so please forgive any absence of basic Ruby knowledge.