Skip to content

Commit

Permalink
Use bootsnap to reduce resource usage spike on startup.
Browse files Browse the repository at this point in the history
Bootsnap has been enabled as standard for new Rails apps since Rails
5.2. It reduces startup time and - more importantly - reduces spikes in
resource usage at startup
([example](https://www.github.com/alphagov/government-frontend/pull/2626)).
  • Loading branch information
sengi committed Jan 15, 2023
1 parent 8c77d63 commit 7e018f8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ WORKDIR $APP_HOME
COPY Gemfile* .ruby-version ./
RUN bundle install
COPY . .
RUN bootsnap precompile --gemfile .


FROM $base_image
Expand All @@ -17,6 +18,7 @@ ENV GOVUK_APP_NAME=publishing-api

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
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source "https://rubygems.org"
gem "rails", "7.0.4"

gem "aws-sdk-s3"
gem "bootsnap", require: false
gem "bunny"
gem "dalli"
gem "fuzzy_match"
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ GEM
aws-sigv4 (1.5.2)
aws-eventstream (~> 1, >= 1.0.2)
bindex (0.8.1)
bootsnap (1.15.0)
msgpack (~> 1.2)
brakeman (5.2.3)
brpoplpush-redis_script (0.1.3)
concurrent-ruby (~> 1.0, >= 1.0.5)
Expand Down Expand Up @@ -247,6 +249,7 @@ GEM
mini_mime (1.1.2)
mini_portile2 (2.8.1)
minitest (5.17.0)
msgpack (1.6.0)
multi_xml (0.6.0)
net-imap (0.3.4)
date
Expand Down Expand Up @@ -532,6 +535,7 @@ PLATFORMS

DEPENDENCIES
aws-sdk-s3
bootsnap
bunny
byebug
climate_control
Expand Down
1 change: 1 addition & 0 deletions config/boot.rb
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 7e018f8

Please sign in to comment.