Skip to content

Instantly share code, notes, and snippets.

@alexesDev
Last active May 17, 2019 09:45
Show Gist options
  • Save alexesDev/f1630f30f10dbb95b18d2da03dc3ec61 to your computer and use it in GitHub Desktop.
Save alexesDev/f1630f30f10dbb95b18d2da03dc3ec61 to your computer and use it in GitHub Desktop.
Multi-stage Dockerfile for Rails 5.2
.git
.gitignore
Dockerfile
log
tmp
public/system
FROM ruby:2.6.3-alpine3.9 AS base
RUN apk --update add tzdata postgresql-dev libxslt-dev libxml2-dev imagemagick
WORKDIR /app
# bundle install
FROM base as bundler
RUN apk --update add build-base
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN echo 'gem: --no-rdoc --no-ri' > ~/.gemrc && \
bundle install --no-cache --without development test --jobs 2
# build assets
FROM bundler AS assets
RUN apk --update add nodejs yarn
ENV RAILS_ENV=production
COPY config ./config
COPY package.json Rakefile ./
COPY app/assets ./app/assets
RUN SKIP_ALL_ROUTES=yes bundle exec rake assets:precompile
# final image
FROM base as final
ENV EXECJS_RUNTIME=Disabled RAILS_ENV=production
COPY --from=bundler /usr/local/bundle /usr/local/bundle
COPY --from=assets /app/public/assets ./public/assets
COPY . .
CMD ["/app/bin/rails", "server"]
Rails.application.routes.draw do
return if ENV['SKIP_ALL_ROUTES']
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment