Skip to content
9 min read

Forgejo patch upgrades you can prove

Moving a forge to the latest patch release of the line it already runs is routine work. Doing it across a fleet, and knowing afterwards that every forge really changed, is where the mistakes live. This runbook covers the path we use for managed forges, and above all the places where an upgrade can silently not happen while every dashboard looks fine.

It is written for anyone who runs more than one Forgejo, and the single-forge reader can use it as a checklist. For a list of Forgejo releases and their notes, see the upstream

upgrade guide.

What this path is, and is not

  • It is a patch move inside a release channel. A forge on the long-term support line stays on it. A forge on the stable line stays on that. Changing a forge’s channel is a separate decision made by its owner, never a side effect of a patch rollout.
  • It is not zero downtime. The upgrade is an in-place restart: the Forgejo container is recreated and, on startup, Forgejo runs its own database migrations. The database server is not restarted. The outage is the container recreate plus the migration time, so plan a window rather than promising none. A true zero-downtime upgrade needs a second instance and a traffic switch, which is a different design.
  • Migrations only go forward. Once the new version has migrated the database, the old version cannot be started against it. That one fact shapes the rollback section below.

Intent is not effect

An upgrade has several layers, and each one can be done while the next is not.

LayerWhat changesWhat it does not change
Pin in codeThe version the control plane considers the target for a channel.Anything running.
Deploy of the control planeThe control plane now knows the new pin.Any forge.
Stored target on each forgeThe target recorded for that forge.Any forge.
New provisioningA forge created or re-created from now on starts on the new version.Forges that already exist.
The upgrade commandOne forge’s image, then a restart.Every other forge.

The consequence is the sentence to remember: merging a version bump upgrades no existing forge. Provisioning picks up the new pin automatically, so newly created forges come up correct, which makes the fleet look healthy while the forges that matter are still on the old patch. Unless you build a reconcile loop, existing forges move only when someone runs the upgrade, one forge at a time.

Record a channel change as intent only, too. If changing a forge’s channel writes a note that an upgrade is needed, the note is not the upgrade, and changing “to the channel it is already on” must not stamp a new note, or the patch rollout will look requested when nothing was.

Measure the running box, not the record

The only evidence that a forge is on a version is that forge saying so. Forgejo reports it at /api/v1/version. Build the whole process around reading that endpoint:

  • Sample it on a schedule and store the observed version with the time of the sample and the result of the probe.
  • Compare it to the channel’s target and classify each forge as one of current, behind, ahead or unknown.
  • Treat unknown as not green. A stale sample, a failed probe or a refused request is not a version reading. It means you did not measure, and it must never be rendered the same as current.
  • Read current together with its target. “Current” against an old deployed target is a green light for the wrong thing.
  • Never let the sweep upgrade anything. Detection and change are separate authorities. A monitor that can also act turns a bad reading into an outage.

A rollout is complete when every forge in scope has a fresh reading equal to the target. Pins, stored targets, channel rows and the output of the upgrade command are all intermediate evidence.

The upgrade step

The command that changes one forge should be small, strict and read back its own work.

  1. Preflight. Refuse any forge that is not fully ready. Read the current version where possible and refuse an evident downgrade. Validate the target as a version tag before building an image name from it.
  2. Pull first. Pull the new image before anything is changed. If the pull fails, the forge is still exactly as it was, and the failure is safe.
  3. Take a rollback point on a quiet forge. Stop writers first: the HTTP service, SSH pushes and background jobs. The upgrade restarts Forgejo anyway, so stopping it for the snapshot costs little. Then snapshot the whole machine, so that one rollback point holds the data volume, the database volume and the compose configuration together, and continue only once the snapshot reports complete. Keep a copy of the current compose file as well. A snapshot of a forge that is taking pushes can record the database and the repositories at different moments, and a rollback that restores the volumes but not the old image tag starts the new version again. Also make a best-effort Forgejo dump, but treat it as secondary evidence: it is best effort, and it may not exist when you need it.
  4. Rewrite only the image line. Change the Forgejo image tag in the compose file and nothing else, then read the file back and fail if the tag did not change. A pattern that matches nothing rewrites nothing, and the next step will happily succeed on the old image.
  5. Restart only Forgejo. Recreate the Forgejo service and leave the database running.
  6. Wait for the version endpoint. Poll /api/v1/version with a bounded timeout. Success is the endpoint reporting the target. The container command returning, or a line saying that it is upgrading, is not success: the container can be recreated well before the migrations finish.

If step 6 times out, the state is unknown. The forge may be upgraded and slow, or stuck in a restart loop. Inspect before you retry. Do not run the step again on a guess.

Canary first, then promote

Run the first upgrade on a forge that can afford it, such as an internal demo instance, in a window you chose.

  • Before you start, check that the drift reading for that forge is fresh. If it is unknown, fix measurement first. You cannot judge the result of a change you could not see the start of.
  • Take the snapshot on a quiet forge and wait for it to complete, run the command for exactly one forge, and then check the endpoint yourself in addition to the command’s own report.
  • Wait for the next sweep and confirm that the forge is now current against its channel target, with nothing behind, ahead or unknown.
  • Promote to the other forges only after that. Do not pass a stable-line target to a long-term-support forge because the stable number is higher.

Rollback

Which rollback you have depends on where the failure happened.

Before any snapshot restore, stop all writers again: the HTTP service, SSH pushes and background jobs. A restarted Forgejo may have accepted writes even if it later loops or the version poll times out. With writers stopped, preserve the current machine state separately from the pre-upgrade snapshot, including the data volume, database volume and compose configuration. Confirm that preservation completed before proceeding. Identify writes accepted since the rollback point and explicitly assess and agree their loss with the forge owner before restoring. If the extent of data loss is unknown or the owner does not accept it, keep the preserved state and investigate a roll-forward recovery instead. Keep writers stopped throughout the restore and verification.

FailureState of the forgeWhat to do
Preflight or pull failsUnchanged, still running.Fix the cause and retry. Nothing to roll back.
The snapshot fails, or the compose rewrite fails after writers were stoppedOld image, but stopped.Put back the saved compose file if it was edited, start the old service, and confirm the version endpoint reports the old version before anything else. Retry only when the forge is serving again.
Restart succeeds, migration fails or the container loopsPossibly partly migrated.Restore the machine snapshot, then start Forgejo, since the snapshot was taken with it stopped, and confirm the version endpoint reports the pre-upgrade version before you call it recovered. The old version cannot run against a migrated database.
Version poll times outUnknown.Inspect the container and logs first. Restore only if it is not recovering, and finish the restore the same way: start Forgejo and confirm the old version.
Upgrade is healthy but a problem appears laterMigrated.Roll forward to a fixed patch. Restoring a snapshot loses everything since it was taken.

Use the dump only as a secondary route to the data, and see Backups and restore drills for how far a dump can be trusted and how to prove it.

Where an upgrade silently does not happen

If this step never runsYou still seeWhat is actually true
The pin is merged but the control plane is not deployedA green build and a merged changeNothing has changed, and drift may still report current against the old target.
The stored targets are not updatedCode and database disagree in some viewsReads of the stored target can contradict the pin until you check deploy and migration state.
Nobody runs the upgrade on existing forgesNew forges on the new versionExisting forges stay on the old patch. There is no automatic reconcile.
A same-channel change is postedA success responseBy design it records no upgrade intent, so it cannot be used to roll a patch across a channel.
The sweep is stalled or batch-starvedAn old sample that still looks fineThe classification should have turned to unknown, and your dashboard has to show that.
The version probe cannot authenticateA healthy-looking forgeRefused is not a reading. It does not tell you whether the forge is current.
The probe ran but saving it failedAn error in a logThe next view can still show a stale earlier reading.
The operator credential is not configuredA failed commandNo background retry will upgrade the forge later.
The forge’s command script is out of dateA failed or unrecognised commandRefresh the script on the forge before the upgrade can happen.
The compose rewrite matches nothingAn “upgrading” messageWithout the read-back, the forge stays on the old image and the step still reports success.
The container returns before migrations finishA good-looking command resultThe version endpoint is the only real success criterion.

Verify it is healthy

  • Every forge in scope has a recent probe, and none is unknown.
  • Every forge’s observed version equals its own channel’s target.
  • The control plane that holds the pin was actually deployed.
  • Your last canary was timed, so you can state the outage a patch move costs.
  • You can say, for each forge, where its pre-upgrade snapshot is and how long it is kept.
Contributors
  • Stephen Way