feat(admin): open a fresh region from the portal (ADR-0182 section 15)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m31s
Foundation / postgres-tools (push) Successful in 27s
Foundation / server-image (push) Successful in 4m33s
Foundation / image (push) Successful in 5m39s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m31s
Foundation / postgres-tools (push) Successful in 27s
Foundation / server-image (push) Successful in 4m33s
Foundation / image (push) Successful in 5m39s
The Regions page opens the next region in place of the one DEV serves: the admin API reads the region overlay, its kustomization, the grant broker and the portal deployment from main at one commit, rewrites only the region id, routes, genesis commit and seeded wildlife range (refusing files whose layout differs), commits them in one Gitea multi-file commit as aevolution-bot, then starts a full Argo sync of exactly that commit. The page follows the sync until the region is live, across the portal's own restart. Credentials come from Secret aevolution-admin mounted read-only as files (--deploy-config); without it the feature stays off. A small OpenSSL HTTPS client talks to Gitea (verified) and argocd-server (verification per ARGOCD_TLS_VERIFY). The portal's NetworkPolicy gains egress to the node's ingress for Gitea and to the argocd-server pods, as approved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -609,6 +609,7 @@ const tuningMap = (text) => new Map(parseTuning(text).flatMap((g) => g.settings.
|
||||
// ---------- Region list ----------
|
||||
async function regionsPage() {
|
||||
const data = await api('/api/regions');
|
||||
const opener = h('div', { class: 'card', style: { marginTop: '18px' } }, h('p', { class: 'hint' }, 'Loading…'));
|
||||
show(
|
||||
h('div', { class: 'head' }, h('div', {}, h('h1', {}, 'Regions'), h('div', { class: 'subtitle' }, `World ${data.world}`)),
|
||||
h('div', { class: 'tools' }, h('button', { onclick: () => route() }, 'Refresh'))),
|
||||
@@ -623,7 +624,121 @@ async function regionsPage() {
|
||||
{ key: 'build', label: 'Build', render: (r) => h('span', { class: 'mono', title: r.build || '' }, r.build ? r.build.slice(0, 12) : '—') },
|
||||
{ key: 'window_open', label: 'Sessions', render: windowBadge, sort: (r) => (r.window_open ? r.window_expires : 0) },
|
||||
{ key: 'viewable', label: '', render: (r) => (r.viewable ? h('a', { href: `#/regions/${r.region}` }, 'Open view →') : h('span', { class: 'muted' }, 'no view')) },
|
||||
], data.regions, { sortKey: 'region', onRow: (r) => { if (r.viewable) location.hash = `#/regions/${r.region}`; } }));
|
||||
], data.regions, { sortKey: 'region', onRow: (r) => { if (r.viewable) location.hash = `#/regions/${r.region}`; } }),
|
||||
opener);
|
||||
openRegionCard(opener);
|
||||
}
|
||||
|
||||
// ADR-0182 section 15: open a fresh region in place of the one DEV serves (one Git commit,
|
||||
// then a full Argo sync). The progress survives this tab reloading while the portal restarts.
|
||||
function argoBadges(argo) {
|
||||
if (!argo || argo.error) return h('span', { class: 'badge warn' }, `Argo unavailable${argo && argo.error ? `: ${argo.error}` : ''}`);
|
||||
const tone = (v, good) => (v === good ? 'alive' : v ? 'warn' : '');
|
||||
return h('span', {},
|
||||
h('span', { class: `badge ${tone(argo.phase, 'Succeeded')}`, title: argo.message || '' }, argo.phase || 'no operation'), ' ',
|
||||
h('span', { class: `badge ${tone(argo.sync, 'Synced')}` }, argo.sync || 'sync ?'), ' ',
|
||||
h('span', { class: `badge ${tone(argo.health, 'Healthy')}` }, argo.health || 'health ?'));
|
||||
}
|
||||
async function openRegionCard(card) {
|
||||
const progressKey = 'deploy-progress';
|
||||
const saved = (() => { try { return JSON.parse(sessionStorage.getItem(progressKey) || 'null'); } catch { return null; } })();
|
||||
if (saved && Date.now() - saved.at < 20 * 60 * 1000) return followOpening(card, saved, progressKey);
|
||||
let status;
|
||||
try { status = await api('/api/deploy'); } catch (e) { fill(card, h('h2', {}, 'Open a new region'), h('p', { class: 'error' }, `Unavailable: ${e.code || e.message}`)); return; }
|
||||
if (!status.configured) {
|
||||
fill(card, h('h2', {}, 'Open a new region'),
|
||||
h('p', { class: 'hint' }, 'Not configured: the admin API needs Secret aevolution-admin (Gitea and Argo CD settings and tokens) mounted at /run/deploy.'));
|
||||
return;
|
||||
}
|
||||
const problem = status.git && status.git.error ? `Git: ${status.git.error}` : status.layout_error ? `The region files changed shape (${status.layout_error}); edit them by hand.`
|
||||
: status.world_mismatch ? 'Git serves another world than this portal.' : !status.next ? 'The next region number is unavailable.' : '';
|
||||
const running = status.argo && status.argo.phase === 'Running';
|
||||
const reason = reasonInput();
|
||||
const confirmBox = h('input', { type: 'text', placeholder: status.next ? `Type ${status.next.region} to confirm` : '', class: 'count', style: { width: '170px' } });
|
||||
const note = h('div', { class: 'note' });
|
||||
const go = h('button', { class: 'primary', disabled: true }, status.next ? `Open region ${status.next.region}` : 'Open region');
|
||||
const ready = () => { go.disabled = !!problem || running || !status.next || confirmBox.value.trim() !== status.next.region; };
|
||||
confirmBox.addEventListener('input', ready);
|
||||
go.addEventListener('click', async () => {
|
||||
go.disabled = true;
|
||||
try {
|
||||
const q = new URLSearchParams({ region: status.next.region });
|
||||
if (reason.value.trim()) q.set('reason', reason.value.trim());
|
||||
const r = await api(`/api/deploy/region?${q}`, true, 'POST');
|
||||
const progress = { region: r.region, from: r.from, commit: r.commit, synced: r.sync_started, at: Date.now() };
|
||||
try { sessionStorage.setItem(progressKey, JSON.stringify(progress)); } catch { /* private mode */ }
|
||||
followOpening(card, progress, progressKey);
|
||||
} catch (e) {
|
||||
note.className = 'note error';
|
||||
const d = e.detail || {};
|
||||
note.textContent = {
|
||||
sync_running: 'An Argo sync is already running; try again when it finishes.',
|
||||
region_changed: `The next region is now ${d.expected}: reload.`,
|
||||
layout_changed: `The region files changed shape (${d.detail}).`,
|
||||
commit_refused: `Gitea refused the commit (HTTP ${d.status}); someone may have changed these files. Reload.`,
|
||||
gitea_unavailable: `Gitea is unreachable (${d.detail}).`,
|
||||
argo_unavailable: `Argo CD is unreachable (${d.detail}).`,
|
||||
}[e.code] || `Could not open the region: ${e.code || e.message}`;
|
||||
ready();
|
||||
}
|
||||
});
|
||||
const c = status.current || {}, n = status.next || {};
|
||||
const last = n.wildlife_count ? String(BigInt(n.wildlife_first) + BigInt(n.wildlife_count) - 1n) : '';
|
||||
fill(card,
|
||||
h('div', { class: 'card-head' }, h('h2', {}, 'Open a new region'), argoBadges(status.argo)),
|
||||
h('p', { class: 'hint' }, `Opens a fresh region in world ${c.world || '?'} and serves it in place of region ${c.region || '?'}. `,
|
||||
'The portal commits the change to Git (region values, grant broker and portal) and runs a full Argo sync: the provision hook opens the region first, then the region host, broker and this portal restart. ',
|
||||
'The current region stays in the stores but is no longer served.'),
|
||||
h('dl', { class: 'facts' },
|
||||
h('dt', {}, 'Serving now'), h('dd', {}, c.region ? `region ${c.region}` : '—'),
|
||||
h('dt', {}, 'Opens'), h('dd', {}, n.region ? h('strong', {}, `region ${n.region}`) : '—'),
|
||||
h('dt', {}, 'Seeded wildlife'), h('dd', { class: 'mono' }, n.wildlife_count ? `${n.wildlife_count} cells, ids ${n.wildlife_first}–${last}` : 'none'),
|
||||
h('dt', {}, 'Rules'), h('dd', {}, 'the Git baseline tuning files; adopt a revision afterwards to change them'),
|
||||
h('dt', {}, 'Repository'), h('dd', { class: 'mono' }, `${status.repository} @ ${status.branch}${status.git && status.git.head ? ` (${status.git.head.slice(0, 8)})` : ''}`),
|
||||
h('dt', {}, 'Application'), h('dd', { class: 'mono' }, status.application)),
|
||||
problem ? h('div', { class: 'callout', style: { marginTop: '12px' } }, problem) : null,
|
||||
running ? h('div', { class: 'callout', style: { marginTop: '12px' } }, 'An Argo sync is running; wait for it to finish.') : null,
|
||||
h('div', { class: 'form-row' }, reason, confirmBox, go), note);
|
||||
ready();
|
||||
}
|
||||
async function followOpening(card, progress, progressKey) {
|
||||
const steps = h('div', { class: 'list' });
|
||||
const step = (done, text, sub) => h('div', { class: 'list-item' },
|
||||
h('span', { class: `badge ${done === true ? 'alive' : done === false ? 'warn' : ''}` }, done === true ? 'done' : done === false ? 'waiting' : '…'),
|
||||
h('div', { class: 'grow' }, text, sub ? h('div', { class: 'sub' }, sub) : null));
|
||||
const finish = h('div', { class: 'form-row' });
|
||||
fill(card, h('div', { class: 'card-head' }, h('h2', {}, `Opening region ${progress.region}`), h('span', { class: 'muted small' }, `from region ${progress.from}`)), steps, finish);
|
||||
let stopped = false;
|
||||
const previous = stopPage;
|
||||
stopPage = () => { stopped = true; previous(); };
|
||||
const clear = () => { try { sessionStorage.removeItem(progressKey); } catch { /* */ } };
|
||||
for (;;) {
|
||||
if (stopped) return;
|
||||
let argo = null, regions = null, restarting = false;
|
||||
try { argo = (await api('/api/deploy?argo=1')).argo; } catch { restarting = true; }
|
||||
try { regions = await api('/api/regions'); } catch { restarting = true; }
|
||||
const target = regions && regions.regions.find((r) => String(r.region) === String(progress.region));
|
||||
const synced = argo && !argo.error && argo.revision === progress.commit && argo.phase === 'Succeeded';
|
||||
const live = target && target.lease_held && target.viewable;
|
||||
fill(steps,
|
||||
step(true, `Committed to Git`, h('span', { class: 'mono' }, progress.commit.slice(0, 12))),
|
||||
step(progress.synced ? (synced ? true : false) : false, progress.synced ? 'Full Argo sync of that commit' : 'Argo did not accept the sync request: start a full sync of the commit by hand',
|
||||
argo && !argo.error ? `${argo.phase || 'no operation'} · ${argo.sync} · ${argo.health}${argo.message ? ` · ${argo.message}` : ''}` : restarting ? 'the admin portal is restarting with the new region…' : ''),
|
||||
step(live ? true : false, `Region ${progress.region} provisioned and running`, target ? (target.lease_held ? `lease held · tick ${fmtInt(target.tick)}` : 'provisioned, waiting for the region host') : 'not provisioned yet'));
|
||||
if (live) {
|
||||
clear();
|
||||
fill(finish,
|
||||
h('a', { href: `#/regions/${progress.region}` }, h('button', { class: 'primary' }, `Open region ${progress.region} →`)),
|
||||
h('span', { class: 'hint', style: { margin: 0 } }, 'Players can join once a session window is open (region page, Access tab).'));
|
||||
return;
|
||||
}
|
||||
if (Date.now() - progress.at > 20 * 60 * 1000) {
|
||||
clear();
|
||||
fill(finish, h('div', { class: 'callout' }, 'Still not live after 20 minutes: check the Argo Application and the provision job.'));
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||
}
|
||||
}
|
||||
|
||||
function windowBadge(r) {
|
||||
|
||||
Reference in New Issue
Block a user