From 024d2fc5bc26b8c1482dd9fab1fb4f5eb4a88d34 Mon Sep 17 00:00:00 2001 From: David Wessman Date: Thu, 12 Nov 2020 06:58:30 +0100 Subject: [PATCH 1/2] Gemfile_next -> Gemfile.next --- README.md | 34 +++++++++++++++++----------------- bin/compile | 16 ++++++++-------- bin/detect | 2 +- bin/test-compile | 16 ++++++++-------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 89d28f5..b22aca9 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ alongside Heroku's ruby buildpack. You may want to use this during Rails upgrades to run two Rails versions simultaneously in the same Heroku environment. For example, you could have some of your dynos running the current Rails version, and the rest of your dynos running the next Rails version. -- Capable of running 2 different gemfiles `Gemfile` and `Gemfile_next` from one Heroku slug +- Capable of running 2 different gemfiles `Gemfile` and `Gemfile.next` from one Heroku slug - Configurable to run tests against both gemfiles when using Heroku CI parallel - Allows you to run two Rails versions in production -- Uses an env var to specify which dynos you want to use `Gemfile_next` +- Uses an env var to specify which dynos you want to use `Gemfile.next` ## Setup @@ -26,18 +26,18 @@ same Heroku environment. For example, you could have some of your dynos running If you want Heroku CI support, you'll also need to include this buildpack in the `environments > test > buildpacks` array in `app.json`. -3. Create `Gemfile_next` with its dependencies in your project root. This is the same directory as your existing `Gemfile`. +3. Create `Gemfile.next` with its dependencies in your project root. This is the same directory as your existing `Gemfile`. -4. Generate `Gemfile_next.lock` by running: +4. Generate `Gemfile.next.lock` by running: ```sh -BUNDLE_GEMFILE=Gemfile_next bundle install +BUNDLE_GEMFILE=Gemfile.next bundle install ``` -5. Commit `Gemfile_next` and `Gemfile_next.lock` to your git repository. +5. Commit `Gemfile.next` and `Gemfile.next.lock` to your git repository. -6. For Heroku CI support, set the `DEPENDENCIES_NEXT_CI_NODES` environment variable (in the `environments > test > env` object in `app.json`) to a comma-separated string of node indexes you want to use `Gemfile_next`. +6. For Heroku CI support, set the `DEPENDENCIES_NEXT_CI_NODES` environment variable (in the `environments > test > env` object in `app.json`) to a comma-separated string of node indexes you want to use `Gemfile.next`. -For example, if you have 4 CI nodes in total, and you want the first 2 nodes to use `Gemfile` (the default), and the last 2 nodes to use `Gemfile_next`, set the following: +For example, if you have 4 CI nodes in total, and you want the first 2 nodes to use `Gemfile` (the default), and the last 2 nodes to use `Gemfile.next`, set the following: ``` "DEPENDENCIES_NEXT_CI_NODES": "2,3" @@ -45,29 +45,29 @@ For example, if you have 4 CI nodes in total, and you want the first 2 nodes to (CI nodes are zero-indexed.) -7. To specify which dynos use `Gemfile_next`, set the `DEPENDENCIES_NEXT_DYNOS` environment variable to a comma-separated string of dyno names with glob/wildcard (`*`) support. +7. To specify which dynos use `Gemfile.next`, set the `DEPENDENCIES_NEXT_DYNOS` environment variable to a comma-separated string of dyno names with glob/wildcard (`*`) support. -- `DEPENDENCIES_NEXT_DYNOS=*` would cause all dynos to use `Gemfile_next`. -- `DEPENDENCIES_NEXT_DYNOS=worker.1,scheduler.*,web.*,run.*` would cause `worker.1` and all `scheduler`, `web` and one-off `run` dynos to use `Gemfile_next`. All other dynos would use `Gemfile`. -- `DEPENDENCIES_NEXT_DYNOS=web.5,web.6,worker.3` would cause dynos `web.5`, `web.6`, and `worker.3` to use `Gemfile_next`. All other dynos would use `Gemfile`. +- `DEPENDENCIES_NEXT_DYNOS=*` would cause all dynos to use `Gemfile.next`. +- `DEPENDENCIES_NEXT_DYNOS=worker.1,scheduler.*,web.*,run.*` would cause `worker.1` and all `scheduler`, `web` and one-off `run` dynos to use `Gemfile.next`. All other dynos would use `Gemfile`. +- `DEPENDENCIES_NEXT_DYNOS=web.5,web.6,worker.3` would cause dynos `web.5`, `web.6`, and `worker.3` to use `Gemfile.next`. All other dynos would use `Gemfile`. ## How it works When Heroku builds your app, these additional steps are performed by this buildpack: -- Installs gems specified in `Gemfile_next.lock` into your slug. +- Installs gems specified in `Gemfile.next.lock` into your slug. -- Writes a shell script in your dyno's `.profile.d/` directory which sets environment variables on startup `BUNDLE_GEMFILE=Gemfile_next` and `DEPENDENCIES_NEXT=true` for the dynos you specify in the `DEPENDENCIES_NEXT_DYNOS` environment variable (or `DEPENDENCIES_NEXT_CI_NODES` for Heroku CI). +- Writes a shell script in your dyno's `.profile.d/` directory which sets environment variables on startup `BUNDLE_GEMFILE=Gemfile.next` and `DEPENDENCIES_NEXT=true` for the dynos you specify in the `DEPENDENCIES_NEXT_DYNOS` environment variable (or `DEPENDENCIES_NEXT_CI_NODES` for Heroku CI). ## Rollback to Gemfile -If you need to rollback to using `Gemfile` on a dyno instead of `Gemfile_next`, change the value of `DEPENDENCIES_NEXT_DYNOS`. All dynos will restart and only those dynos specified in `DEPENDENCIES_NEXT_DYNOS` will use `Gemfile_next`. All other dynos will use `Gemfile`. If you want no dynos to use `Gemfile_next`, you can delete the `DEPENDENCIES_NEXT_DYNOS` environment variable. +If you need to rollback to using `Gemfile` on a dyno instead of `Gemfile.next`, change the value of `DEPENDENCIES_NEXT_DYNOS`. All dynos will restart and only those dynos specified in `DEPENDENCIES_NEXT_DYNOS` will use `Gemfile.next`. All other dynos will use `Gemfile`. If you want no dynos to use `Gemfile.next`, you can delete the `DEPENDENCIES_NEXT_DYNOS` environment variable. -## How to run a Rails console using Gemfile_next +## How to run a Rails console using Gemfile.next ```sh -heroku run --app YOUR_HEROKU_APP_NAME -- BUNDLE_GEMFILE=Gemfile_next bundle exec rails console +heroku run --app YOUR_HEROKU_APP_NAME -- BUNDLE_GEMFILE=Gemfile.next bundle exec rails console ``` diff --git a/bin/compile b/bin/compile index 6144a8b..4760cca 100755 --- a/bin/compile +++ b/bin/compile @@ -32,17 +32,17 @@ function indent() { } # The heroku ruby buildpack will have already installed the gems for the default Gemfile, so now -# install the missing gems from Gemfile_next. -echo "-----> Installing Gemfile_next gems" +# install the missing gems from Gemfile.next. +echo "-----> Installing Gemfile.next gems" cd $BUILD_DIR bundle_without="development:test" set -o pipefail # Enable pipefail so failure exit code from bundle install will not be lost by pipe to indent. -BUNDLE_GEMFILE=Gemfile_next bundle install --without $bundle_without --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment | indent +BUNDLE_GEMFILE=Gemfile.next bundle install --without $bundle_without --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment | indent bundle_install_status=$? set +o pipefail # Disable pipefail, only needed for above command as it is pipes to indent. if [ $bundle_install_status -ne 0 ]; then - error "bundle install error: This can happen when Gemfile_next.lock falls out of sync with Gemfile_next. Check the committed Gemfile_next.lock is up-to-date." + error "bundle install error: This can happen when Gemfile.next.lock falls out of sync with Gemfile.next. Check the committed Gemfile.next.lock is up-to-date." fi echo "-----> Writing .profile.d/multiple-gemfiles.sh to run on dyno startup" @@ -56,7 +56,7 @@ unset DEPENDENCIES_NEXT echo "---------------------> Unsetting BUNDLE_GEMFILE" unset BUNDLE_GEMFILE -# DEPENDENCIES_NEXT_DYNOS is a comma-separated string of dynos that should use Gemfile_next, +# DEPENDENCIES_NEXT_DYNOS is a comma-separated string of dynos that should use Gemfile.next, # and glob wildcards can be used in the following ways: # * => matches all dynos (*.* also works the same) # web.* => matches all web dynos @@ -78,7 +78,7 @@ function is_next_server() { for next_server in "${next_servers[@]}"; do # This supports glob matching (*) if [[ "$server_id" == $next_server ]]; then - # matches => this server will use Gemfile_next. + # matches => this server will use Gemfile.next. true return fi @@ -93,8 +93,8 @@ if [ -n "$next_server_ids" ]; then if is_next_server; then echo "---------------------> Setting DEPENDENCIES_NEXT=true" export DEPENDENCIES_NEXT=true - echo "---------------------> Setting BUNDLE_GEMFILE=$HOME/Gemfile_next" - export BUNDLE_GEMFILE=$HOME/Gemfile_next + echo "---------------------> Setting BUNDLE_GEMFILE=$HOME/Gemfile.next" + export BUNDLE_GEMFILE=$HOME/Gemfile.next fi fi diff --git a/bin/detect b/bin/detect index bbdb963..c645fb9 100755 --- a/bin/detect +++ b/bin/detect @@ -4,7 +4,7 @@ # parse and derive params BUILD_DIR=$1 -if [ -e $BUILD_DIR/Gemfile_next ]; then +if [ -e $BUILD_DIR/Gemfile.next ]; then echo 'Multiple Gemfiles' exit 0 fi diff --git a/bin/test-compile b/bin/test-compile index 7ab0589..54a1016 100644 --- a/bin/test-compile +++ b/bin/test-compile @@ -33,18 +33,18 @@ function indent() { # The heroku ruby buildpack will have already installed the gems for the default Gemfile, so now -# install the missing gems from Gemfile_next. We want gem versions from both Gemfiles to be in the +# install the missing gems from Gemfile.next. We want gem versions from both Gemfiles to be in the # app for parity with the production slug. -echo "-----> Installing Gemfile_next gems" +echo "-----> Installing Gemfile.next gems" cd $BUILD_DIR bundle_without="development" set -o pipefail # Enable pipefail so failure exit code from bundle install will not be lost by pipe to indent. -BUNDLE_GEMFILE=Gemfile_next bundle install --without $bundle_without --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment | indent +BUNDLE_GEMFILE=Gemfile.next bundle install --without $bundle_without --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment | indent bundle_install_status=$? set +o pipefail # Disable pipefail, only needed for above command as it is pipes to indent. if [ $bundle_install_status -ne 0 ]; then - error "bundle install error: This can happen when Gemfile_next.lock falls out of sync with Gemfile_next. Check the committed Gemfile_next.lock is up-to-date." + error "bundle install error: This can happen when Gemfile.next.lock falls out of sync with Gemfile.next. Check the committed Gemfile.next.lock is up-to-date." fi echo "-----> Writing .profile.d/multiple-gemfiles.sh to run on dyno startup" @@ -59,7 +59,7 @@ echo "---------------------> Unsetting BUNDLE_GEMFILE" unset BUNDLE_GEMFILE # DEPENDENCIES_NEXT_CI_NODES is a comma-separated string of CI node indexes that should use -# Gemfile_next (glob wildcards can be used though you probably don't want to do this in CI): +# Gemfile.next (glob wildcards can be used though you probably don't want to do this in CI): # # e.g. DEPENDENCIES_NEXT_CI_NODES=5,6,7 next_server_ids=$DEPENDENCIES_NEXT_CI_NODES @@ -72,7 +72,7 @@ function is_next_server() { for next_server in "${next_servers[@]}"; do # This supports glob matching (*) if [[ "$server_id" == $next_server ]]; then - # matches => this server will use Gemfile_next. + # matches => this server will use Gemfile.next. true return fi @@ -87,8 +87,8 @@ if [ -n "$next_server_ids" ]; then if is_next_server; then echo "---------------------> Setting DEPENDENCIES_NEXT=true" export DEPENDENCIES_NEXT=true - echo "---------------------> Setting BUNDLE_GEMFILE=$HOME/Gemfile_next" - export BUNDLE_GEMFILE=$HOME/Gemfile_next + echo "---------------------> Setting BUNDLE_GEMFILE=$HOME/Gemfile.next" + export BUNDLE_GEMFILE=$HOME/Gemfile.next fi fi From 0c41d2e6d183876c52031a609b4ea9351d773677 Mon Sep 17 00:00:00 2001 From: David Wessman Date: Wed, 10 Jan 2024 14:36:40 +0100 Subject: [PATCH 2/2] Update bundle - Also adds output of folder sizes to the build log --- bin/compile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/compile b/bin/compile index 4760cca..8248b3d 100755 --- a/bin/compile +++ b/bin/compile @@ -35,9 +35,11 @@ function indent() { # install the missing gems from Gemfile.next. echo "-----> Installing Gemfile.next gems" cd $BUILD_DIR -bundle_without="development:test" set -o pipefail # Enable pipefail so failure exit code from bundle install will not be lost by pipe to indent. -BUNDLE_GEMFILE=Gemfile.next bundle install --without $bundle_without --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment | indent + + +# Inspired by heroku ruby buildpack +BUNDLE_GEMFILE=Gemfile.next BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install | indent bundle_install_status=$? set +o pipefail # Disable pipefail, only needed for above command as it is pipes to indent. @@ -100,4 +102,5 @@ fi EOF +du -h --max-depth=3 | sort -rh echo "-----> Multiple Gemfiles done"