From 30a8d52500b20721116e59594a8d6633e5f884f7 Mon Sep 17 00:00:00 2001 From: Mateusz Pstrucha Date: Mon, 9 Nov 2026 16:37:24 +0100 Subject: [PATCH] Release builds the image only, ygg/deployments deploys it Production now runs from ygg/deployments, so a deploy from here would write over it. Renovate opens a PR there for the new version, and merging it deploys. Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/release.yml | 24 ++----------- README.md | 2 +- deploy/README.md | 62 -------------------------------- deploy/compose.yml | 68 ------------------------------------ 4 files changed, 3 insertions(+), 153 deletions(-) delete mode 100644 deploy/README.md delete mode 100644 deploy/compose.yml diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 5d00113..461763f 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -1,5 +1,7 @@ name: Release +# Builds and pushes the image. Production runs from ygg/deployments: Renovate +# opens a PR there for the new version, and merging it deploys. on: push: tags: ['v*'] @@ -7,9 +9,6 @@ on: jobs: image: runs-on: rocky-10 - outputs: - version: ${{ steps.image.outputs.version }} - digest: ${{ steps.image.outputs.digest }} steps: - name: Check out source uses: actions/checkout@v4 @@ -31,22 +30,3 @@ jobs: DIGEST: ${{ steps.image.outputs.digest }} run: | printf 'tags: %s\ndigest: %s\n' "$TAGS" "$DIGEST" - - # Deploys the image just pushed to tern-api.mtps.pl (deploy/compose on - # the app host; see deploy/README.md). - deploy: - needs: image - runs-on: rocky-10 - steps: - - name: Check out source - uses: actions/checkout@v4 - - - name: Deploy - uses: https://git.app.ygg/ygg/actions/deploy@v2 - with: - type: compose - dist-path: deploy/compose.yml - extra-vars: | - version=${{ needs.image.outputs.version }} - ssh-key: ${{ secrets.DEPLOY_SSH_KEY }} - known-hosts: ${{ secrets.DEPLOY_KNOWN_HOSTS }} diff --git a/README.md b/README.md index 99f4054..41b2379 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Only the first user can sign up, which is how a new server gets its owner. After ## Deployment -[`deploy/`](deploy/README.md) holds the production deployment to tern-api.mtps.pl: the server and its Postgres as one compose project, deployed by this repo's release workflow through the shared `ygg/actions/deploy` action. The webapp deploys separately, from tern-web. The image's `HEALTHCHECK` runs `tern-server healthcheck`, so `docker compose up --wait` only succeeds once the server answers `/healthz`. +A `v*` tag builds the image and pushes it to the registry. Production, tern-api.mtps.pl, is defined in [`ygg/deployments`](https://git.app.ygg/ygg/deployments/src/branch/main/deployments/tern-server.yml), secrets included: Renovate opens a PR there for the new version, and merging it deploys. The webapp is released separately, from tern-web. Back up `CREDENTIAL_KEY` outside the deployments repository: without it, the stored IMAP/SMTP passwords and the VAPID key can't be decrypted. The image's `HEALTHCHECK` runs `tern-server healthcheck`, so `docker compose up --wait` only succeeds once the server answers `/healthz`. ## Sessions diff --git a/deploy/README.md b/deploy/README.md deleted file mode 100644 index 6637d70..0000000 --- a/deploy/README.md +++ /dev/null @@ -1,62 +0,0 @@ -# Deployment - -[`compose.yml`](compose.yml) deploys tern-server to **tern-api.mtps.pl**. It's one compose project with two services: - -- `db`: `postgres:16-alpine`, with its data in the `db-data` volume. -- `server`: `git.app.ygg/mtps/tern-server:`, with mail and attachments in the `blob-data` volume. - -The server publishes port **11901** on the app host. The existing nginx proxies the domain to it, using the management repo's `site` role, with `websocket.conf` included so live updates (`/api/ws`) pass through. The server mounts the host's CA bundle, so mail and push servers behind the internal CA are trusted. - -The webapp deploys separately, from tern-web's own release, to tern.mtps.pl. It calls this API cross-origin. That works because clients authenticate with a bearer token rather than a cookie, and the server allows cross-origin requests. - -## How a release deploys - -tern-server's release workflow has two jobs: - -1. **`image`** builds and pushes `tern-server:` and `:latest` with [`ygg/actions/push-image`](https://git.app.ygg/ygg/actions/src/branch/main/push-image). -2. **`deploy`** sends this file inline through [`ygg/actions/deploy`](https://git.app.ygg/ygg/actions/src/branch/main/deploy) (`type: compose`), with `version=`. - -On the app host, `docker compose up --wait` replaces the containers. The deploy only succeeds once every service is healthy. The image's `HEALTHCHECK` runs `tern-server healthcheck`, which passes once the server answers `/healthz`, after migrations have run. So a server that can't start fails the workflow instead of leaving the API down. - -## One-time setup - -1. **Secrets on kara:** `/opt/ygg/secrets/env/tern-server.env`. It's copied next to the compose file as `.env`. - - ```ini - POSTGRES_PASSWORD= - CREDENTIAL_KEY= - # optional: PUSH_URL_REWRITE, PUSH_TLS_INSECURE, PUSH_VAPID_SUBJECT, - # SESSION_TTL_HOURS, TRASH_RETENTION_DAYS, OPEN_REGISTRATION, RUST_LOG - ``` - - - `CREDENTIAL_KEY` is 32 bytes, as 64 hex digits or base64. - - The database password can contain any characters, because it reaches the server as `PGPASSWORD`, not inside a URL. - - Back up `CREDENTIAL_KEY` somewhere other than kara. Without it, the stored IMAP/SMTP passwords and the VAPID key can't be decrypted. - -2. **Secrets on the `mtps/tern-server` repository:** `DEPLOY_SSH_KEY` and `DEPLOY_KNOWN_HOSTS`. The `ygg` org's secrets don't reach `mtps` repositories. - -3. **PyYAML on the runner** (`dnf install python3-pyyaml`). The deploy action converts this YAML file to JSON before sending it. - -4. **Create your user.** Only the first user can register unless `OPEN_REGISTRATION=true` is set. Sign up once in the Android app (*Create a new user on this server*), or with: - - ```bash - curl -X POST https://tern-api.mtps.pl/api/auth/register \ - -H 'Content-Type: application/json' -d '{"username":"…","password":"…"}' - ``` - -## By hand - -The same deploy, run directly on kara with this file copied to the dist directory: - -```bash -/opt/ygg/play.sh deploy/compose -e @/opt/ygg/dist/compose/tern-server.yml -e version=0.9.0 -``` - -To take it down, add `-e compose_state=destroy`. That stops the project and removes the nginx site, but keeps the `db-data` and `blob-data` volumes. - -## Escaping in `compose.yml` - -The file is processed twice, so some characters need care: - -- **Ansible** templates `{{ … }}`. That's how `{{ version }}` gets filled in. Wrap anything else that looks like Jinja in `{% raw %}`. -- **Docker compose** interpolates `$`. That's how `${POSTGRES_PASSWORD}` comes from `.env`. Write a literal `$` as `$$`. diff --git a/deploy/compose.yml b/deploy/compose.yml deleted file mode 100644 index d45b46d..0000000 --- a/deploy/compose.yml +++ /dev/null @@ -1,68 +0,0 @@ -# tern-server's deployment: the server and its Postgres as one compose -# project on the app host (deploy/compose in the ygg management repo), run -# by this repo's release workflow through ygg/actions/deploy. See -# deploy/README.md. -# -# `version` arrives as an extra var (the release tag without its v) and is -# templated in by Ansible. Secrets come from -# /opt/ygg/secrets/env/tern-server.env on kara, copied next to compose.yml -# as .env — never put them in here: this file is sent on the command line. - -compose_project: tern-server - -# The existing nginx proxies the domain to site_port on the app host; the -# include passes WebSocket upgrades through for live updates (/api/ws). -domain: tern-api.mtps.pl -cert: mtps.pl -site_port: 11901 -site_includes: websocket.conf - -compose: - services: - db: - image: postgres:16-alpine - restart: unless-stopped - environment: - POSTGRES_USER: tern - POSTGRES_DB: tern - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in tern-server.env} - volumes: - - db-data:/var/lib/postgresql/data - healthcheck: - test: ["CMD-SHELL", "pg_isready -U tern -d tern"] - interval: 5s - timeout: 5s - retries: 20 - - server: - image: "git.app.ygg/mtps/tern-server:{{ version }}" - restart: unless-stopped - depends_on: - db: - condition: service_healthy - environment: - # The password goes in separately (libpq's PGPASSWORD, which sqlx - # reads), so it never needs URL-escaping inside DATABASE_URL. - DATABASE_URL: postgres://tern@db:5432/tern - PGPASSWORD: ${POSTGRES_PASSWORD} - BIND_ADDR: 0.0.0.0:8080 - CREDENTIAL_KEY: ${CREDENTIAL_KEY:?set CREDENTIAL_KEY in tern-server.env} - BLOB_STORAGE_DIR: /data/blobs - SESSION_TTL_HOURS: ${SESSION_TTL_HOURS:-720} - TRASH_RETENTION_DAYS: ${TRASH_RETENTION_DAYS:-30} - OPEN_REGISTRATION: ${OPEN_REGISTRATION:-false} - PUSH_URL_REWRITE: ${PUSH_URL_REWRITE:-} - PUSH_TLS_INSECURE: ${PUSH_TLS_INSECURE:-false} - PUSH_VAPID_SUBJECT: ${PUSH_VAPID_SUBJECT:-mailto:postmaster@mtps.pl} - RUST_LOG: ${RUST_LOG:-tern_server=info} - ports: - - "11901:8080" - volumes: - - blob-data:/data/blobs - # The host's trust store, so IMAP/SMTP and push servers behind the - # internal CA are trusted like public ones. - - /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem:/etc/ssl/certs/ca-certificates.crt:ro - - volumes: - db-data: {} - blob-data: {}