Updating Forgejo from version 13 to version 17

A small recap of the steps I followed to update my forgejo instance across several major versions in one go.

In this post

Intro

If you read my prior post about reinstalling my web server, you may remember I finished it by mentioning that version 14.0.2 of forgejo was already out and so my next step should be to upgrade the instance to it. Well, some time has passed - and more importantly, some (major(!)) versions of forgejo have as well. At the time of this writing, the latest official version of forgejo available as a rootless container is 17.0.1.

v13.x to v14.x

The steps for this version increase were very simple:

  1. incrementing the version number used in the Image value of the forgejo.container file:
    [Container]
    # ...
    - Image=codeberg.org/forgejo:13-rootless
    + Image=codeberg.org/forgejo:14-rootless
    # ...
  2. making systemd regenerate the service file that lets it run the instance container by running:
    systemctl --user daemon-reload
  3. making systemd pull (and use) the correct image version by running:
    systemctl --user restart forgejo

v14.x to v15.x

The steps for this version increase are basically the same as for the previous increase, with 15 instead of 14:

  1. increment the version number used in the Image value of the forgejo.container file:
    [Container]
    # ...
    - Image=codeberg.org/forgejo:14-rootless
    + Image=codeberg.org/forgejo:15-rootless
    # ...
  2. make systemd regenerate the service file that lets it run the instance container by running:
    systemctl --user daemon-reload
  3. make systemd pull (and use) the correct image version by running:
    systemctl --user restart forgejo

v15.x to v16.x

The upgrade guide has specific sections that address this version increment and the next. For incrementing from before 16.0 to 16.0 or greater there is just an optional cleanup operation - deleting a handful of server-side git hooks. While the actual file size is almost negligeable, I didn't want to be holding on to a handful of extra files for each of the thirty-odd existing repositories tracked by my instance.

First, I repeated the same steps as for the previous version increments:

  1. increment the version number used in the Image value of the forgejo.container file:
    [Container]
    # ...
    - Image=codeberg.org/forgejo:15-rootless
    + Image=codeberg.org/forgejo:16-rootless
    # ...
  2. make systemd regenerate the service file that lets it run the instance container by running:
    systemctl --user daemon-reload
  3. make systemd pull (and use) the correct image version by running:
    systemctl --user restart forgejo

The upgrade guide provides a single bash/shell command that would do the cleanup for me, I just needed to feed it the correct directory. Since the instance is run as a container + data volume pair, the "correct directory" is inside of that data-volume.

  1. Seeing as the instance is running in a container, a simple way to have access to the directory needed was to open a shell inside of that container:
    debian@hostname$ podman exec -it forgejo /bin/bash
    5054265fc0f7:/var/lib/gitea$
    
  2. The command provided is find "$REPO_PATH" -mindepth 3 -maxdepth 3 -name hooks -exec rm -rf {} \;. I found it simpler to define the REPO_PATH variable first, and then paste the command and press enter:
    5054265fc0f7:/var/lib/gitea$ export REPO_PATH="./git/repositories"
    5054265fc0f7:/var/lib/gitea$ find "$REPO_PATH" -mindepth 3 -maxdepth 3 -name hooks -exec rm -rf {} \;
    (output omitted)
    

v16.x to v17.0.1

The specific section for this version upgrade has another optional cleanup step. This time it's deleting .patch files that forgejo used to download for pull requests migrated from other software forges. According to the upgrade guide, these files were unnecessary and not used by forgejo and can be deleted to free up disk space. The guide, again, provides a single bash/shell command that takes care of the cleanup:
find "$REPO_PATH" -mindepth 3 -maxdepth 3 -name pulls -exec rm -rf {} \;
Just like the previous increment, I found it simpler to open a shell inside of my instance's container, define the $REPO_PATH variable, and then run the find command.

First, I repeated the same steps as for the previous version increments:

  1. increment the version number used in the Image value of the forgejo.container file:
    [Container]
    # ...
    - Image=codeberg.org/forgejo:16-rootless
    + Image=codeberg.org/forgejo:17-rootless
    # ...
  2. make systemd regenerate the service file that lets it run the instance container by running:
    systemctl --user daemon-reload
  3. make systemd pull (and use) the correct image version by running:
    systemctl --user restart forgejo
  4. Then, I opened a shell inside the instance's container, defined the REPO_PATH variable, and finally ran the find command:
    debian@hostname$ podman exec -it forgejo /bin/bash
    5054265fc0f7:/var/lib/gitea$ export REPO_PATH="./git/repositories"
    5054265fc0f7:/var/lib/gitea$ find "$REPO_PATH" -mindepth 3 -maxdepth 3 -name pulls -exec rm -rf {} \;
    (output omitted)
    

Conclusion

At the end of all of this, viewing one of the instance's pages in my preferred web browser showed me a small Powered by Forgejo Version: 17.0.1 in that page's footer; confirmation that the instance was now running on the latest version of forgejo.

I really should have done this sooner; the fuss it took me to get the instance back up and running overly discouraged me from even trying the updates - which themselves turned out to be rather painless.