From 472ae645a03d6e76ff69096785cd468d9137868c Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Thu, 22 Feb 2024 12:05:02 -0800 Subject: [PATCH] Finish migrating to Ruby 3.3.0 As the comment in `deploy.yml` explains, this was a multi-step process, but it went very smoothly as planned, hooray!! I noticed again while making this change that Bundler doesn't seem to be availing itself of the checked-in dependencies in `vendor/cache`. I think I know the fix for this, I'll toss it into an upcoming change and see if it works! --- .ruby-version | 2 +- Gemfile | 2 +- Gemfile.lock | 4 ++-- deploy/deploy.yml | 28 +++++++++++++++++++++++----- deploy/files/impress.service | 2 +- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.ruby-version b/.ruby-version index 0aec50e6..15a27998 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.4 +3.3.0 diff --git a/Gemfile b/Gemfile index 2c479ae8..fe320aec 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '3.1.4' +ruby '3.3.0' gem 'rails', '~> 7.1', '>= 7.1.3.2' diff --git a/Gemfile.lock b/Gemfile.lock index 12bad76f..56689f5b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -394,7 +394,7 @@ DEPENDENCIES will_paginate (~> 4.0) RUBY VERSION - ruby 3.1.4p223 + ruby 3.3.0p0 BUNDLED WITH - 2.3.26 + 2.5.5 diff --git a/deploy/deploy.yml b/deploy/deploy.yml index 887a1bbb..a45288ae 100644 --- a/deploy/deploy.yml +++ b/deploy/deploy.yml @@ -9,6 +9,19 @@ # deploy:setup should have added us to the "impress-deployers" group, so we # should be able to become the "impress" user without a password. ansible_become_password: "" + + # Set this to `yes` to skip setting this version as `current`. (We also + # skip our usual cleanup, to avoid disrupting the `current` version!) + # + # This can be useful for upgrading our Ruby version without downtime: + # 1. Install the new Ruby version, but don't uninstall the old one. + # 2. Update the app to reference the new Ruby version in the `Gemfile`. + # 3. Deploy the app with `skip_set_as_current`. + # 4. Update the service file manually to use the new Ruby to run the new + # version of the app, referenced directly by path. + # 5. Link the new version as `current` manually. + # 6. Reset the service file to use the new Ruby to run `current`. + skip_set_as_current: no tasks: - name: Generate a version name from the current timestamp command: date '+%Y-%m-%d-%s' @@ -41,7 +54,7 @@ - name: Configure Bundler to run in deployment mode command: chdir: "{{ remote_app_root }}" - cmd: /opt/ruby-3.1.4/bin/bundle config set --local deployment true + cmd: /opt/ruby-3.3.0/bin/bundle config set --local deployment true # This ensures that, while attempting our current deploy, we don't # accidentally delete gems out from under the currently-running version. @@ -51,7 +64,7 @@ - name: Configure Bundler to *not* clean up old gems when installing command: chdir: "{{ remote_app_root }}" - cmd: /opt/ruby-3.1.4/bin/bundle config set --local clean false + cmd: /opt/ruby-3.3.0/bin/bundle config set --local clean false # NOTE: Bundler recommends this, and they're pretty smart about it: if the # Gemfile changes, this shouldn't disrupt the currently-running version, @@ -60,18 +73,19 @@ - name: Configure Bundler to use the bundle folder shared by all app versions command: chdir: "{{ remote_app_root }}" - cmd: "/opt/ruby-3.1.4/bin/bundle config set --local path {{ remote_project_root}}/shared/bundle" + cmd: "/opt/ruby-3.3.0/bin/bundle config set --local path {{ remote_project_root}}/shared/bundle" - name: Run `bundle install` to install dependencies in remote folder command: chdir: "{{ remote_app_root }}" - cmd: /opt/ruby-3.1.4/bin/bundle install + cmd: /opt/ruby-3.3.0/bin/bundle install - name: Update the `current` folder to point to the new version file: src: "{{ remote_app_root }}" dest: /srv/impress/current state: link + when: not skip_set_as_current # NOTE: This uses the passwordless sudo rule we set up in deploy:setup. # We write it as a command rather than using the built-in `systemd` Ansible @@ -83,11 +97,13 @@ - name: Restart the app become: no command: sudo systemctl restart impress + when: not skip_set_as_current - name: Clean up gems no longer used in the current app version command: chdir: "{{ remote_app_root }}" - cmd: /opt/ruby-3.1.4/bin/bundle clean + cmd: /opt/ruby-3.3.0/bin/bundle clean + when: not skip_set_as_current - name: Find older app versions to clean up # Print out all but the 5 last-recently-updated versions. @@ -95,9 +111,11 @@ chdir: "{{ remote_project_root }}/versions" cmd: bash -c 'ls -t | tail -n +6' register: versions_to_clean_up + when: not skip_set_as_current - name: Clean up older versions file: path: "{{ remote_project_root }}/versions/{{ item }}" state: absent with_items: "{{ versions_to_clean_up.stdout_lines }}" + when: not skip_set_as_current diff --git a/deploy/files/impress.service b/deploy/files/impress.service index f77c370b..10c46d48 100644 --- a/deploy/files/impress.service +++ b/deploy/files/impress.service @@ -5,7 +5,7 @@ Description=Dress to Impress webapp User=impress Restart=always WorkingDirectory=/srv/impress/current -ExecStart=/opt/ruby-3.1.4/bin/bundle exec falcon host +ExecStart=/opt/ruby-3.3.0/bin/bundle exec falcon host Environment="RAILS_ENV=production" ; Set EXECJS_RUNTIME to save us from needing to install Node Environment="EXECJS_RUNTIME=Disabled"