-
-
Save dharamgollapudi/096e34fdb152985509d20e76fedd1ccd to your computer and use it in GitHub Desktop.
Sample of multistage Dockerfile for Rails app in production
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM madnight/docker-alpine-wkhtmltopdf as wkhtmltopdf_savior | |
# STAGE for bundle & yarn install | |
FROM ruby:2.4.3-alpine3.7 as builder | |
ENV CA_CERTS_PATH /etc/ssl/certs/ | |
ENV RAILS_ENV production | |
ENV RAILS_LOG_TO_STDOUT true | |
ENV RAILS_SERVE_STATIC_FILES true | |
RUN apk add --no-cache \ | |
build-base \ | |
busybox \ | |
ca-certificates \ | |
curl \ | |
git \ | |
gnupg1 \ | |
graphicsmagick \ | |
libffi-dev \ | |
libsodium-dev \ | |
nodejs=8.9.3-r0 \ | |
openssh-client \ | |
postgresql-dev \ | |
rsync \ | |
yarn | |
RUN mkdir -p /app | |
WORKDIR /app | |
COPY Gemfile Gemfile.lock /app/ | |
ARG SSH_CHECKOUT_KEY | |
RUN mkdir /root/.ssh/ \ | |
&& echo "${SSH_CHECKOUT_KEY}" > /root/.ssh/id_rsa \ | |
&& chmod 400 /root/.ssh/id_rsa \ | |
&& touch /root/.ssh/known_hosts \ | |
&& echo $'\ | |
github.com,192.30.255.112 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== \n\ | |
bitbucket.org,104.192.143.1 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw== \n\ | |
' >> /root/.ssh/known_hosts \ | |
&& bundle config --global frozen 1 \ | |
&& bundle install --without development test -j4 --retry 3 \ | |
&& rm -rf /root/.ssh/id_rsa \ | |
/usr/local/bundle/bundler/gems/*/.git \ | |
/usr/local/bundle/cache/ | |
COPY package.json yarn.lock /app/ | |
RUN yarn install | |
COPY . /app/ | |
RUN bundle exec rails \ | |
AWS_ACCESS_KEY_ID=dontneed \ | |
AWS_SECRET_ACCESS_KEY=dontneed \ | |
DATABASE_URL=postgresql:does_not_exist \ | |
SECRET_KEY_BASE=nein \ | |
assets:precompile | |
# Packaging final app w/o node_modules & the development tools | |
FROM ruby:2.4.3-alpine3.7 | |
ENV CA_CERTS_PATH /etc/ssl/certs/ | |
ENV RAILS_ENV production | |
ENV RAILS_SERVE_STATIC_FILES true | |
ENV RAILS_LOG_TO_STDOUT true | |
RUN apk add --no-cache \ | |
busybox \ | |
ca-certificates \ | |
curl \ | |
gnupg1 \ | |
graphicsmagick \ | |
libsodium-dev \ | |
nodejs=8.9.3-r0 \ | |
postgresql-dev \ | |
rsync | |
# Patch for wkhtmltopdf | |
RUN apk add --update --no-cache \ | |
libgcc libstdc++ libx11 glib libxrender libxext libintl \ | |
libcrypto1.0 libssl1.0 \ | |
ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family | |
COPY --from=wkhtmltopdf_savior /bin/wkhtmltopdf /bin/ | |
RUN mkdir -p /app | |
WORKDIR /app | |
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/ | |
COPY --from=builder /app/ /app/ | |
COPY --from=builder /app/config/gpg/ /root/.gnupg/ | |
EXPOSE 3000 | |
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment