Skip to content

Setting it up

Upgrading

Which image tags to run, a backup first, the API and the worker together, and the way back.

A release is numbered X.Y.Z: the last number for fixes, the middle one for what is new, the first for a change that asks something of you, which its release notes say. The API and the worker are released as a pair, built from one commit, and run as one: the same version for both.

Help & support lists the dashboard, the API and every worker answering, each with its version and commit, and marks a worker on another build than the API. Without signing in, the health endpoint says the same of the API:

Terminal window
curl https://contactmesh.example.com/health/live
{"status":"Healthy","version":"1.4.2","commit":"…"}
TagNamesChanges
1.4.2One releaseNever
1.4The newest fix of 1.4With each fix
latestThe newest releaseWith each release
1.4.2-rc.1A candidate for 1.4.2Never
mainThe newest development buildWith every change; not for running

Run a release by its full number, 1.4.2, for both images. A tag that moves can move one image before the other is pulled, and the pair is then two versions.

  1. Read the release notes for every version between yours and the new one. A first number that changes says what it asks of you there.

  2. Write down the newest migration under Database on Help & support. If the upgrade moves it, the way back is a restore, not a tag.

  3. Back up the database, and keep the protection key beside the dump. The production stack opens no PostgreSQL port, so the dump comes out through its container:

    Terminal window
    docker compose exec -T postgres \
    sh -c 'pg_dump --format=custom --no-owner --no-privileges -U "$POSTGRES_USER" "$POSTGRES_DB"' \
    > /secure/backup/contactmesh-before-1.4.2.dump
  4. Set both images to the new version in .env:

    CONTACTMESH_API_IMAGE=git.kruede.com/lukas/contactmesh-api:1.4.2
    CONTACTMESH_WORKER_IMAGE=git.kruede.com/lukas/contactmesh-worker:1.4.2
  5. Pull both, then start the API before the worker. The worker and the API stop first, so neither runs old code against a schema the migrate step is moving forward; starting the API runs that step first, and the worker starts again once the API answers. PostgreSQL is left alone, and the dashboard is away for the seconds a migration and the API’s restart take.

    To check first that both images are the ones ContactMesh published, with cosign and the key the manual serves:

    Terminal window
    curl -fsSLO https://contactmesh.example.com/docs/cosign.pub
    cosign verify --key cosign.pub git.kruede.com/lukas/contactmesh-api:1.4.2
    cosign verify --key cosign.pub git.kruede.com/lukas/contactmesh-worker:1.4.2
    Terminal window
    docker compose pull api worker
    docker compose stop worker api
    docker compose up -d --wait api
    docker compose up -d worker
  6. Check Help & support. Every row has the new version, nothing is marked as differing from the API, and Database says Up to date.

./contactmesh update --version 1.4.2 does steps 3 to 6 for you, stopping the worker and the API before the migrate step moves the database forward and starting them once it has. See The operator tool.

compose.yaml runs the migrations in a container of their own, migrate, before the API and the worker start, as the database’s owner. Since 1.9.0 it also keeps a database role for the API and the worker, contactmesh_app, which reads and writes ContactMesh’s data and can change nothing else, once CONTACTMESH_DB_APP_PASSWORD is set in .env. Without it they log in as the owner, a superuser, as before, and Help & support marks Database role. To switch, take 1.9.0’s compose.yaml, set the variable to the output of openssl rand -hex 32, and run docker compose up -d.

docker compose up -d and docker compose up -d api run the step first; --no-deps skips it, and an API that logs in as the role then waits for it and refuses to start. docker compose ps -a lists it as exited (0) once it has run. Going back below 1.9.0 takes the older compose.yaml as well as the older images, and the variable out of .env.

Building from the repository instead of pulling: check out the release’s tag, then build both images with the script, which names the build after the tag.

Terminal window
git fetch --tags
git checkout v1.4.2
scripts/build-images.sh
docker compose stop worker api
docker compose up -d --wait api
docker compose up -d worker

If the newest migration did not change, put the previous version back in .env for both images and run step 5 again.

If it did, the older version refuses to start against the newer schema, and a tag change is not enough. Stop the API and the worker, restore the dump taken in step 3 with the protection key it was taken with, put the previous version back for both images, and start them. What ContactMesh wrote into mailboxes after the backup is still there, and reconciliation recognises it again. Deploying says what a backup holds and what it needs beside it.