Skip to content

fix(docker): drop gem test folders and lock files from the image - #2058

Merged
cru-Luis-Rodriguez merged 3 commits into
masterfrom
drop-gem-test-folders-and-lockfiles
Nov 17, 2026
Merged

cru-Luis-Rodriguez merged 3 commits into
masterfrom
drop-gem-test-folders-and-lockfiles

Conversation

@cru-Luis-Rodriguez

Copy link
Copy Markdown
Contributor

This drops the test folders and Gemfile.lock files that installed gems ship inside the image. Amazon Inspector reads those lock files as installed packages, so they show up as findings even though the app never loads them. Only the Dockerfile changes.

Why

The newest production image (production-11386) has 19 CRITICAL and 111 HIGH findings in Amazon Inspector. 16 CRITICAL and 90 HIGH of them come from files this change removes, mostly lock files and test folders inside rspec_api_documentation, bundler-audit and raddocs. What stays (3 CRITICAL, 21 HIGH) is mostly thruster's Go binary, which waits on an upstream release. This is part of the DevOps cleanup of Inspector findings across our ECR images.

What changes

In the same RUN as bundle install, so the gem layer itself gets smaller, the build now removes:

  • the gem cache and the .git folders of git-sourced gems
  • the top-level spec, test and example folders of installed gems
  • every Gemfile.lock inside installed gems and inside Ruby's bundled gems

The app's own Gemfile.lock is untouched.

The same block has run in production since Nov 6 on global_registry (https://github.com/CruGlobal/global_registry/pull/423) and ararat (https://github.com/CruGlobal/ararat/pull/247), and a variant of it on fl-pos-admin (https://github.com/CruGlobal/fl-pos-admin/pull/114).

What I checked

  • I could not build this one locally: bundle install needs the Sidekiq Pro login, which only CI has. global_registry and fl-pos-admin also install Sidekiq Pro, and they have run this same cleanup in production since Nov 6. Six other apps in this batch were built locally with it, and all of them passed the checks.
  • A separate review went through every gem in this app's Gemfile.lock (the installed copies, the published gem files, and git gems at their locked commits), looking for any that load files from the removed folders or read their own lock files at runtime. It found none.

Testing

Jason and Daniel, could you test this on stage before it merges? Merging this branch into staging builds it and deploys it there. Nothing has built this image yet, so please let that build finish before merging. A quick check that the app loads, sign-in works, and Sidekiq picks up jobs should cover it. Merging to master builds and deploys to production, and rollback is redeploying production-11386 from cru-deploy.

🤖 Generated with Claude Code

In the same RUN as bundle install, remove the gem cache, git-gem .git folders, top-level spec/test/example folders, and every Gemfile.lock inside installed gems and Ruby's bundled gems. Amazon Inspector reads those lock files as installed packages, so they show up as findings the app never loads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cru-Luis-Rodriguez

Copy link
Copy Markdown
Contributor Author

Heads-up on the failing audit check: it isn't from this change. bundler-audit is flagging gems that are already on master:

  • puma 8.0.2: 7 new advisories. Fix: 8.0.3.
  • msgpack 1.8.x: 1 advisory. Fix: 1.8.7 or later.

Dependabot's #2057 already bumps msgpack, so only puma is left after that one merges. Any PR opened here today fails the same way. My recommendation: bump these in their own PR (bundle update --patch --conservative puma msgpack), then update this branch from master and the check should go green. I've left the gem bumps to you rather than adding them here, so this PR stays a Dockerfile-only change.

@cru-Luis-Rodriguez

Copy link
Copy Markdown
Contributor Author

@JasonBennett41 @frett Friendly nudge on this one. It's updated from master and all checks pass now, audit included. It's a Dockerfile-only change, and the same cleanup is live on 12 other apps. Thanks for taking a look when you have a minute.

@JasonBennett41

Copy link
Copy Markdown
Contributor

@cru-Luis-Rodriguez taking a look now 👍🏽

Resolve the Dockerfile conflict with #2059: keep its BuildKit secret mount and /root/.bundle removal, then run the gem cleanup in the same RUN.
@stage-branch-merger

Copy link
Copy Markdown

I see you added the "On Staging" label, I'll get this merged to the staging branch!

@stage-branch-merger

Copy link
Copy Markdown

Merge conflict attempting to merge this into staging. Please fix manually.

@stage-branch-merger

Copy link
Copy Markdown

I see you added the "On Staging" label, I'll get this merged to the staging branch!

@stage-branch-merger

Copy link
Copy Markdown

Merge conflict attempting to merge this into staging. Please fix manually.

@JasonBennett41

JasonBennett41 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Tested on stage after merging into staging (build 7576d9a5, Build & Deploy ECS succeeded).

  • Running container has the cleanup applied: /usr/local/bundle/cache is gone and there are no Gemfile.lock files under the bundle or Ruby gem dirs.
  • Both git gems (raddocs, rspec_api_documentation) are still present, docs:generate ran in the build, and /docs serves.
  • /languages and the health check return 200.
  • Okta login and authenticated requests work in both admin dashboards.
  • sidekiq-pro-8.0.3 is installed. I couldn't confirm jobs run on stage: I don't have credentials for the Sidekiq UI, and there's no separate sidekiq task I could reach with cru app exec.
  • Not checked: container logs (couldn't find the stage app's logs in Datadog).

@cru-Luis-Rodriguez
cru-Luis-Rodriguez merged commit 492d563 into master Nov 17, 2026
13 checks passed
@cru-Luis-Rodriguez
cru-Luis-Rodriguez deleted the drop-gem-test-folders-and-lockfiles branch November 17, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants