phusion / passenger-docker

Docker base images for Ruby, Python, Node.js and Meteor web apps
MIT License
2.78k stars 408 forks source link

Setting PASSENGER_APP_ENV **does not** set RAILS_ENV to same value #300

Closed ortonomy closed 4 years ago

ortonomy commented 4 years ago

Running a rails app inside this container, and doing some build stuff around it.

Either way, once it launches, RAILS_ENV is always set to production. This is not how the read me says it should be?

This doesn't work either:

# /etc/nginx/sites-enabled/webapp.conf:
server {
    ...
    # Ensures that RAILS_ENV, NODE_ENV, etc are set to "staging"
    # when your application is started.
    passenger_app_env development;
}

Dockerfile

FROM phusion/passenger-ruby26

# Set correct environment variables.
ENV HOME /root
ENV RAILS_SERVE_STATIC_FILES false
ENV RAILS_LOG_TO_STDOUT true
ENV PASSENGER_APP_ENV development

# WHO WROTE THISs
LABEL maintainer="Gregory Orton <ortonomy.dev@gmail.com>"

# Use baseimage-docker's init process.

COPY ./docker/development/20_persist_app_env.sh /etc/my_init.d
CMD ["/sbin/my_init"]

# Ruby 2.6.6
RUN bash -l -c 'rvm --default use ruby-2.6.6'

# Update OS if possible
RUN apt-get update && apt-get upgrade -y -o Dpkg::Options::="--force-confold"

# download and dependencies for building
RUN apt-get install -y build-essential devscripts wget

# download and install imagemagick
WORKDIR /tmp
RUN apt-get install -y libltdl-dev

RUN wget https://www.imagemagick.org/download/ImageMagick.tar.gz
RUN tar -xvf ImageMagick.tar.gz && rm ImageMagick.tar.gz
RUN mv $(ls | grep ImageMagick) imagemagick
WORKDIR /tmp/imagemagick
RUN ./configure --with-modules=yes
RUN make && make install && ldconfig /usr/local/lib

# download and install dependencies and build libvips
# https://renchap.com/blog/post/building_recent_libvips_on_debian/
WORKDIR /tmp
RUN apt-get update && apt-get install -y libexpat-dev glib2.0-dev libjpeg-dev libexif-dev libgif-dev librsvg2-bin libtiff-dev libpng-dev libwebp-dev
RUN wget https://github.com/libvips/libvips/releases/download/v8.10.1/vips-8.10.1.tar.gz
RUN tar xf vips-8.10.1.tar.gz
WORKDIR /tmp/vips-8.10.1
RUN ./configure
RUN make && make install && ldconfig

# Install dependencies
RUN apt-get install -y postgresql-client tzdata

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

# Create app dir
RUN mkdir /home/app/entertwine-api
WORKDIR /home/app/entertwine-api

# Bundle gem install
COPY Gemfile Gemfile.lock ./
RUN bundle install --jobs 20 --retry 5 --binstubs

# set up nginx
RUN rm /etc/nginx/sites-enabled/default
COPY --chown=app:app ./docker/development/webapp.conf /etc/nginx/sites-enabled/webapp.conf

# add other nginx vars
COPY --chown=app:app ./docker/development/rails-env.conf /etc/nginx/main.d/

# Copy app
COPY --chown=app:app . /home/app/entertwine-api

COPY --chown=app:app ./docker/development/database.yml ./config/database.yml

# Enable the Nginx service.
RUN rm -f /etc/service/nginx/down

# Run sidekiq
RUN mkdir /etc/service/sidekiq
ADD ./docker/sidekiq.sh /etc/service/sidekiq/run
ortonomy commented 4 years ago

Hmm, actually it does. It was my fault for misconfiguring my database.yml file