Upgrade
An upgrade runs a new release next to the running one, checks it, then switches the proxy to it. People using it are not signed out and do not see half-loaded pages. If something is wrong, going back is one proxy switch of a few seconds.
Before upgrading
- Read the release notes (Changelog). If the new release needs a manual step or a new required setting, the notes say what to do before upgrading.
- Back up. Check that the latest backup is still recent (
status, see Backup and restore) or run one now. - Check CLI compatibility. The new server may raise the minimum CLI version; see CLI and server compatibility.
Upgrade
This part is for an installation with Caddy in front, because deploy.sh switches only Caddy. With nginx or Traefik, see With nginx or Traefik below.
Get the new release's source code into a folder (see Install, step 0) and run from its docker/ folder, with the same environment file and state folder as at install time:
export TMSPEC_ENV_FILE=/etc/tmspec/env.prod
export TMSPEC_DEPLOY_STATE_DIR=/var/lib/tmspec/deploy
./deploy.sh deploy --pull <new-tag> # pull images from the registry (needs TMSPEC_IMAGE_PREFIX)
./deploy.sh deploy --no-build <new-tag> # the images are already on the machine
./deploy.sh deploy <new-tag> # build images from the local source
Keep both across every change of folder. The environment file holds the passwords and keys; the state folder remembers the running color, each color's tag and the lock. If the state folder is missing, deploy.sh treats it as no color running, takes down the blue color that is serving and builds it again, and users will see a disruption. Also copy over the optional settings you exported (for example TMSPEC_COMPOSE_FILES) and keep the proxy's upstream file where it was.
Each release has its own image tag. The command runs in this order:
lock → infrastructure up → the other color: down, then up with the new release (database preparation, migrations)
→ wait until auth, API, worker, web are healthy
→ quick test on the new color's ports (API and web healthy, the sign-in page names the right issuer)
→ write the proxy's upstreams, reload the proxy → record the running color
→ stop the old color's worker
After the switch, the old color still runs but without a worker, so two workers do not process the queue together. --drain <seconds> takes the old color fully down after that many seconds, in exchange for losing the instant way back (you can still go back but it must restart from the images).
Two upgrades do not run at the same time: the second exits with code 3 because of the lock. Check ./deploy.sh status: the running color, each color's tag and the containers.
Confirm the running version: the server reports product_version and commit at GET /v1/meta (see CLI and server compatibility).
Database and migrations
The new release's migrations run while the old release is still serving on the same database, so a release only adds: adding tables, columns (nullable or with a default) and indexes. Removing or renaming something the previous release reads must wait for the release after. That way a database holding the newer schema is still usable by the previous release when you go back.
With nginx or Traefik
deploy.sh deploy and deploy.sh rollback write Caddy's upstream file and reload Caddy, so they cannot be used when the proxy is nginx or Traefik. You do exactly those steps by hand, as in Install, step 3 (details in docker/ops/blue-green.md of the release):
- Get the new release's source code, keep the environment file, then start the other color with compose (use
colors/green.envifblueis running, and the other way round) with the new release's tag. That color may still be running the old release (without a worker) from the previous upgrade: take it down first (docker compose ... -f compose.app.yaml downwith that color's file), so it is built again with the new release. Wait until every service of that color is healthy. - Point the proxy's three upstreams at the new color's ports (the port table is in
docker/proxy/README.md) and reload the proxy; the reload keeps open connections. - Stop the old color's worker (
docker compose ... -f compose.app.yaml stop workerwith the old color's file) so two workers do not process the queue together.
Going back is also by hand: start the previous color again with compose using the tag it ran with (its worker starts again with it), point the three upstreams back at its ports, reload the proxy, then stop the worker of the color you just left. The section "Database and migrations" applies the same way. Clean-up of old images runs on its own only inside deploy.sh deploy, so when you are done, run ./deploy.sh prune (it does not depend on the proxy).
When an upgrade fails
A failure before the proxy switch (a migration, an unhealthy service, a failed quick test, a failed proxy reload) makes the command print the containers and the last few log lines, take the new color down and exit with code 1. The proxy and the running color stay as they were, so users see nothing.
| Error line | Check |
|---|---|
dependency failed to start or a migrate job that exited | The migrate job's log. A failed migration stops the upgrade before any service starts |
<color> not healthy after ...s | The containers' health state. On a slow machine, raise TMSPEC_HEALTH_TIMEOUT |
smoke: auth discovery does not name the issuer | TMSPEC_AUTH_HOST in the environment file must match the running color's issuer |
caddy reload failed | The Caddy configuration must import tmspec's upstream file |
another deploy is running | An upgrade is running, or a stuck one holds the lock |
nothing to roll back to | Only one color has ever been installed |
Go back to the previous release
With Caddy (nginx and Traefik: see the section above):
./deploy.sh rollback
The command starts the previous color with the tag recorded for it (if it was taken down), waits until it is healthy, runs the quick test, switches the proxy and stops the worker of the color it just left. The images of both colors are always kept on the machine, so going back needs no registry. The database keeps the newer schema, which the previous release tolerates because every release only extends the schema.
Clean-up
Each upgrade cleans old images: it keeps the images of the 5 most recent releases built or pulled (TMSPEC_KEEP_IMAGES) and of both colors. ./deploy.sh prune runs that on its own.
Two stacks on one machine
One machine can run a second stack (for example a demo next to the real one), with its own database, signing key and accounts. Each stack has its own TMSPEC_STACK, network range, ports, state folder and upstream file, and TMSPEC_KEEP_STATE_DIRS so that cleaning one stack's images does not delete the other's. Backups also run separately for each stack.
Restart on failure
Long-running containers are restarted by Docker when the process exits and when the machine boots. A hung container (the process is there but does not answer) is restarted by autoheal after about a minute. autoheal can reach the Docker socket, so it can control every container on the machine; it has no network and opens no port.