228 lines
11 KiB
YAML
228 lines
11 KiB
YAML
# Deploy this stack onto kasse. Every value the stack runs with is an
|
|
# Actions variable (vars.*: hosts, versions, where the content comes from)
|
|
# or secret (secrets.*: passwords, tokens, the first person's address) of
|
|
# this repo, or of the tomtervel org for what other repos share
|
|
# (LOAD_TOKEN, which the content repo's reload posts to the site, and
|
|
# PORTAL_RELEASE, which its lint runs). The table is
|
|
# in README.md. A new host name or a portal bump is a variable changed and
|
|
# then Run workflow; a change to the files here deploys on push.
|
|
#
|
|
# Runs on kasse's host runner, which is not root. It writes the env files
|
|
# into its own directory, and may run one script as root,
|
|
# /usr/local/bin/deploy-tomtervel (deploy-tomtervel here), which pulls
|
|
# main, puts those files in place and runs `podman compose up -d --build`.
|
|
name: deploy
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- compose.yml
|
|
- Caddyfile
|
|
- portal/**
|
|
- gdo/**
|
|
- rauthy-providers.sh
|
|
- rauthy-theme.sh
|
|
- rauthy/config.toml
|
|
- deploy-tomtervel
|
|
- .gitea/workflows/deploy.yml
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
deploy:
|
|
if: github.ref == 'refs/heads/main'
|
|
runs-on: fish
|
|
env:
|
|
STAGE: /var/lib/gitea-runner/tomtervel-env
|
|
# What the stack is.
|
|
PORTAL_HOST: ${{ vars.PORTAL_HOST }}
|
|
PAY_HOST: ${{ vars.PAY_HOST }}
|
|
PORTAL_RELEASE: ${{ vars.PORTAL_RELEASE }}
|
|
GDO_RELEASE: ${{ vars.GDO_RELEASE }}
|
|
KRON_RELEASE: ${{ vars.KRON_RELEASE }}
|
|
COMPOSE_PROFILES: ${{ vars.COMPOSE_PROFILES }}
|
|
CONTENT_REPO: ${{ vars.CONTENT_REPO }}
|
|
CONTENT_BRANCH: ${{ vars.CONTENT_BRANCH }}
|
|
SITE_NAME: ${{ vars.SITE_NAME }}
|
|
PEOPLE_BACKEND: ${{ vars.PEOPLE_BACKEND }}
|
|
RESPONSIBLE_GROUP: ${{ vars.RESPONSIBLE_GROUP }}
|
|
OAUTH2_CLIENT_ID: ${{ vars.OAUTH2_CLIENT_ID }}
|
|
GARAGE_S3_ENDPOINT: ${{ vars.GARAGE_S3_ENDPOINT }}
|
|
GARAGE_UPLOADS_BUCKET: ${{ vars.GARAGE_UPLOADS_BUCKET }}
|
|
# The programs beside the site (README.md, "The site's own
|
|
# network"): each one's key and what it may do, and the site's own
|
|
# key and where it listens. Public keys, said in the logs; set
|
|
# once, from what move-1.0/move.sh prints.
|
|
DHD_KEYS: ${{ vars.DHD_KEYS }}
|
|
PORTAL_DHD: ${{ vars.PORTAL_DHD }}
|
|
# Optional: sealed copies of the site's store, every six hours
|
|
# (README.md, "Backups"). PORTAL_BACKUP_TO is an age public key
|
|
# whose private half is kept off this host.
|
|
PORTAL_BACKUP_TO: ${{ vars.PORTAL_BACKUP_TO }}
|
|
GARAGE_BACKUPS_BUCKET: ${{ vars.GARAGE_BACKUPS_BUCKET }}
|
|
# What it runs with.
|
|
# The token the content repo's reload posts; the site is given
|
|
# its hash alone.
|
|
LOAD_TOKEN: ${{ secrets.LOAD_TOKEN }}
|
|
OAUTH2_CLIENT_SECRET: ${{ secrets.OAUTH2_CLIENT_SECRET }}
|
|
GARAGE_ACCESS_KEY: ${{ secrets.GARAGE_ACCESS_KEY }}
|
|
GARAGE_SECRET_KEY: ${{ secrets.GARAGE_SECRET_KEY }}
|
|
SEED_ADMIN_EMAIL: ${{ secrets.SEED_ADMIN_EMAIL }}
|
|
SEED_ADMIN_NAME: ${{ secrets.SEED_ADMIN_NAME }}
|
|
# Optional: unset, maps are off (the landing hero is empty, a
|
|
# location field is two numbers).
|
|
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
|
|
MAPBOX_STYLE: ${{ vars.MAPBOX_STYLE }}
|
|
# Who is who: Rauthy (README.md, "Rauthy"). RAUTHY_HOST and the
|
|
# three secrets run it; portal signs in at OIDC_ISSUER;
|
|
# RAUTHY_API_KEY lets portal make accounts there.
|
|
RAUTHY_HOST: ${{ vars.RAUTHY_HOST }}
|
|
RAUTHY_ENC_KEY: ${{ secrets.RAUTHY_ENC_KEY }}
|
|
RAUTHY_SECRET_RAFT: ${{ secrets.RAUTHY_SECRET_RAFT }}
|
|
RAUTHY_SECRET_API: ${{ secrets.RAUTHY_SECRET_API }}
|
|
# Optional, for Rauthy's very first start only: a short-lived key
|
|
# (base64 JSON, README.md "Rauthy") that makes the clients. Rauthy
|
|
# reads it into an empty database and never again.
|
|
RAUTHY_BOOTSTRAP_API_KEY: ${{ secrets.RAUTHY_BOOTSTRAP_API_KEY }}
|
|
RAUTHY_BOOTSTRAP_API_KEY_SECRET: ${{ secrets.RAUTHY_BOOTSTRAP_API_KEY_SECRET }}
|
|
OIDC_ISSUER: ${{ vars.OIDC_ISSUER }}
|
|
RAUTHY_API_KEY: ${{ secrets.RAUTHY_API_KEY }}
|
|
RAUTHY_LANGUAGE: ${{ vars.RAUTHY_LANGUAGE }}
|
|
# The money service (README.md, "Payments"): Vipps's keys for the
|
|
# Medlemskap sales unit, read by kron alone, from its env: with
|
|
# all four set kron asks the site for nothing. VIPPS_WEBHOOK_SECRET may wait, kron
|
|
# then settles by asking Vipps every minute instead.
|
|
VIPPS_MSN: ${{ vars.VIPPS_MSN }}
|
|
VIPPS_CLIENT_ID: ${{ secrets.VIPPS_CLIENT_ID }}
|
|
VIPPS_CLIENT_SECRET: ${{ secrets.VIPPS_CLIENT_SECRET }}
|
|
VIPPS_SUBSCRIPTION_KEY: ${{ secrets.VIPPS_SUBSCRIPTION_KEY }}
|
|
VIPPS_WEBHOOK_SECRET: ${{ secrets.VIPPS_WEBHOOK_SECRET }}
|
|
steps:
|
|
# The repo's own scripts (rauthy-providers.sh) run from the
|
|
# checkout; the stack itself is pulled on the host by
|
|
# deploy-tomtervel, not from here.
|
|
- uses: actions/checkout@v4
|
|
|
|
# A missing value stops here, by name, before anything on the host
|
|
# is touched. Only names are printed: the log is public.
|
|
- name: Write the env files
|
|
run: |
|
|
missing=
|
|
for v in PORTAL_HOST RAUTHY_HOST OIDC_ISSUER PORTAL_RELEASE GDO_RELEASE \
|
|
KRON_RELEASE CONTENT_REPO CONTENT_BRANCH SITE_NAME PEOPLE_BACKEND \
|
|
RESPONSIBLE_GROUP OAUTH2_CLIENT_ID \
|
|
GARAGE_S3_ENDPOINT GARAGE_UPLOADS_BUCKET \
|
|
DHD_KEYS PORTAL_DHD LOAD_TOKEN OAUTH2_CLIENT_SECRET \
|
|
RAUTHY_ENC_KEY RAUTHY_SECRET_RAFT RAUTHY_SECRET_API RAUTHY_API_KEY \
|
|
GARAGE_ACCESS_KEY GARAGE_SECRET_KEY SEED_ADMIN_EMAIL; do
|
|
[ -n "${!v}" ] || missing="$missing $v"
|
|
done
|
|
[ -z "$missing" ] || { echo "not set as an Actions variable or secret:$missing"; exit 1; }
|
|
pay=
|
|
case ",$COMPOSE_PROFILES," in *,pay,*) pay=1;; esac
|
|
if [ -n "$pay" ]; then
|
|
for v in PAY_HOST VIPPS_MSN VIPPS_CLIENT_ID VIPPS_CLIENT_SECRET VIPPS_SUBSCRIPTION_KEY; do
|
|
[ -n "${!v}" ] || missing="$missing $v"
|
|
done
|
|
[ -z "$missing" ] || { echo "COMPOSE_PROFILES has pay, but not set:$missing"; exit 1; }
|
|
fi
|
|
|
|
umask 077
|
|
mkdir -p "$STAGE"
|
|
# Interpolated by compose: hosts, versions, profiles. No secret.
|
|
cat > "$STAGE/.env" <<EOF
|
|
PORTAL_HOST=$PORTAL_HOST
|
|
PORTAL_RELEASE=$PORTAL_RELEASE
|
|
GDO_RELEASE=$GDO_RELEASE
|
|
KRON_RELEASE=$KRON_RELEASE
|
|
PORTAL_DHD=$PORTAL_DHD
|
|
COMPOSE_PROFILES=$COMPOSE_PROFILES
|
|
PAY_HOST=$PAY_HOST
|
|
RAUTHY_HOST=$RAUTHY_HOST
|
|
OIDC_ISSUER=$OIDC_ISSUER
|
|
EOF
|
|
# The site keeps no token, only its hash.
|
|
load_hash=$(printf %s "$LOAD_TOKEN" | sha256sum | cut -d' ' -f1)
|
|
cat > "$STAGE/portal.env" <<EOF
|
|
PUBLIC_URL=https://$PORTAL_HOST
|
|
DHD_KEYS=$DHD_KEYS
|
|
DHD_TOKENS=$load_hash=load
|
|
OAUTH2_CLIENT_ID=$OAUTH2_CLIENT_ID
|
|
OAUTH2_CLIENT_SECRET=$OAUTH2_CLIENT_SECRET
|
|
COOKIE_SECURE=true
|
|
CONTENT_REPO=$CONTENT_REPO
|
|
CONTENT_BRANCH=$CONTENT_BRANCH
|
|
SITE_NAME=$SITE_NAME
|
|
PEOPLE_BACKEND=$PEOPLE_BACKEND
|
|
RESPONSIBLE_GROUP=$RESPONSIBLE_GROUP
|
|
SEED_ADMIN_EMAIL=$SEED_ADMIN_EMAIL
|
|
SEED_ADMIN_NAME=$SEED_ADMIN_NAME
|
|
GARAGE_S3_ENDPOINT=$GARAGE_S3_ENDPOINT
|
|
GARAGE_ACCESS_KEY=$GARAGE_ACCESS_KEY
|
|
GARAGE_SECRET_KEY=$GARAGE_SECRET_KEY
|
|
GARAGE_UPLOADS_BUCKET=$GARAGE_UPLOADS_BUCKET
|
|
MAPBOX_TOKEN=$MAPBOX_TOKEN
|
|
MAPBOX_STYLE=$MAPBOX_STYLE
|
|
OIDC_ISSUER=$OIDC_ISSUER
|
|
RAUTHY_URL=${RAUTHY_HOST:+https://$RAUTHY_HOST}
|
|
RAUTHY_API_KEY=$RAUTHY_API_KEY
|
|
RAUTHY_LANGUAGE=$RAUTHY_LANGUAGE
|
|
EOF
|
|
# With the money service in the stack, portal may ask for
|
|
# payments without `by_hand`; the address itself is never
|
|
# called (kron dials the site), the lint only reads that it is
|
|
# set. The content repo's lint sets it the same way.
|
|
if [ -n "$pay" ]; then
|
|
echo "PAY_URL=http://127.0.0.1:3080" >> "$STAGE/portal.env"
|
|
fi
|
|
if [ -n "$PORTAL_BACKUP_TO" ] && [ -n "$GARAGE_BACKUPS_BUCKET" ]; then
|
|
printf 'PORTAL_BACKUP_TO=%s\nGARAGE_BACKUPS_BUCKET=%s\n' "$PORTAL_BACKUP_TO" "$GARAGE_BACKUPS_BUCKET" >> "$STAGE/portal.env"
|
|
fi
|
|
# kron: Vipps's keys for the Medlemskap sales unit (kron refuses
|
|
# some set and some not). Written even without the profile, so
|
|
# the file compose names is there.
|
|
{
|
|
echo "WEBHOOK_SECRET=$VIPPS_WEBHOOK_SECRET"
|
|
for name in VIPPS_MSN VIPPS_CLIENT_ID VIPPS_CLIENT_SECRET VIPPS_SUBSCRIPTION_KEY; do
|
|
if [ -n "${!name}" ]; then echo "$name=${!name}"; fi
|
|
done
|
|
} > "$STAGE/kron.env"
|
|
# Rauthy's secrets. The first admin is the vel's first person.
|
|
cat > "$STAGE/rauthy.env" <<EOF
|
|
ENC_KEYS=$RAUTHY_ENC_KEY
|
|
ENC_KEY_ACTIVE=${RAUTHY_ENC_KEY%%/*}
|
|
HQL_SECRET_RAFT=$RAUTHY_SECRET_RAFT
|
|
HQL_SECRET_API=$RAUTHY_SECRET_API
|
|
BOOTSTRAP_ADMIN_EMAIL=$SEED_ADMIN_EMAIL
|
|
RAUTHY_ADMIN_EMAIL=$SEED_ADMIN_EMAIL
|
|
EVENT_EMAIL=$SEED_ADMIN_EMAIL
|
|
EOF
|
|
if [ -n "$RAUTHY_BOOTSTRAP_API_KEY" ]; then
|
|
printf 'BOOTSTRAP_API_KEY=%s\nBOOTSTRAP_API_KEY_SECRET=%s\n' \
|
|
"$RAUTHY_BOOTSTRAP_API_KEY" "$RAUTHY_BOOTSTRAP_API_KEY_SECRET" >> "$STAGE/rauthy.env"
|
|
fi
|
|
# Compose reads an env_file the way it reads compose.yml: "$name" in
|
|
# a value is a variable to fill in, and one that is not set comes
|
|
# out empty. Every value above is the secret itself, so a "$" left
|
|
# in one is literal (Rauthy's API keys are "<name>$<secret>"), and
|
|
# "$$" is compose's literal "$". Without this, RAUTHY_API_KEY reached
|
|
# portal as "portal" alone, Rauthy answered 401, and every invite
|
|
# failed. .env is left alone: it is what compose.yml interpolates.
|
|
sed -i 's/\$/$$/g' "$STAGE/portal.env" "$STAGE/rauthy.env" "$STAGE/kron.env"
|
|
|
|
- name: Pull and bring the stack up
|
|
run: sudo /usr/local/bin/deploy-tomtervel
|
|
|
|
# The sign-in providers Rauthy offers (Vipps Login), kept by the
|
|
# deploy through Rauthy's API: rauthy-providers.sh. Unset values
|
|
# change nothing.
|
|
- name: Sign-in providers in Rauthy
|
|
env:
|
|
VIPPS_LOGIN_CLIENT_ID: ${{ vars.VIPPS_LOGIN_CLIENT_ID }}
|
|
VIPPS_LOGIN_CLIENT_SECRET: ${{ secrets.VIPPS_LOGIN_CLIENT_SECRET }}
|
|
run: ./rauthy-providers.sh
|
|
|
|
# The vel's colours on Rauthy's pages: rauthy-theme.sh. Needs the
|
|
# API key to have Clients read and update; without, it says so.
|
|
- name: Colours in Rauthy
|
|
run: ./rauthy-theme.sh
|