From 2d064bab64e0e0bbb4f1002ebc4f823c070068a1 Mon Sep 17 00:00:00 2001 From: Gareth Date: Wed, 20 Aug 2025 10:13:20 -0400 Subject: [PATCH] Created a bundler service that runs once removing responsibilities from any other services. The bundler service always runs install which should still be pretty fast if nothing or only a few gems have changed. A healthcheck won't work unless bundler runs continuously which is impractical. Instead, a checksum is generated on bundle install and sentinels in the other services have a definite confirmation that bundle is complete. The nice thing about this approach is that web, webpack, and sidekiq (which share the same bundles dependencies) will not concurrently run bundle install solving dep install redundancies. --- compose.yaml | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/compose.yaml b/compose.yaml index 1dc150c50a..ef6f18762c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -17,6 +17,18 @@ services: redis: image: redis + + bundler: + build: . + # Runs once: installs gems into /bundles, writes a checksum sentinel, then exits + command: > + sh -lc 'bundle check || bundle install --jobs 4 --retry 3 --quiet; + sha256sum Gemfile.lock > /bundles/.Gemfile.lock.sha' + volumes: + - .:/usr/src/app + - gems:/bundles + restart: "no" + web: tty: true stdin_open: true @@ -48,15 +60,17 @@ services: WEBPACKER_DEV_SERVER_PUBLIC: localhost:3035 command: > - bash -c "rm -f tmp/pids/server.pid && - (bundle check || bundle install) && - bundle exec rails db:prepare && - yarn install && - bundle exec rails s -b 0.0.0.0 -p 3000" + sh -lc 'rm -f tmp/pids/server.pid; + until [ -f /bundles/.Gemfile.lock.sha ] && sha256sum -c /bundles/.Gemfile.lock.sha >/dev/null 2>&1; do sleep 0.5; done; + bundle exec rails db:prepare && + yarn install && + exec bundle exec rails s -b 0.0.0.0 -p 3000' sidekiq: build: . - command: bundle exec sidekiq + command: > + sh -lc 'until [ -f /bundles/.Gemfile.lock.sha ] && sha256sum -c /bundles/.Gemfile.lock.sha >/dev/null 2>&1; do sleep 0.5; done; + exec bundle exec sidekiq' depends_on: db: condition: service_healthy @@ -75,12 +89,20 @@ services: webpack: build: . - command: ./bin/webpack-dev-server + command: > + sh -lc 'until [ -f /bundles/.Gemfile.lock.sha ] && sha256sum -c /bundles/.Gemfile.lock.sha >/dev/null 2>&1; do sleep 0.5; done; + exec ./bin/webpack-dev-server' ports: - "3035:3035" volumes: - .:/usr/src/app - gems:/bundles + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://localhost:3035/webpack-dev-server >/dev/null || wget -qO- http://localhost:3035/sockjs-node/info >/dev/null"] + interval: 5s + timeout: 3s + retries: 30 + environment: WEBPACKER_DEV_SERVER_HOST: 0.0.0.0 volumes: