Skip to content

Commit

Permalink
perf: subsequent docker builds are faster by caching the bundle insta…
Browse files Browse the repository at this point in the history
…ll cmd (#352)
  • Loading branch information
adrianthedev committed Apr 13, 2021
1 parent 512c53c commit 16dad39
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Expand Up @@ -20,3 +20,7 @@ node_modules/
docker/
coverage/
pkg/

# Allow v1.0.0 files from tmp in docker
!tmp/Gemfile_v1.lock
!tmp/version_v1.rb
16 changes: 12 additions & 4 deletions docker/Dockerfile
Expand Up @@ -26,12 +26,16 @@ ENV BUNDLE_WITHOUT=development:test

WORKDIR /avo/

# gems
COPY Gemfile* /avo/
# Install gems
COPY Gemfile /avo/Gemfile
COPY Rakefile /avo/
COPY avo.gemspec /avo/
COPY ./lib/avo.rb /avo/lib/avo.rb
COPY ./lib/avo/version.rb /avo/lib/avo/version.rb
RUN mkdir /avo/lib/avo

# Cache the bundle install command with a fake version
COPY ./tmp/Gemfile_v1.lock /avo/Gemfile.lock
COPY ./tmp/version_v1.rb /avo/lib/avo/version.rb
RUN bundle install --jobs 4 --retry 3

COPY package.json /avo/
Expand All @@ -40,6 +44,10 @@ COPY yarn.lock /avo/
RUN yarn install
RUN yarn check --integrity

# re-run bundle install with the appropriate version number
COPY ./lib/avo/version.rb /avo/lib/avo/version.rb
RUN bundle install --jobs 4 --retry 3

COPY ./bin/ /avo/bin/
COPY ./app/packs/ /avo/app/packs/
COPY ./config/ /avo/config/
Expand All @@ -50,7 +58,7 @@ COPY ./tailwind.config.js /avo/tailwind.config.js
COPY ./babel.config.js /avo/babel.config.js

# Copy the files needed by PurgeCSS
COPY . /avo/
COPY . /avo

# Remove webpacker.yml config files
RUN rm /avo/config/webpacker.yml
Expand Down
7 changes: 7 additions & 0 deletions scripts/build.sh
Expand Up @@ -4,6 +4,13 @@ set -e

VERSION=$(bundle exec rails runner 'puts Avo::VERSION')

# Create v1.0.0 versions of the Gemfile and version file for better caching on the docker layer
cp ./Gemfile.lock ./tmp/Gemfile_v1.lock
sed -i '' 's/avo \(.*\)/avo (1.0.0)/' ./tmp/Gemfile_v1.lock
cp ./lib/avo/version.rb ./tmp/version_v1.rb
sed -i '' 's/VERSION = ".*"/VERSION = "1.0.0"/' ./tmp/version_v1.rb


docker build -t avo-build -f docker/Dockerfile .
IMAGE_ID=$(docker create avo-build)
rm -f ./pkg/latest-avo.gem
Expand Down

0 comments on commit 16dad39

Please sign in to comment.