Skip to content

Remove Old Root-Installed Gems#66922

Merged
Hamms merged 5 commits into
stagingfrom
elijah/remove-root-installed-ruby-gems
Sep 4, 2025
Merged

Remove Old Root-Installed Gems#66922
Hamms merged 5 commits into
stagingfrom
elijah/remove-root-installed-ruby-gems

Conversation

@Hamms

@Hamms Hamms commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

Planned follow-up to #66536, which switched us from installing gems as the root user to doing so as the ubuntu user with the deployment option.

That change has been successfully applied to all of our persistent managed servers (after a couple of attempts), and we are now successfully using the new deployment-installed gems on all persistent managed servers. Now, we want to minimize drift by removing all of the gems that were previously installed by root.

This temporary chef resource should handle that.

Testing story

Verified on an adhoc; spun one up based on staging latest (which is currently installing all gems in deployment mode) and manually installed all gems in our current Gemfile.lock with sudo, to emulate the current state of our build pipeline servers.

Finally, I merged this change in, let it build, and manually executed it with sudo chef-client -o cdo-apps. I verified that the web application servers can be built and initialized correctly afterwards, but I will largely be relying on the DTT and our other CD operations to verify that we haven't broken any obscure functionality.

Note

One thing to note is that we do end up with fewer gems installed after running this recipe than we do on a clean server (before, after).

Specifically, this recipe will remove the following gems from /usr/local/lib/ruby/gems/3.1.0/gems/ on an adhoc:

debug-1.4.0
matrix-0.4.2
minitest-5.15.0
net-ftp-0.1.3
net-imap-0.2.2
net-pop-0.1.1
net-smtp-0.3.1
power_assert-2.0.1
prime-0.1.2
rake-13.0.6
rbs-2.0.0
rexml-3.2.5
rss-0.2.9
ruby2_keywords-0.0.5
rubygems-update-3.3.22
test-unit-3.5.3
typeprof-0.21.1

I'm calling this out because it is technically an example of drift between our persistent managed servers and what we'd get if we recreated them from scratch, but as far as I can tell it does not impact any actual functionality. We should be entirely depending on the gems installed to ~/adhoc/vendor/bundle/ruby/gems/3.1.0/gems/ rather than any system-level gems.

Follow-up work

Once this resource has executed on all persistent managed servers, we can remove it.

Hamms added 3 commits July 3, 2025 16:42
Follow-up to #50661,
which added a temporary Chef resource to remove the unused `/etc/gemrc`
file from all of our persistent managed servers. It's been just over two
full years since it was first merged, so I'm pretty sure it should be
safe to remove by now.
Base automatically changed from elijah/clean-up-ancient-temp-chef-resource to staging July 7, 2025 20:15
@Hamms Hamms changed the title add temp chef script for removing old root-installed gems Remove Old Root-Installed Gems Jul 8, 2025
@Hamms Hamms marked this pull request as ready for review July 15, 2025 19:05
@Hamms Hamms requested a review from a team as a code owner July 15, 2025 19:05
@Hamms Hamms marked this pull request as draft August 22, 2025 18:34
@Hamms Hamms marked this pull request as ready for review August 27, 2025 20:49
@Hamms Hamms added the Ruby Update Everything related to work to update the version of Ruby our codebase runs on label Aug 27, 2025
@snickell snickell self-requested a review August 28, 2025 10:14

@snickell snickell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and agree the DTT should flag if there's something we missed.

# For simplicity, just check for one arbitrary gem. It's a fragile
# strategy, but this code is intended to be temporary and a false negative
# is harmless.
canary = '3.1.0/gems/rails-6.1.7.7'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused to see the rails used as the canary gem since it doesn't appear in the list of gems that would be uninstalled in the PR description, but I might have misunderstood something.

@Hamms Hamms Aug 28, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably have been more clear with what I meant with that list.

Right now when you spin up a fresh adhoc, it installs all of our Gemfile dependencies including Rails to ~/adhoc/vendor. But the base AMI we use comes with I think 92 gems already installed to /usr/local/lib. Most of those gems remain installed even after running gem uninstall --all, but the ones listed above get removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this means for our persistent managed servers is that this PR will bring them more in line with what we would get if we were to recreate them from scratch, by removing all of the Gemfile dependencies those servers still have installed to /usr/local/lib despite no longer using. But we will still end up having some drift from the "clean server" state, in that we remove a few more gems than we strictly need to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, more succinctly:

environment ll /usr/local/lib/ruby/gems/3.1.0/gems/ | wc -l
current staging 612
fresh server 92
state after this PR 85

@sureshc sureshc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm taking a break from vacation to do my on call shift tomorrow (Friday). If you want to try releasing this tomorrow, I'm available to help shepherd it through.

@Hamms Hamms merged commit b0f3632 into staging Sep 4, 2025
6 checks passed
@Hamms Hamms deleted the elijah/remove-root-installed-ruby-gems branch September 4, 2025 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ruby Update Everything related to work to update the version of Ruby our codebase runs on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants