2026-07-23 05:11:33 +00:00
|
|
|
name: Sync infra to hosts
|
|
|
|
|
|
|
|
|
|
# The infra DOMAIN's own pipeline (new with the monorepo -- the split era had
|
|
|
|
|
# no infra deploy workflow at all; infra changes rode along lazily with the
|
2026-07-26 06:56:38 +00:00
|
|
|
# next app deploy's `git reset`). On a push touching infra/**, SSH to every
|
|
|
|
|
# host, fast-forward each ENVIRONMENT's monorepo checkout and re-render that
|
|
|
|
|
# environment's env file from the SOPS vault -- so a compose edit or a secret
|
|
|
|
|
# rotation lands push-button instead of waiting for the next app deploy.
|
2026-07-23 05:11:33 +00:00
|
|
|
#
|
|
|
|
|
# Deliberately does NOT roll any service: image tags are the app domains'
|
2026-07-26 06:56:38 +00:00
|
|
|
# axis, not infra's. A compose or stack change that must recreate containers
|
|
|
|
|
# takes effect on the next app deploy, or a by-hand
|
2026-07-23 05:11:33 +00:00
|
|
|
# `SERVICE=all ... infra/deploy/deploy.sh` run (see that script's header).
|
|
|
|
|
#
|
2026-07-26 06:56:38 +00:00
|
|
|
# THREE CHECKOUTS, TWO HOSTS. This is the shape the vps1/vps2 split forces:
|
|
|
|
|
#
|
|
|
|
|
# vps1 /opt/thermograph-dev branch dev -> /etc/thermograph.env
|
|
|
|
|
# vps2 /opt/thermograph-beta branch main -> /etc/thermograph-beta.env
|
|
|
|
|
# vps2 /opt/thermograph branch main -> /etc/thermograph.env
|
|
|
|
|
#
|
|
|
|
|
# The two checkouts on vps2 are separate directories on purpose: a `git reset
|
|
|
|
|
# --hard` for beta must not be able to move prod's tree, and each environment
|
|
|
|
|
# renders its own env file from its own vault file. Because the paths differ,
|
|
|
|
|
# the beta and prod jobs below can safely run at the same time on one box.
|
|
|
|
|
#
|
|
|
|
|
# Beta and prod both track `main` (infra is not environment-staged -- only app
|
|
|
|
|
# IMAGES are, via tags). Dev tracks `dev`, which is why this workflow now
|
|
|
|
|
# triggers on both branches: a dev-branch infra change has to reach the dev
|
|
|
|
|
# checkout, and only that one.
|
|
|
|
|
#
|
|
|
|
|
# Each `render_thermograph_secrets` call passes the environment name and the
|
|
|
|
|
# output path EXPLICITLY. It used to rely on the host's
|
|
|
|
|
# /etc/thermograph/secrets-env marker, which cannot answer the question on vps2
|
|
|
|
|
# -- one marker, two environments. Passing them here means a beta sync can
|
|
|
|
|
# never render prod's vault, and vice versa.
|
2026-07-23 05:11:33 +00:00
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
2026-07-26 06:56:38 +00:00
|
|
|
branches: [dev, main]
|
2026-07-23 05:11:33 +00:00
|
|
|
paths: ['infra/**']
|
|
|
|
|
workflow_dispatch: {}
|
|
|
|
|
|
|
|
|
|
jobs:
|
2026-07-26 06:56:38 +00:00
|
|
|
sync-dev:
|
|
|
|
|
# Only the dev branch feeds the dev checkout.
|
|
|
|
|
if: github.ref_name == 'dev'
|
|
|
|
|
runs-on: docker
|
|
|
|
|
concurrency:
|
|
|
|
|
group: infra-sync-dev
|
|
|
|
|
cancel-in-progress: false
|
|
|
|
|
steps:
|
|
|
|
|
- name: Sync dev checkout on vps1 + re-render secrets
|
|
|
|
|
uses: https://github.com/appleboy/ssh-action@v1.2.0
|
|
|
|
|
with:
|
|
|
|
|
host: ${{ secrets.VPS1_SSH_HOST }}
|
|
|
|
|
username: ${{ secrets.VPS1_SSH_USER }}
|
|
|
|
|
key: ${{ secrets.VPS1_SSH_KEY }}
|
|
|
|
|
port: ${{ secrets.VPS1_SSH_PORT }}
|
|
|
|
|
script: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
cd /opt/thermograph-dev
|
|
|
|
|
git fetch --prune origin dev
|
|
|
|
|
git reset --hard origin/dev
|
2026-07-26 07:05:09 +00:00
|
|
|
echo "synced to $(git log --oneline -1)"
|
|
|
|
|
|
|
|
|
|
# RENDER ONLY IF THIS HOST IS ACTUALLY DEV.
|
|
|
|
|
#
|
|
|
|
|
# dev's env file is /etc/thermograph.env — the same path beta uses,
|
|
|
|
|
# and during the vps1/vps2 cutover beta is STILL ON VPS1. Rendering
|
|
|
|
|
# unconditionally would overwrite the live env file of the
|
|
|
|
|
# environment currently serving beta.thermograph.org with dev's
|
|
|
|
|
# credentials: beta's running containers would survive (env_file is
|
|
|
|
|
# read at container start) and then come up wrong on its next
|
|
|
|
|
# deploy, pointed at dev's database password.
|
|
|
|
|
#
|
|
|
|
|
# The host marker is the box's own statement of which environment it
|
|
|
|
|
# is, and it is the right authority for "is it safe to write this
|
|
|
|
|
# file here". It flips to `dev` in provision-dev.sh, which is run
|
|
|
|
|
# only after beta has vacated. Until then this skips loudly rather
|
|
|
|
|
# than failing: the checkout sync above is still useful and correct.
|
|
|
|
|
marker=$(cat /etc/thermograph/secrets-env 2>/dev/null || true)
|
|
|
|
|
if [ "$marker" != dev ]; then
|
|
|
|
|
echo "!! /etc/thermograph/secrets-env says '${marker:-<unset>}', not 'dev'."
|
|
|
|
|
echo "!! Skipping the secrets render — this host is not dev yet, and"
|
|
|
|
|
echo "!! /etc/thermograph.env here belongs to '${marker:-another environment}'."
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
2026-07-26 06:56:38 +00:00
|
|
|
if [ -f infra/deploy/render-secrets.sh ]; then
|
|
|
|
|
. infra/deploy/render-secrets.sh
|
|
|
|
|
# SKIP_COMMON is dev's standing rule, not a preference: common.yaml
|
|
|
|
|
# is the fleet's shared production credential set, and vps1 also
|
|
|
|
|
# runs Forgejo and its CI. See render-secrets.sh.
|
|
|
|
|
THERMOGRAPH_SECRETS_SKIP_COMMON=1 \
|
|
|
|
|
render_thermograph_secrets /opt/thermograph-dev/infra dev /etc/thermograph.env
|
|
|
|
|
fi
|
|
|
|
|
|
2026-07-23 05:11:33 +00:00
|
|
|
sync-beta:
|
2026-07-26 06:56:38 +00:00
|
|
|
if: github.ref_name == 'main'
|
2026-07-23 05:11:33 +00:00
|
|
|
runs-on: docker
|
|
|
|
|
concurrency:
|
|
|
|
|
group: infra-sync-beta
|
|
|
|
|
cancel-in-progress: false
|
|
|
|
|
steps:
|
2026-07-26 06:56:38 +00:00
|
|
|
- name: Sync beta checkout on vps2 + re-render secrets
|
2026-07-23 05:11:33 +00:00
|
|
|
uses: https://github.com/appleboy/ssh-action@v1.2.0
|
|
|
|
|
with:
|
2026-07-26 06:56:38 +00:00
|
|
|
host: ${{ secrets.VPS2_SSH_HOST }}
|
|
|
|
|
username: ${{ secrets.VPS2_SSH_USER }}
|
|
|
|
|
key: ${{ secrets.VPS2_SSH_KEY }}
|
|
|
|
|
port: ${{ secrets.VPS2_SSH_PORT }}
|
2026-07-23 05:11:33 +00:00
|
|
|
script: |
|
|
|
|
|
set -euo pipefail
|
2026-07-26 06:56:38 +00:00
|
|
|
cd /opt/thermograph-beta
|
2026-07-23 05:11:33 +00:00
|
|
|
git fetch --prune origin main
|
|
|
|
|
git reset --hard origin/main
|
|
|
|
|
if [ -f infra/deploy/render-secrets.sh ]; then
|
|
|
|
|
. infra/deploy/render-secrets.sh
|
2026-07-26 06:56:38 +00:00
|
|
|
render_thermograph_secrets /opt/thermograph-beta/infra beta /etc/thermograph-beta.env
|
2026-07-23 05:11:33 +00:00
|
|
|
fi
|
|
|
|
|
echo "synced to $(git log --oneline -1)"
|
|
|
|
|
|
|
|
|
|
sync-prod:
|
2026-07-26 06:56:38 +00:00
|
|
|
if: github.ref_name == 'main'
|
2026-07-23 05:11:33 +00:00
|
|
|
runs-on: docker
|
|
|
|
|
concurrency:
|
|
|
|
|
group: infra-sync-prod
|
|
|
|
|
cancel-in-progress: false
|
|
|
|
|
steps:
|
2026-07-26 06:56:38 +00:00
|
|
|
- name: Sync prod checkout on vps2 + re-render secrets
|
2026-07-23 05:11:33 +00:00
|
|
|
uses: https://github.com/appleboy/ssh-action@v1.2.0
|
|
|
|
|
with:
|
2026-07-26 06:56:38 +00:00
|
|
|
host: ${{ secrets.VPS2_SSH_HOST }}
|
|
|
|
|
username: ${{ secrets.VPS2_SSH_USER }}
|
|
|
|
|
key: ${{ secrets.VPS2_SSH_KEY }}
|
|
|
|
|
port: ${{ secrets.VPS2_SSH_PORT }}
|
2026-07-23 05:11:33 +00:00
|
|
|
script: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
cd /opt/thermograph
|
|
|
|
|
git fetch --prune origin main
|
|
|
|
|
git reset --hard origin/main
|
|
|
|
|
if [ -f infra/deploy/render-secrets.sh ]; then
|
|
|
|
|
. infra/deploy/render-secrets.sh
|
2026-07-26 06:56:38 +00:00
|
|
|
render_thermograph_secrets /opt/thermograph/infra prod /etc/thermograph.env
|
2026-07-23 05:11:33 +00:00
|
|
|
fi
|
|
|
|
|
echo "synced to $(git log --oneline -1)"
|