Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ARG RUBY_VER=2.5.1
- ARG APP_PATH=/usr/src/app
- ARG ENVIRONMENT=production
- ##################
- # Stage: Builder
- ##################
- FROM ruby:${RUBY_VER}-alpine as builder
- # Set working dir
- ARG APP_PATH
- RUN mkdir $APP_PATH
- WORKDIR $APP_PATH
- # Set environment
- ARG ENVIRONMENT
- ENV RAILS_ENV $ENVIRONMENT
- ENV NODE_ENV $ENVIRONMENT
- # Install build dependencies
- RUN apk --update add --no-cache \
- build-base \
- # For nokogiri
- libxml2-dev libxslt-dev \
- # For uglifier & webpacker
- nodejs \
- # For postgresql
- postgresql-dev \
- # For tzinfo-data
- tzdata \
- # For webpacker
- yarn
- # Bundle gems
- COPY Gemfile Gemfile.lock $APP_PATH/
- RUN if [[ "$RAILS_ENV" == "production" ]]; \
- then bundle install --jobs "$(getconf _NPROCESSORS_ONLN)" --retry 5 --without development test; \
- else bundle install --jobs "$(getconf _NPROCESSORS_ONLN)" --retry 5; \
- fi
- # Install Javascript packages
- COPY package.json yarn.lock $APP_PATH/
- RUN if [[ "$NODE_ENV" == "production" ]]; \
- then yarn install --frozen-lockfile --production; \
- else yarn install --frozen-lockfile; \
- fi \
- && yarn cache clean
- COPY . $APP_PATH/
- # Precompile assets
- RUN if [[ "$RAILS_ENV" == "production" ]]; \
- then bundle exec rails assets:precompile; \
- fi
- # Cleanup
- RUN rm -rf node_modules tmp/* log/* /usr/local/bundle/cache/*.gem \
- && find /usr/local/bundle/gems/ -name "*.c" -delete \
- && find /usr/local/bundle/gems/ -name "*.o" -delete
- ##################
- # Stage: Final app
- ##################
- FROM ruby:${RUBY_VER}-alpine
- ARG APP_PATH
- ENV PATH $APP_PATH/bin:$PATH
- ENV RAILS_LOG_TO_STDOUT true
- # Set working dir
- RUN mkdir $APP_PATH
- WORKDIR $APP_PATH
- # Install runtime dependencies
- RUN apk --update add --no-cache \
- # For Active Storage
- imagemagick \
- # For uglifier & webpacker
- nodejs \
- # For postgresql
- postgresql-dev \
- # For tzinfo-data
- tzdata
- # Set environment
- ARG ENVIRONMENT
- ENV RAILS_ENV $ENVIRONMENT
- ENV NODE_ENV $ENVIRONMENT
- COPY --from=builder $APP_PATH $APP_PATH
- COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
- # Tighten security
- RUN chown -R nobody:nogroup $APP_PATH
- USER nobody
- CMD ["bundle", "exec", "rails", "s", "-p", "3000", "-b", "0.0.0.0"]
Add Comment
Please, Sign In to add comment