From 2f363f9858d31a15196166089363c80d65ae2d7d Mon Sep 17 00:00:00 2001 From: Chris Banks Date: Thu, 8 Dec 2022 17:28:17 +0000 Subject: [PATCH 1/2] Dockerfile cleanup. - Add .dockerignore. docker build no longer fails when there are build artefacts in the source directory. - Use `$APP_HOME` from the base image instead of hardcoding `/app` throughout. - Remove unnecessary and misleading definition of `PORT` env var. - Re-enable bootsnap. - Simplify the command, now that we no longer need to run `bundle exec` explicitly. --- .dockerignore | 14 ++++++++++++++ Dockerfile | 22 ++++++++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..80100df1e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +.dockerignore +.git +.gitignore +Dockerfile +Jenkinsfile +Procfile +README.md +coverage +docs +features +log +spec +test +tmp diff --git a/Dockerfile b/Dockerfile index 42dd54b6d..7f6c9a2ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,24 +3,22 @@ ARG builder_image=ghcr.io/alphagov/govuk-ruby-builder:3.1.2 FROM $builder_image AS builder -WORKDIR /app - +WORKDIR $APP_HOME COPY Gemfile* .ruby-version ./ RUN bundle install - -COPY . /app -RUN bundle exec rails assets:precompile && rm -rf /app/log +COPY . ./ +RUN bundle exec bootsnap precompile --gemfile . +RUN bundle exec rails assets:precompile && rm -rf log FROM $base_image -# TODO: remove PORT and set it in publishing-e2e-tests instead. -ENV GOVUK_APP_NAME=government-frontend PORT=3090 +ENV GOVUK_APP_NAME=government-frontend -COPY --from=builder /usr/local/bundle/ /usr/local/bundle/ -COPY --from=builder /app /app/ +WORKDIR $APP_HOME +COPY --from=builder $BUNDLE_PATH/ $BUNDLE_PATH/ +COPY --from=builder $BOOTSNAP_CACHE_DIR/ $BOOTSNAP_CACHE_DIR/ +COPY --from=builder $APP_HOME ./ USER app -WORKDIR /app - -CMD ["bundle", "exec", "puma"] +CMD ["puma"] From c5d5971fc38788692ce290e078d6abf481ceb7cf Mon Sep 17 00:00:00 2001 From: Chris Banks Date: Thu, 8 Dec 2022 17:39:47 +0000 Subject: [PATCH 2/2] Use bootsnap to improve startup time. --- Gemfile | 1 + Gemfile.lock | 5 +++++ config/boot.rb | 1 + 3 files changed, 7 insertions(+) diff --git a/Gemfile b/Gemfile index 5e6fadcbd..38a19fa1a 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" gem "rails", "7.0.4" +gem "bootsnap", require: false gem "dalli" gem "gds-api-adapters" gem "govuk_ab_testing" diff --git a/Gemfile.lock b/Gemfile.lock index 67174d32a..7139c0c0c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,6 +83,8 @@ GEM smart_properties binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) + bootsnap (1.15.0) + msgpack (~> 1.2) brakeman (5.3.1) builder (3.2.4) capybara (3.38.0) @@ -206,6 +208,8 @@ GEM ruby2_keywords (>= 0.0.5) net-imap (0.3.2) date + msgpack (1.6.0) + net-imap (0.3.1) net-protocol net-pop (0.1.2) net-protocol @@ -395,6 +399,7 @@ PLATFORMS DEPENDENCIES better_errors binding_of_caller + bootsnap capybara climate_control dalli diff --git a/config/boot.rb b/config/boot.rb index 282011619..997563c2a 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,4 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup"