From cf8f9ceef9df01b188798526a5152256254c6f01 Mon Sep 17 00:00:00 2001 From: unimatrix Date: Tue, 17 Nov 2026 12:23:11 +0000 Subject: [PATCH 1/2] fix(ci): prune previous artifacts only after exact build is live --- .forgejo/workflows/web-deploy.yml | 8 ++ website/ops/README.md | 68 ++++++++----- website/scripts/build.mjs | 100 +++++++++---------- website/scripts/prune-ci-artifacts.mjs | 58 +++++++++++ website/tests/ci-artifact-retention.test.mjs | 34 +++++++ 5 files changed, 193 insertions(+), 75 deletions(-) create mode 100644 website/scripts/prune-ci-artifacts.mjs create mode 100644 website/tests/ci-artifact-retention.test.mjs diff --git a/.forgejo/workflows/web-deploy.yml b/.forgejo/workflows/web-deploy.yml index a64d1d5f..101ef3e8 100644 --- a/.forgejo/workflows/web-deploy.yml +++ b/.forgejo/workflows/web-deploy.yml @@ -76,3 +76,11 @@ jobs: printf '%s\n' '91.107.196.242 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC8x/XocsIz41fWHGty0DbZhSvafSQFt9jaHHgzdr55W root@ubuntu-4gb-fsn1-1' >> ~/.ssh/known_hosts ssh -p 22 -i ~/.ssh/deploy_key -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes dunedeploy@91.107.196.242 "$GITHUB_SHA" rm -f ~/.ssh/deploy_key + + - name: Prune previous CI artifacts after confirmed publication + if: github.ref == 'refs/heads/main' + continue-on-error: true + shell: bash + env: + REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: node website/scripts/prune-ci-artifacts.mjs diff --git a/website/ops/README.md b/website/ops/README.md index 37abb5c4..63f5140a 100644 --- a/website/ops/README.md +++ b/website/ops/README.md @@ -1,28 +1,46 @@ -# Migrated web deployment +# Migrated web deployment + +The production website is hosted at `91.107.196.242`. The Forgejo Actions +workflow pins that host's SSH key and can trigger deployment only from `main`. +Its deploy key is restricted to `/usr/local/bin/dunerealms-ci-trigger`, which +rejects commits that do not match the current main branch. + +Forgejo, repositories, artifact storage, the rootless runner, container data, +build workspaces and deployment state use `/mnt/HC_Volume_107481500/dunegit`. +Compatibility links preserve the existing application and home-directory paths. +The volume is part of the live service and must remain attached. The services +require its mount before starting, rather than writing to an empty mountpoint. + +`promote-safe-v3.py` is installed as +`/usr/local/sbin/dunerealms-promote-safe-v3`. It prepares an immutable release, +checks a candidate website and panel, updates their shared nginx configuration, +checks public readiness, and restores the previous routing if that check fails. +Retired background workers are stopped and the active process list is saved. + +The first successful promotion retires the migrated baseline systemd website +services. Subsequent candidates are supervised by `dunerealms-runtime.service`. +The separate Forgejo service remains `dunegit.service`. + +Run the promoter routing checks with: + +```sh +python3 -m unittest discover -s website/ops -p 'test_*.py' +``` -The production website is hosted at `91.107.196.242`. The Forgejo Actions -workflow pins that host's SSH key and can trigger deployment only from `main`. -Its deploy key is restricted to `/usr/local/bin/dunerealms-ci-trigger`, which -rejects commits that do not match the current main branch. +## CI artifact retention -Forgejo, repositories, artifact storage, the rootless runner, container data, -build workspaces and deployment state use `/mnt/HC_Volume_107481500/dunegit`. -Compatibility links preserve the existing application and home-directory paths. -The volume is part of the live service and must remain attached. The services -require its mount before starting, rather than writing to an empty mountpoint. +Feature CI runs build and test without uploading the website artifact. Main +publications keep their current artifact with a one-day expiry as a fallback. +`prune-ci-artifacts.mjs` runs after the asynchronous deploy trigger and waits +for `/ci-build.json` to report the exact CI commit. Only then can it remove +older `DuneRealms-Website` artifacts belonging to completed runs. It preserves +the current build, newer artifacts, running jobs, and all other artifact names. +A changed live commit stops deletion. Failed or unconfirmed deployment leaves +previous artifacts available. Cleanup errors are warnings and do not turn an +already successful publication into a failed deployment. -`promote-safe-v3.py` is installed as -`/usr/local/sbin/dunerealms-promote-safe-v3`. It prepares an immutable release, -checks a candidate website and panel, updates their shared nginx configuration, -checks public readiness, and restores the previous routing if that check fails. -Retired background workers are stopped and the active process list is saved. - -The first successful promotion retires the migrated baseline systemd website -services. Subsequent candidates are supervised by `dunerealms-runtime.service`. -The separate Forgejo service remains `dunegit.service`. - -Run the promoter routing checks with: - -```sh -python3 -m unittest discover -s website/ops -p 'test_*.py' -``` +Forgejo removes the corresponding physical chunks through its existing +`cleanup_actions` maintenance task; deleting API records need not immediately +increase free disk space. Deployed application releases and their rollback +retention are separate from CI artifact retention. No backups or Git history +are removed by this policy. diff --git a/website/scripts/build.mjs b/website/scripts/build.mjs index 8130ab63..b0f207f0 100644 --- a/website/scripts/build.mjs +++ b/website/scripts/build.mjs @@ -1,50 +1,50 @@ -import {HOUSE_STYLE_CSS} from './house-style.mjs'; -import {bankRatesPage} from './bank-rates-page.mjs'; -import{withCanonicalMenu,MAIN_MENU}from'./main-menu.mjs'; -import{withMenuBadges}from'./menu-updates.mjs'; -import{updatePortalNavigation}from'./portal-navigation.mjs'; -// Package the authored web and worker sources without rewriting their content. -import {readFileSync,writeFileSync,openSync,writeSync,closeSync,readdirSync,statSync,mkdirSync,existsSync,rmSync,cpSync} from 'node:fs';import path from 'node:path';import {fileURLToPath} from 'node:url'; -const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..'),web=path.join(root,'web'),dist=path.join(root,'dist'); -// Fail before packaging if a public menu destination or illustration is missing. -for(const [label,href,icon] of MAIN_MENU){ - const url=new URL(href); - if(url.hostname==='www.dunerealms.com'){ - const relative=url.pathname==='/'?'index.html':decodeURIComponent(url.pathname.slice(1)); - if(!existsSync(path.join(web,relative)))throw Error('Broken public menu link: '+label+' -> '+relative); - } - if(!existsSync(path.join(web,'assets',icon)))throw Error('Missing menu artwork: '+label+' -> '+icon); -} -for(const [page,dependencies] of [['shop.html',['shop-landing.css','shop-embed.js']],['kits.html',['kits.css','kits.js']]]){ - for(const file of dependencies)if(!existsSync(path.join(web,file)))throw Error('Missing '+page+' dependency: '+file); -} -// Menu badges are now published manually through Imperial Bureau. -const homepage=readFileSync(path.join(web,'index.html'),'utf8'); -const legalNotice=homepage.match(/