Created
October 2, 2019 07:27
-
-
Save jacobat/d3479bb0b2448e75ee478934ff70bf73 to your computer and use it in GitHub Desktop.
Dockerfile with optimized Gem installs
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
# The prepare stage extracts the versions of some heavy gems into | |
# individual files enabling us to preinstall these gems in the build stage | |
# below. Thus we won't have to install the heavy gems everytime the | |
# Gemfile.lock changes, only when heavy gem versions are changed. | |
FROM ruby:2.6.3 AS prepare | |
RUN mkdir /gem_versions | |
COPY Gemfile.lock /gem_versions/Gemfile.lock | |
RUN grep "^ nokogiri " /gem_versions/Gemfile.lock | awk -F '[()]' '{print $2}' > /gem_versions/nokogiri.version | |
RUN grep "^ sassc " /gem_versions/Gemfile.lock | awk -F '[()]' '{print $2}' > /gem_versions/sassc.version | |
## Build stage | |
FROM ruby:2.6.3 AS build | |
WORKDIR /app | |
COPY --from=prepare /gem_versions/sassc.version /gem_versions/ | |
RUN gem install sassc -v $(cat /gem_versions/sassc.version) | |
COPY --from=prepare /gem_versions/nokogiri.version /gem_versions/ | |
RUN gem install nokogiri -v $(cat /gem_versions/nokogiri.version) | |
COPY Gemfile Gemfile.lock /app/ | |
RUN bundle install --jobs=4 --clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment