@wildshard/engine 0.1.20 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/lint/engine-sides.json +4 -0
- package/lint/shardfile-boundaries.mjs +4 -2
- package/lint/wildshard-plugin.js +1 -1
- package/package.json +3 -1
- package/scripts/audio-download-proof.mjs +1 -1
- package/scripts/chaos-proxy-core.mjs +14 -1
- package/scripts/chaos-proxy-proof.mjs +22 -0
- package/scripts/check-spelled-paths.mjs +6 -3
- package/scripts/committed-fast-checks.mjs +2 -2
- package/scripts/failmode-cases.d.mts +8 -0
- package/scripts/failmode-cases.mjs +97 -0
- package/scripts/failmode-proof.mjs +556 -0
- package/scripts/grid-crossing-nightly.mjs +5 -4
- package/scripts/grid-crossing-report.mjs +5 -2
- package/scripts/grid-crossing-tour.mjs +25 -8
- package/scripts/grid-crossing-walk-proof.mjs +3 -3
- package/scripts/hover-speed-probe.mjs +136 -0
- package/scripts/mmo-bots.mjs +7 -3
- package/scripts/net-lag-proof.mjs +4 -3
- package/scripts/online-rig.mjs +11 -9
- package/scripts/parity/boot-smoke.mjs +1 -1
- package/scripts/release-cook.mjs +113 -0
- package/scripts/test-products.json +0 -21
- package/scripts/vps/cook-follow.d.mts +6 -0
- package/scripts/vps/cook-follow.mjs +45 -0
- package/scripts/vps/harden-apply.sh +10 -1
- package/scripts/vps/rebuild.sh +120 -26
- package/scripts/vps/wildshard-apply.mjs +5 -1
- package/scripts/vps/wildshard-config +117 -3
- package/src/client/app/entry.ts +2 -3
- package/src/client/engine/boot/contentRead.ts +78 -9
- package/src/client/engine/boot/downloadGiveUp.ts +34 -0
- package/src/client/engine/boot/gpuFiles.ts +3 -3
- package/src/client/engine/boot/leaveAfterPaint.ts +4 -1
- package/src/client/engine/combat/EquipmentService.ts +2 -0
- package/src/client/engine/core/Game.ts +6 -2
- package/src/client/engine/core/shadowLayer.ts +18 -0
- package/src/client/engine/explore/pick.ts +13 -1
- package/src/client/engine/net/predictor.ts +12 -4
- package/src/client/engine/player/TouchControls.ts +3 -2
- package/src/client/engine/render/families/sceneSurface.ts +3 -1
- package/src/client/engine/telemetry/browserErrors.ts +3 -1
- package/src/client/engine/ui/ErrorModal.ts +1 -1
- package/src/client/engine/ui/Loading.ts +14 -2
- package/src/client/engine/ui/downloadFailed.ts +54 -0
- package/src/client/engine/ui/errorScreen.ts +51 -9
- package/src/client/engine/ui/hoverBoost.ts +31 -4
- package/src/client/engine/ui/styles/touch.css +6 -0
- package/src/client/game/boot/spawnDownload.ts +56 -7
- package/src/client/game/grid/copyPrompts.ts +3 -4
- package/src/client/game/grid/dataCellKit.ts +91 -0
- package/src/client/game/grid/enteredEquipment.ts +11 -2
- package/src/client/game/grid/live.ts +11 -301
- package/src/client/game/grid/liveSession.ts +33 -10
- package/src/client/game/grid/neighbourLife.ts +50 -32
- package/src/client/game/grid/reveal.ts +7 -2
- package/src/client/game/grid/session.ts +6 -70
- package/src/client/game/grid/shardfileFar.ts +13 -2
- package/src/client/game/plugin/weaponFamily.ts +6 -0
- package/src/client/game/shardfile/clientSource.ts +7 -3
- package/src/client/game/shardfile/clientWorker.ts +17 -7
- package/src/client/game/shardfile/groundMerge.ts +5 -3
- package/src/client/host/online/linkScreens.ts +12 -6
- package/src/client/host/online/reconnectStrip.ts +3 -2
- package/src/client/host/online/release.ts +87 -16
- package/src/client/host/online/releaseScreens.ts +108 -0
- package/src/client/host/online/shell.ts +46 -12
- package/src/client/host/online/voice.ts +45 -1
- package/src/client/host/online/voiceUi.ts +24 -6
- package/src/server/engine/sim/playerSim.ts +1 -1
- package/src/server/game/grid/room.ts +2 -38
- package/src/server/game/grid/simulation.ts +12 -6
- package/src/server/game/shardfile/declaredKitItems.ts +8 -2
- package/src/server/host/dedicated/cellHost.ts +9 -2
- package/src/server/host/dedicated/cellProtocol.ts +1 -1
- package/src/server/host/dedicated/cellWorker.ts +2 -2
- package/src/server/host/dedicated/dedicatedRoom.ts +22 -4
- package/src/server/host/dedicated/gridCells.ts +5 -3
- package/src/server/host/dedicated/main.ts +6 -4
- package/src/server/host/dedicated/roadRoom.ts +3 -0
- package/src/server/host/dedicated/workerTable.ts +0 -10
- package/src/server/host/dedicated/world.ts +39 -5
- package/src/server/host/standalone/cellWorld.ts +1 -1
- package/src/server/host/standalone/gridServer.ts +1 -1
- package/src/shared/engine/boot/loadingWaits.ts +10 -2
- package/src/shared/engine/core/config.ts +3 -0
- package/src/shared/engine/player/hoverSpeed.ts +3 -3
- package/src/shared/engine/saves/shape.ts +17 -2
- package/src/shared/engine/strings.ts +22 -1
- package/src/shared/game/grid/placementRows.ts +4 -3
- package/src/shared/game/grid/rules.ts +12 -0
- package/src/client/game/grid/cellLoading.ts +0 -110
- package/src/client/game/grid/cellScreens.ts +0 -48
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// MMO-SERVER MS2.4a: turn staging's signed release into the root-owned state
|
|
3
|
+
// that selects the cook checkout. cook.env deliberately contains credentials only.
|
|
4
|
+
import { createPublicKey, verify } from 'node:crypto';
|
|
5
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { dirname } from 'node:path';
|
|
7
|
+
import { pathToFileURL } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const BUILD = /^[0-9a-f]{40}$/u, TAG = /^server-staging-([0-9a-f]{40})$/u;
|
|
10
|
+
/** @param {string} text @param {string} name */
|
|
11
|
+
const value = (text, name) => [...text.matchAll(new RegExp(`^${name}=(.*)$`, 'gmu'))].pop()?.[1]?.trim().replaceAll(/^["']|["']$/gu, '') ?? '';
|
|
12
|
+
/** @param {string} name */
|
|
13
|
+
const argument = name => { const index = process.argv.indexOf(name), next = process.argv[index + 1]; if (index === -1 || next === undefined) throw new Error(`Missing ${name}`); return next; };
|
|
14
|
+
|
|
15
|
+
/** @param {string} text @param {string} key */
|
|
16
|
+
export function signedCookRelease(text, key) {
|
|
17
|
+
const signed = JSON.parse(text);
|
|
18
|
+
if (typeof signed?.body !== 'string' || typeof signed?.signature !== 'string' || !/^(?:[0-9a-f]{2})+$/u.test(signed.signature)) throw new Error('Invalid signed release');
|
|
19
|
+
const publicKey = createPublicKey({ key: Buffer.from(key, 'hex'), format: 'der', type: 'spki' });
|
|
20
|
+
if (!verify(null, Buffer.from(signed.body), publicKey, Buffer.from(signed.signature, 'hex'))) throw new Error('A release file has a bad signature');
|
|
21
|
+
const release = JSON.parse(signed.body), tag = typeof release?.bundle?.name === 'string' ? release.bundle.name.split('/')[0] : '';
|
|
22
|
+
if (release?.channel !== 'staging' || typeof release.engineBuild !== 'string' || !BUILD.test(release.engineBuild) || !TAG.test(tag) || tag.slice('server-staging-'.length) !== release.engineBuild) throw new Error('The signed staging release has no matching server tag and build');
|
|
23
|
+
return { tag, build: release.engineBuild };
|
|
24
|
+
}
|
|
25
|
+
/** @param {string} path @param {string} text */
|
|
26
|
+
function atomic(path, text) {
|
|
27
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o750 });
|
|
28
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
29
|
+
try { writeFileSync(temporary, text, { mode: 0o600 }); renameSync(temporary, path); }
|
|
30
|
+
finally { rmSync(temporary, { force: true }); }
|
|
31
|
+
}
|
|
32
|
+
async function main() {
|
|
33
|
+
const env = argument('--env'), state = argument('--state'), envText = readFileSync(env, 'utf8');
|
|
34
|
+
const check = process.argv.includes('--check');
|
|
35
|
+
const url = value(envText, 'RELEASE_URL'), key = value(envText, 'RELEASE_PUBLIC_KEY');
|
|
36
|
+
if (!url.startsWith('https://') || key === '') throw new Error('staging.env has no HTTPS signed release configuration');
|
|
37
|
+
const response = await fetch(url, { cache: 'no-store', signal: AbortSignal.timeout(20_000), redirect: 'error' });
|
|
38
|
+
if (!response.ok) throw new Error(`The signed staging release answered ${response.status}`);
|
|
39
|
+
const next = signedCookRelease(await response.text(), key), text = `COOK_ENGINE_REF=${next.tag}\nWILDSHARD_BUILD=${next.build}\n`;
|
|
40
|
+
if (check) { console.info('would'); return; }
|
|
41
|
+
let held = ''; try { held = readFileSync(state, 'utf8'); } catch (error) { if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT')) throw error; }
|
|
42
|
+
if (held === text) { console.info('unchanged'); return; }
|
|
43
|
+
atomic(state, text); console.info('changed');
|
|
44
|
+
}
|
|
45
|
+
if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) await main();
|
|
@@ -363,9 +363,18 @@ if put /usr/local/sbin/wildshard-alert 755 root:root VH14 <<'EOF'
|
|
|
363
363
|
# sudo runs PAM with an empty environment, so the path is its own.
|
|
364
364
|
PATH=/usr/sbin:/usr/bin:/sbin:/bin
|
|
365
365
|
[ "${PAM_TYPE:-open_session}" = open_session ] || exit 0
|
|
366
|
+
# SENTRY-TRIAGE S16: an SSH login over the tailnet (100.64.0.0/10, fd7a:115c:a1e0::/48) is our own operator or agent, so it sends
|
|
367
|
+
# nothing. A login from any other address, sudo, the console and fail2ban's bans (the failed logins) still report.
|
|
368
|
+
if [ $# -eq 0 ] && [ "${PAM_SERVICE:-}" = sshd ]; then
|
|
369
|
+
case ${PAM_RHOST:-} in
|
|
370
|
+
100.6[4-9].*|100.[7-9][0-9].*|100.1[01][0-9].*|100.12[0-7].*|[Ff][Dd]7[Aa]:115[Cc]:[Aa]1[Ee]0:*) exit 0 ;;
|
|
371
|
+
esac
|
|
372
|
+
fi
|
|
373
|
+
line=${1:-"${PAM_SERVICE:-?}: ${PAM_USER:-?}${PAM_RUSER:+ (by $PAM_RUSER)} from ${PAM_RHOST:-the box}"}
|
|
374
|
+
# Tests only: print the line instead of sending it. PAM and fail2ban never set it.
|
|
375
|
+
[ -z "${WILDSHARD_ALERT_PRINT:-}" ] || { printf '%s\n' "$line"; exit 0; }
|
|
366
376
|
dsn=$(sed -n 's/^SENTRY_CRON_DSN=//p' /etc/wildshard/ops.env 2>/dev/null | tail -n 1)
|
|
367
377
|
[ -n "$dsn" ] || exit 0
|
|
368
|
-
line=${1:-"${PAM_SERVICE:-?}: ${PAM_USER:-?}${PAM_RUSER:+ (by $PAM_RUSER)} from ${PAM_RHOST:-the box}"}
|
|
369
378
|
key=${dsn#*://} key=${key%%@*} rest=${dsn#*@}
|
|
370
379
|
body=$(python3 -I -c 'import json, sys, socket, uuid; print(json.dumps({"event_id": uuid.uuid4().hex, "level": "warning", "logger": "wildshard-auth", "platform": "other", "server_name": socket.gethostname(), "environment": "production", "message": {"formatted": sys.argv[1]}, "tags": {"kind": "auth"}}))' "$line" 2>/dev/null) || exit 0
|
|
371
380
|
( curl -fsS -m 5 -o /dev/null -H 'Content-Type: application/json' \
|
package/scripts/vps/rebuild.sh
CHANGED
|
@@ -7,20 +7,25 @@
|
|
|
7
7
|
# 4. The cook worker (C4): an engine checkout at a tag, its user, its AppArmor allowance and its unit. It needs cook.env.
|
|
8
8
|
# sudo bash rebuild.sh do what is missing. Exit 0 is done; exit 2 is waiting for one of Jake's inputs
|
|
9
9
|
# bash rebuild.sh --check change nothing and say what it would do; protected state says `cannot verify`
|
|
10
|
+
# sudo bash rebuild.sh --cook step 4 alone (AUTO-RELEASE AR3): `wildshard-config cook <tag>` runs it as root after
|
|
11
|
+
# writing cook.settings, whose COOK_ENGINE_REF and WILDSHARD_BUILD win over cook.env's
|
|
10
12
|
# Keep this beside the other scripts/vps files. docs/vps-setup.md, "Rebuild from nothing", has the steps around it.
|
|
11
13
|
# HARD STOP (Jake, 2026-11-09): this never runs on the old VPS. Nothing there is rebuilt until OPENCLAW-EXTRACT's OX10
|
|
12
14
|
# is signed, so a host that still holds OpenClaw, Coolify, clawdbot or Ollama state is refused in both modes.
|
|
13
15
|
# Port 443 and `rooms.wildshard.io` are Jake's, after VPS-HARDENING VH16 (J179): Caddy is installed and left off.
|
|
14
16
|
set -euo pipefail
|
|
15
|
-
CHECK=0
|
|
16
|
-
if [ "$
|
|
17
|
-
elif [ "$#"
|
|
17
|
+
CHECK=0 COOK_ONLY=0 PHASE2=0
|
|
18
|
+
if [ "$#" = 1 ] && [ "$1" = --check ]; then CHECK=1
|
|
19
|
+
elif [ "$#" = 1 ] && [ "$1" = --cook ]; then COOK_ONLY=1
|
|
20
|
+
elif [ "$#" != 0 ]; then printf 'stop Expected no arguments, --check or --cook\n'; exit 1; fi
|
|
18
21
|
HERE=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
|
19
22
|
ETC=/etc/wildshard HOME_DIR=/var/lib/wildshard SYSTEMD=/etc/systemd/system
|
|
20
23
|
PG_VERSION=16 NODE=/usr/bin/node NODE_MAJOR=24 PNPM=pnpm@10.34.9
|
|
21
24
|
KEY_DIR=/home/raynos/wildshard-e7 KEY_FILE=/home/raynos/wildshard-e7/release-public-key.hex
|
|
22
|
-
COOK_ENV=/etc/wildshard/cook.env COOK_HOME=/var/lib/wildshard-cook COOK_SRC=/opt/wildshard/engine COOK_LIB=/usr/local/lib/wildshard-cook
|
|
25
|
+
COOK_ENV=/etc/wildshard/cook.env COOK_STATE=/etc/wildshard/cook-release.env COOK_HOME=/var/lib/wildshard-cook COOK_SRC=/opt/wildshard/engine COOK_LIB=/usr/local/lib/wildshard-cook
|
|
26
|
+
COOK_PNPM_STORE=/var/lib/wildshard-pnpm-store
|
|
23
27
|
COOK_GROUP=wildshard-cook
|
|
28
|
+
COOK_SETTINGS=/etc/wildshard/cook.settings
|
|
24
29
|
# 8790 and 8791 are the game's loopback ports; the cook worker's own default was 8791 too.
|
|
25
30
|
COOK_PORT=8792
|
|
26
31
|
ENGINE_GIT=https://github.com/project-wildshard/engine.git
|
|
@@ -80,10 +85,18 @@ env_value() { sed -n "s/^$2=//p" "$1" 2>/dev/null | tail -n 1; }
|
|
|
80
85
|
# The cook worker starts only once its env file names a build, an API, a token and one store (R2's four rows or a folder).
|
|
81
86
|
cook_env_complete() {
|
|
82
87
|
local file=$1 name
|
|
83
|
-
|
|
88
|
+
# The signed staging release supplies the ref and build. cook.env has credentials only.
|
|
89
|
+
for name in COOK_NOTIFY_TOKEN; do [ -n "$(env_value "$file" "$name")" ] || return 1; done
|
|
84
90
|
if [ -n "$(env_value "$file" COOK_STORE_DIR)" ]; then return 0; fi
|
|
85
91
|
for name in R2_ACCOUNT_ID R2_BUCKET_PACKS R2_PACKS_ACCESS_KEY_ID R2_PACKS_SECRET_ACCESS_KEY; do [ -n "$(env_value "$file" "$name")" ] || return 1; done
|
|
86
92
|
}
|
|
93
|
+
# AUTO-RELEASE AR3 (J355) writes an explicit tag and build to cook.settings. It wins over staging's signed follow state,
|
|
94
|
+
# which wins over legacy cook.env values, exactly as the service's EnvironmentFile order does.
|
|
95
|
+
cook_value() {
|
|
96
|
+
if [ -r "$COOK_SETTINGS" ] && grep -q "^$2=" "$COOK_SETTINGS"; then env_value "$COOK_SETTINGS" "$2"
|
|
97
|
+
elif [ -r "$COOK_STATE" ] && grep -q "^$2=" "$COOK_STATE"; then env_value "$COOK_STATE" "$2"
|
|
98
|
+
else env_value "$1" "$2"; fi
|
|
99
|
+
}
|
|
87
100
|
# Caddy's package ships a page on port 80. Only that file, byte for byte as dpkg recorded it, or this script's own
|
|
88
101
|
# placeholder is replaced; any other file is VH9's and is never touched.
|
|
89
102
|
CADDY_PLACEHOLDER="# MMO-PLAN MP0.1: Caddy is installed and off. VPS-HARDENING VH9 writes this file, and port 443 opens by Jake's hand
|
|
@@ -106,12 +119,20 @@ wait_http() {
|
|
|
106
119
|
|
|
107
120
|
# --- Before anything
|
|
108
121
|
if [ "$CHECK" = 0 ] && [ "$(id -u)" != 0 ]; then say stop 'Run with sudo, or pass --check'; exit 1; fi
|
|
109
|
-
|
|
122
|
+
# AUTO-RELEASE AR3: one rebuild at a time, whichever way it was started (a full run, --cook from wildshard-config cook,
|
|
123
|
+
# wildshard-apply <tag> rebuild), so two never move the cook's checkout or install into it at once.
|
|
124
|
+
if [ "$CHECK" = 0 ]; then exec 9>/run/wildshard-rebuild.lock; flock 9; fi
|
|
125
|
+
REQUIRED=(setup.sh setup-state.mjs pull.mjs dump.sh restore-check.sh uptime.sh health-stub.mjs wildshard-config wildshard-apply.mjs wildshard-agent.pub)
|
|
126
|
+
if [ "$COOK_ONLY" = 1 ]; then REQUIRED=(cook-follow.mjs); fi
|
|
127
|
+
for name in "${REQUIRED[@]}"; do
|
|
110
128
|
if [ ! -f "$HERE/$name" ]; then say stop "$name must sit beside rebuild.sh"; exit 1; fi
|
|
111
129
|
done
|
|
112
130
|
# The one trusted public key lives in setup.sh; this stages a copy of it, never another.
|
|
113
|
-
EXPECTED_KEY
|
|
114
|
-
if
|
|
131
|
+
EXPECTED_KEY=''
|
|
132
|
+
if [ "$COOK_ONLY" = 0 ]; then
|
|
133
|
+
EXPECTED_KEY=$(sed -n 's/^EXPECTED_RELEASE_PUBLIC_KEY=\([0-9a-f]*\)$/\1/p' "$HERE/setup.sh")
|
|
134
|
+
if ! [[ "$EXPECTED_KEY" =~ ^302a300506032b6570032100[0-9a-f]{64}$ ]]; then say stop 'Cannot read the release public key from setup.sh'; exit 1; fi
|
|
135
|
+
fi
|
|
115
136
|
# shellcheck source=/dev/null
|
|
116
137
|
. /etc/os-release
|
|
117
138
|
if [ "${VERSION_CODENAME:-}" != noble ]; then say stop "Written for Ubuntu 24.04 (noble), and this is ${PRETTY_NAME:-unknown}"; exit 1; fi
|
|
@@ -121,6 +142,8 @@ if [ "$(uname -m)" != x86_64 ]; then say warn "The VPS is x86_64, and this is $(
|
|
|
121
142
|
CPUS=$(nproc) SHARED_CPUS='AllowedCPUs=13-15'
|
|
122
143
|
if [ "$CPUS" -lt 16 ]; then say warn "The units' AllowedCPUs assume 16 cores, and this has $CPUS"; SHARED_CPUS="# AllowedCPUs=13-15 needs 16 cores; this box has $CPUS"; fi
|
|
123
144
|
|
|
145
|
+
# AUTO-RELEASE AR3: --cook is step 4 alone; the box already has what steps 1 to 3 make.
|
|
146
|
+
if [ "$COOK_ONLY" = 0 ]; then
|
|
124
147
|
# --- 1. Packages
|
|
125
148
|
APT_UPDATED=0
|
|
126
149
|
apt_update() { if [ "$APT_UPDATED" = 0 ]; then apt-get update -qq; APT_UPDATED=1; fi; }
|
|
@@ -363,7 +386,6 @@ if [ -f "$HERE/harden.sh" ]; then
|
|
|
363
386
|
else say skip 'harden.sh is not written yet (VPS-HARDENING-PLAN); it must pass VH16 before port 443'; fi
|
|
364
387
|
|
|
365
388
|
# --- 3. Phase 2, once the box is on the tailnet
|
|
366
|
-
PHASE2=0
|
|
367
389
|
if ! tailnet_up; then
|
|
368
390
|
if [ "$CHECK" = 1 ] && [ ! -x "$NODE" ]; then say would 'run setup.sh once Tailscale is installed and up'
|
|
369
391
|
else wait_for 'Tailscale is not logged in: run `sudo tailscale up --ssh`, then run rebuild.sh again (Phase 2 needs the node name)'; fi
|
|
@@ -375,6 +397,7 @@ else
|
|
|
375
397
|
bash "$HERE/setup.sh"
|
|
376
398
|
PHASE2=1
|
|
377
399
|
fi
|
|
400
|
+
fi # COOK_ONLY: --cook skips steps 1 to 3
|
|
378
401
|
|
|
379
402
|
# --- 4. The cook worker (C4, J28): its own user, an engine checkout it can read and not write, and its unit.
|
|
380
403
|
have_cook_user() { id wildshard-cook >/dev/null 2>&1 && getent group wildshard-cook >/dev/null; }
|
|
@@ -384,14 +407,24 @@ COOK_FOLDERS=("$COOK_HOME" "$COOK_HOME/scratch" "$COOK_HOME/server" "$COOK_HOME/
|
|
|
384
407
|
have_cook_folders() { local path; for path in "${COOK_FOLDERS[@]}"; do [ -d "$path" ] && metadata_ok "$path" 750 wildshard-cook:wildshard-cook || return 1; done; }
|
|
385
408
|
make_cook_folders() { install -d -m 750 -o wildshard-cook -g wildshard-cook "${COOK_FOLDERS[@]}"; }
|
|
386
409
|
step 'cook folders' have_cook_folders make_cook_folders
|
|
410
|
+
# GVS G9: pnpm must not choose /root's store (hidden by ProtectHome), and the
|
|
411
|
+
# cook account must only read the packages root installed. Keep the whole tree
|
|
412
|
+
# below a root-owned parent so the worker cannot replace a path the installer uses.
|
|
413
|
+
cook_store_unreadable() {
|
|
414
|
+
find "$COOK_PNPM_STORE" ! -type l \( ! -user root -o ! -group "$COOK_GROUP" -o ! -perm -g+r -o -perm -g+w -o -perm -o+w \
|
|
415
|
+
-o \( -type d ! -perm -g+x \) \) -print -quit
|
|
416
|
+
}
|
|
417
|
+
have_cook_store() { [ -d "$COOK_PNPM_STORE" ] && [ -z "$(cook_store_unreadable)" ]; }
|
|
418
|
+
make_cook_store() {
|
|
419
|
+
install -d -m 750 -o root -g "$COOK_GROUP" "$COOK_PNPM_STORE"
|
|
420
|
+
find "$COOK_PNPM_STORE" ! -type l -exec chown root:"$COOK_GROUP" {} +
|
|
421
|
+
find "$COOK_PNPM_STORE" ! -type l -exec chmod g+rX,g-w,o-w {} +
|
|
422
|
+
}
|
|
423
|
+
step "cook pnpm store $COOK_PNPM_STORE" have_cook_store make_cook_store
|
|
387
424
|
if [ "$(id -u)" != 0 ] && [ -d "$ETC" ] && [ ! -x "$ETC" ]; then say 'cannot verify' "$COOK_ENV (needs sudo)"
|
|
388
425
|
elif put_once "$COOK_ENV" 600 root:root <<'EOF'
|
|
389
|
-
# C4: the cook worker.
|
|
390
|
-
#
|
|
391
|
-
COOK_ENGINE_REF=
|
|
392
|
-
WILDSHARD_BUILD=
|
|
393
|
-
# Where it lists the catalogue and downloads shardfiles
|
|
394
|
-
WILDSHARD_API_URL=https://api.wildshard.io
|
|
426
|
+
# C4: the cook worker. Its signed staging release chooses its engine tag and build.
|
|
427
|
+
# Only credentials belong here; run rebuild.sh again after filling them.
|
|
395
428
|
# The bearer token api-server's notify call sends (J30). The same value goes in api-server's settings.
|
|
396
429
|
COOK_NOTIFY_TOKEN=
|
|
397
430
|
# Where packs go: the four R2 rows, or, on a scratch box only, COOK_STORE_DIR (a folder under /var/lib/wildshard-cook).
|
|
@@ -425,10 +458,22 @@ EOF
|
|
|
425
458
|
then if [ "$CHECK" = 0 ]; then apparmor_parser -r /etc/apparmor.d/wildshard-cook-unshare; fi; fi
|
|
426
459
|
else say ok 'unprivileged user namespaces are not restricted here; no AppArmor profile needed'; fi
|
|
427
460
|
|
|
428
|
-
COOK_REF='' COOK_READY=0
|
|
429
|
-
|
|
461
|
+
COOK_REF='' COOK_BUILD='' COOK_READY=0
|
|
462
|
+
cook_follow() {
|
|
463
|
+
if [ "$CHECK" = 1 ]; then "$NODE" "$HERE/cook-follow.mjs" --check --env "$ETC/staging.env" --state "$COOK_STATE"
|
|
464
|
+
else "$NODE" "$HERE/cook-follow.mjs" --env "$ETC/staging.env" --state "$COOK_STATE"; fi
|
|
465
|
+
}
|
|
466
|
+
if [ -r "$COOK_ENV" ] && cook_env_complete "$COOK_ENV"; then
|
|
467
|
+
if cook_follow; then
|
|
468
|
+
COOK_REF=$(cook_value "$COOK_ENV" COOK_ENGINE_REF)
|
|
469
|
+
COOK_BUILD=$(cook_value "$COOK_ENV" WILDSHARD_BUILD)
|
|
470
|
+
[ -n "$COOK_REF" ] && [ -n "$COOK_BUILD" ] && COOK_READY=1
|
|
471
|
+
else
|
|
472
|
+
wait_for 'The signed staging release did not supply a usable cook ref and build; the cook stays off'
|
|
473
|
+
fi
|
|
474
|
+
fi
|
|
430
475
|
if [ "$COOK_READY" = 0 ]; then
|
|
431
|
-
if [ -r "$COOK_ENV" ] || [ "$CHECK" = 0 ]; then wait_for "Fill $COOK_ENV (
|
|
476
|
+
if [ -r "$COOK_ENV" ] || [ "$CHECK" = 0 ]; then wait_for "Fill $COOK_ENV (notify token and R2 or a folder), then run rebuild.sh again"
|
|
432
477
|
elif [ "$(id -u)" = 0 ]; then say would "wait for $COOK_ENV to be filled"
|
|
433
478
|
else say 'cannot verify' "$COOK_ENV (needs sudo)"; fi
|
|
434
479
|
fi
|
|
@@ -439,8 +484,9 @@ org_git() { env GIT_CONFIG_COUNT=2 GIT_CONFIG_KEY_0=url.https://github.com/proje
|
|
|
439
484
|
GIT_CONFIG_KEY_1=url.https://github.com/project-wildshard/.insteadof GIT_CONFIG_VALUE_1=ssh://git@github.com/project-wildshard/ "$@"; }
|
|
440
485
|
cook_commit() { git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" rev-parse HEAD 2>/dev/null; }
|
|
441
486
|
have_cook_source() {
|
|
442
|
-
[ -f "$COOK_SRC/.wildshard-installed" ] && [ "$(cat "$COOK_SRC/.wildshard-installed")" = "$COOK_REF $
|
|
443
|
-
&& [ "$(
|
|
487
|
+
[ -f "$COOK_SRC/.wildshard-installed" ] && [ "$(cat "$COOK_SRC/.wildshard-installed")" = "$COOK_REF $COOK_BUILD" ] \
|
|
488
|
+
&& [ "$(cook_commit)" = "$COOK_BUILD" ] \
|
|
489
|
+
&& [ "$(git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" rev-parse "$COOK_REF^{commit}" 2>/dev/null)" = "$COOK_BUILD" ]
|
|
444
490
|
}
|
|
445
491
|
make_cook_source() {
|
|
446
492
|
install -d -m 755 -o root -g root "$(dirname "$COOK_SRC")"
|
|
@@ -449,10 +495,12 @@ make_cook_source() {
|
|
|
449
495
|
git -C "$COOK_SRC" sparse-checkout set --no-cone '/*' '!/progress/' '!/art/' '!/sources/'
|
|
450
496
|
fi
|
|
451
497
|
git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" fetch --quiet --tags origin
|
|
452
|
-
git -c safe.directory="$COOK_SRC" -C "$COOK_SRC"
|
|
498
|
+
if [ "$(git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" rev-parse "$COOK_REF^{commit}" 2>/dev/null)" != "$COOK_BUILD" ]; then say stop "The signed release's $COOK_REF does not resolve to $COOK_BUILD"; exit 1; fi
|
|
453
499
|
rm -f "$COOK_SRC/.wildshard-installed"
|
|
454
|
-
|
|
455
|
-
|
|
500
|
+
git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" checkout --quiet --force --detach "$COOK_BUILD"
|
|
501
|
+
(cd "$COOK_SRC" && org_git env CI=1 HOME=/root COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack "$PNPM" install --frozen-lockfile --ignore-scripts --config.confirmModulesPurge=false --config.ci=false --store-dir "$COOK_PNPM_STORE" --virtual-store-dir "$COOK_PNPM_STORE/links")
|
|
502
|
+
(cd "$COOK_SRC" && "$NODE" scripts/assert-store-layout.mjs)
|
|
503
|
+
printf '%s %s\n' "$COOK_REF" "$COOK_BUILD" > "$COOK_SRC/.wildshard-installed"
|
|
456
504
|
chmod -R go-w "$COOK_SRC"
|
|
457
505
|
}
|
|
458
506
|
# MMO-SERVER MS2.4b: root clones under the box's umask 027, so the checkout came out 750 root:root and the cook, its own user,
|
|
@@ -473,9 +521,17 @@ if [ "$COOK_READY" = 1 ]; then
|
|
|
473
521
|
step "cook source $COOK_SRC at $COOK_REF" have_cook_source make_cook_source
|
|
474
522
|
if [ "$CHECK" = 0 ] && ! have_cook_read; then COOK_SOURCE_CHANGED=1; fi
|
|
475
523
|
step "cook source readable by $COOK_GROUP" have_cook_read make_cook_read
|
|
524
|
+
step "cook pnpm store readable by $COOK_GROUP" have_cook_store make_cook_store
|
|
476
525
|
fi
|
|
477
|
-
# What the running worker last read of cook.env, as a hash in its root-owned checkout
|
|
478
|
-
|
|
526
|
+
# What the running worker last read of cook.env, signed follow state and cook.settings, as a hash in its root-owned checkout.
|
|
527
|
+
# A changed value restarts it; absent optional files preserve the legacy cook.env-only hash.
|
|
528
|
+
cook_env_hash() {
|
|
529
|
+
{
|
|
530
|
+
cat "$COOK_ENV"
|
|
531
|
+
if [ -r "${COOK_STATE:-}" ]; then cat "$COOK_STATE"; fi
|
|
532
|
+
if [ -r "${COOK_SETTINGS:-}" ]; then cat "$COOK_SETTINGS"; fi
|
|
533
|
+
} | sha256sum | cut -d' ' -f1
|
|
534
|
+
}
|
|
479
535
|
|
|
480
536
|
if put "$SYSTEMD/wildshard-cook.service" 644 root:root <<EOF
|
|
481
537
|
[Unit]
|
|
@@ -490,6 +546,11 @@ User=wildshard-cook
|
|
|
490
546
|
Group=wildshard-cook
|
|
491
547
|
WorkingDirectory=$COOK_SRC
|
|
492
548
|
EnvironmentFile=$COOK_ENV
|
|
549
|
+
EnvironmentFile=$COOK_STATE
|
|
550
|
+
# AUTO-RELEASE AR3: explicit engine ref/build read after signed state and credentials, so they win. Optional.
|
|
551
|
+
EnvironmentFile=-$COOK_SETTINGS
|
|
552
|
+
# The catalogue is public configuration, not cook.env state.
|
|
553
|
+
Environment=WILDSHARD_API_URL=https://api.wildshard.io
|
|
493
554
|
# MS2.4b: the checkout is root's and the worker runs git in it as wildshard-cook, which git refuses ("dubious ownership")
|
|
494
555
|
# unless the path is a safe.directory. Set here, not in a gitconfig the worker's home would have to hold.
|
|
495
556
|
Environment=GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=safe.directory GIT_CONFIG_VALUE_0=$COOK_SRC
|
|
@@ -522,8 +583,41 @@ WantedBy=multi-user.target
|
|
|
522
583
|
EOF
|
|
523
584
|
then COOK_UNIT_CHANGED=1; else COOK_UNIT_CHANGED=0; fi
|
|
524
585
|
|
|
586
|
+
if put "$SYSTEMD/wildshard-cook-follow.service" 644 root:root <<EOF
|
|
587
|
+
[Unit]
|
|
588
|
+
Description=Follow staging's signed release for the Wildshard cook
|
|
589
|
+
After=network-online.target
|
|
590
|
+
Wants=network-online.target
|
|
591
|
+
ConditionPathExists=$COOK_ENV
|
|
592
|
+
|
|
593
|
+
[Service]
|
|
594
|
+
Type=oneshot
|
|
595
|
+
User=root
|
|
596
|
+
ExecStart=/usr/bin/bash $COOK_LIB/rebuild.sh --cook
|
|
597
|
+
EOF
|
|
598
|
+
then COOK_FOLLOW_UNIT_CHANGED=1; else COOK_FOLLOW_UNIT_CHANGED=0; fi
|
|
599
|
+
if put "$SYSTEMD/wildshard-cook-follow.timer" 644 root:root <<'EOF'
|
|
600
|
+
[Unit]
|
|
601
|
+
Description=Check staging's signed release for the Wildshard cook every five minutes
|
|
602
|
+
|
|
603
|
+
[Timer]
|
|
604
|
+
OnBootSec=2min
|
|
605
|
+
OnUnitActiveSec=5min
|
|
606
|
+
Persistent=true
|
|
607
|
+
|
|
608
|
+
[Install]
|
|
609
|
+
WantedBy=timers.target
|
|
610
|
+
EOF
|
|
611
|
+
then COOK_TIMER_CHANGED=1; else COOK_TIMER_CHANGED=0; fi
|
|
612
|
+
|
|
525
613
|
if [ "$CHECK" = 0 ]; then
|
|
614
|
+
install -d -m 755 -o root -g root "$COOK_LIB"
|
|
615
|
+
if [ "$HERE" != "$COOK_LIB" ]; then
|
|
616
|
+
install -m 750 -o root -g root "$HERE/rebuild.sh" "$COOK_LIB/rebuild.sh"
|
|
617
|
+
install -m 750 -o root -g root "$HERE/cook-follow.mjs" "$COOK_LIB/cook-follow.mjs"
|
|
618
|
+
fi
|
|
526
619
|
systemctl daemon-reload
|
|
620
|
+
systemctl enable --quiet wildshard-cook-follow.timer
|
|
527
621
|
if [ "$COOK_READY" = 1 ]; then
|
|
528
622
|
if systemctl is-active --quiet wildshard-cook.service && [ "$COOK_UNIT_CHANGED" = 0 ] && [ "$COOK_SOURCE_CHANGED" = 0 ] \
|
|
529
623
|
&& [ "$(cat "$COOK_SRC/.wildshard-env" 2>/dev/null)" = "$(cook_env_hash)" ]; then say ok 'cook worker running'
|
|
@@ -546,4 +640,4 @@ if [ "$PHASE2" = 1 ] && [ "$CHECK" = 0 ]; then
|
|
|
546
640
|
fi
|
|
547
641
|
if [ "${#WAITING[@]}" != 0 ]; then say waiting "${#WAITING[@]} input(s) above; everything else is done"; exit 2; fi
|
|
548
642
|
if [ "$CHECK" = 1 ]; then say check 'Read-only pass complete'; exit 0; fi
|
|
549
|
-
say
|
|
643
|
+
if [ "$COOK_ONLY" = 1 ]; then say done 'Cook follow complete'; else say done 'Rebuild complete: Phase 1, Phase 2 and the cook worker'; fi
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/node
|
|
2
2
|
// MMO-SERVER-PLAN MS3.5 (J266): the agents' way to rerun harden.sh or setup.sh as root, from a signed, landed release only.
|
|
3
3
|
// wildshard-apply <tag> harden|setup|rebuild
|
|
4
|
+
// wildshard-apply <tag> verify AUTO-RELEASE AR2 (J355): print `commit <sha>` for a signed tag GitHub agrees on; runs nothing
|
|
4
5
|
// <tag> is a release tag a signed channel file names: `vX.Y.Z` (production) or `server-staging-<sha>` (staging). The file is
|
|
5
6
|
// checked exactly as pull.mjs checks it (Ed25519 over `body`, the release public key embedded below and in setup.sh), and its
|
|
6
7
|
// `bundle.name` must sit under that tag. Its `engineBuild` commit is fetched from GitHub by hash, the tag must point at the
|
|
@@ -89,7 +90,7 @@ async function main() {
|
|
|
89
90
|
{ stdio: 'inherit', env: { PATH: '/usr/sbin:/usr/bin:/sbin:/bin', HOME: '/root', LANG: 'C.UTF-8', WILDSHARD_APPLY_LOCKED: '1' } });
|
|
90
91
|
process.exit(locked.status ?? 1);
|
|
91
92
|
}
|
|
92
|
-
if (tag === undefined || which === undefined || rest.length > 0 || !(which
|
|
93
|
+
if (tag === undefined || which === undefined || rest.length > 0 || !(Object.hasOwn(SCRIPTS, which) || which === 'verify')) stop('usage: wildshard-apply <tag> harden|setup|rebuild|verify');
|
|
93
94
|
if (!TAG.test(tag)) stop(`${tag} is not a release tag (vX.Y.Z or server-staging-<sha>)`);
|
|
94
95
|
const key = test !== undefined ? process.env.WILDSHARD_APPLY_TEST_KEY ?? '' : RELEASE_PUBLIC_KEY;
|
|
95
96
|
const commits = new Set((await signedFiles()).map(text => signedCommit(text, tag, key)).filter(commit => commit !== null));
|
|
@@ -97,12 +98,15 @@ async function main() {
|
|
|
97
98
|
if (commits.size > 1) stop(`signed releases name ${tag} with different commits`);
|
|
98
99
|
const [commit] = commits;
|
|
99
100
|
say('ok', `${tag} is signed: engine ${commit}`);
|
|
101
|
+
if (test !== undefined && which === 'verify') { say('commit', commit); return; }
|
|
100
102
|
if (test !== undefined) { say('would', `fetch ${commit} and run scripts/vps/${SCRIPTS[/** @type {'harden' | 'setup' | 'rebuild'} */ (which)]}`); return; }
|
|
101
103
|
|
|
102
104
|
// The tag on GitHub must point at the signed commit (a peeled annotated tag, or a lightweight one).
|
|
103
105
|
const refs = git(['ls-remote', ENGINE_GIT, `refs/tags/${tag}`, `refs/tags/${tag}^{}`]).trim().split('\n').filter(Boolean).map(row => row.split('\t'));
|
|
104
106
|
const pointed = (refs.find(([, ref]) => ref === `refs/tags/${tag}^{}`) ?? refs.find(([, ref]) => ref === `refs/tags/${tag}`))?.[0];
|
|
105
107
|
if (pointed !== commit) stop(`GitHub's ${tag} points at ${pointed ?? 'nothing'}, not the signed ${commit}`);
|
|
108
|
+
// verify: wildshard-config's cook verb reads this line and moves the cook to exactly this commit (AUTO-RELEASE AR4).
|
|
109
|
+
if (which === 'verify') { say('commit', commit); return; }
|
|
106
110
|
|
|
107
111
|
// A fresh root-only folder for this commit: fetched by hash, unpacked from git's own objects, never a working copy.
|
|
108
112
|
mkdirSync(WORK, { recursive: true, mode: 0o700 });
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
# write the settings, restart the channel once, roll back if
|
|
6
6
|
# it does not come up healthy
|
|
7
7
|
# wildshard-config split <channel> setup.sh's: move the settings out of <channel>.env, once
|
|
8
|
+
# wildshard-config cook <tag> AUTO-RELEASE AR4 (J355): move the cook worker to vX.Y.Z and
|
|
9
|
+
# the build a signed release names for it; roll back on failure
|
|
10
|
+
# wildshard-config show cook print the cook worker's tag and build
|
|
8
11
|
# Settings live in /etc/wildshard/<channel>.settings (640 root:wildshard-<channel>), which the units read after <channel>.env.
|
|
9
12
|
# Secrets stay in the root-only .env, and this never prints one or writes one (it reads only the placement rows there, for
|
|
10
13
|
# the pair check below): only the keys in SETTINGS below, each
|
|
@@ -42,7 +45,6 @@ SETTINGS = {
|
|
|
42
45
|
'RECORD_TAG': lambda value, channel: re.fullmatch(r'[A-Za-z0-9._-]{0,64}', value) is not None,
|
|
43
46
|
'ALLOWED_ORIGINS': lambda value, channel: (set(value.split(',')) <= set(GAME_HOSTS) and len(set(value.split(','))) == len(value.split(','))
|
|
44
47
|
and GAME_HOSTS[CHANNELS[channel]['host']] in value.split(',')),
|
|
45
|
-
'WORLD_CROSSING': lambda value, channel: value in ('off', 'worker'),
|
|
46
48
|
'PLACEMENT_URL': lambda value, channel: value in ('', placements(channel)),
|
|
47
49
|
'PLACEMENT_PUBLIC_KEY': lambda value, channel: value in ('', PLACEMENT_PUBLIC_KEY),
|
|
48
50
|
# SC2: the channel's own port, which the box's Prometheus scrapes, or blank (off). The server binds it on 127.0.0.1 only.
|
|
@@ -53,7 +55,6 @@ RULES = {'WORLD_CELLS': "'grid' or comma-separated cell names (a-z, 0-9, -), non
|
|
|
53
55
|
'WORLD_SEATS': 'a whole number from 1 to 2000', 'RECORD_TAG': 'up to 64 of A-Z a-z 0-9 . _ -',
|
|
54
56
|
'ALLOWED_ORIGINS': "comma-separated, none twice, from https://play.wildshard.io, https://staging.wildshard.io and "
|
|
55
57
|
"https://preview.wildshard.io, keeping the channel's own (production play, staging staging)",
|
|
56
|
-
'WORLD_CROSSING': 'off or worker',
|
|
57
58
|
'PLACEMENT_URL': "https://packs.wildshard.io/releases/<channel>-placements.json for this channel, or blank",
|
|
58
59
|
'PLACEMENT_PUBLIC_KEY': f'the API placement key {PLACEMENT_PUBLIC_KEY}, or blank',
|
|
59
60
|
'METRICS_PORT': "the channel's own metrics port (production 9790, staging 9791), or blank (off)"}
|
|
@@ -167,11 +168,124 @@ def restart(channel):
|
|
|
167
168
|
return healthy(channel)
|
|
168
169
|
|
|
169
170
|
|
|
171
|
+
# AUTO-RELEASE AR4 (J355): the cook worker's two non-secret keys. They go to /etc/wildshard/cook.settings (640
|
|
172
|
+
# root:wildshard-cook), which its unit and rebuild.sh read after the root-only cook.env (the notify token and R2 writer keys,
|
|
173
|
+
# never read here), so they win. The build is never the caller's: wildshard-apply's verify reads it from a signed channel
|
|
174
|
+
# release that names the tag, after checking GitHub's tag points at it. rebuild.sh --cook then moves the checkout, installs,
|
|
175
|
+
# restarts the worker and waits for its /health.
|
|
176
|
+
COOK_KEYS = ('COOK_ENGINE_REF', 'WILDSHARD_BUILD')
|
|
177
|
+
COOK_TAG = r'v[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,4}'
|
|
178
|
+
COOK_HEADER = ['# AUTO-RELEASE AR4 (J355): the cook worker\'s engine tag and build, read after cook.env. Change them with',
|
|
179
|
+
'# `sudo wildshard-config cook <tag>`; the secrets stay in cook.env.']
|
|
180
|
+
CLEAN = {'PATH': '/usr/sbin:/usr/bin:/sbin:/bin', 'HOME': '/root', 'LANG': 'C.UTF-8'}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def helper(name):
|
|
184
|
+
"""A root-owned helper, or the test's stand-in (never as root)."""
|
|
185
|
+
if TEST:
|
|
186
|
+
return os.environ.get(f'WILDSHARD_CONFIG_TEST_{name.upper()}', '/nonexistent')
|
|
187
|
+
return {'apply': '/usr/local/sbin/wildshard-apply', 'rebuild': '/opt/wildshard-vps/rebuild.sh'}[name]
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def helper_env():
|
|
191
|
+
if not TEST:
|
|
192
|
+
return dict(CLEAN)
|
|
193
|
+
return {**CLEAN, 'PATH': os.environ.get('PATH', CLEAN['PATH']),
|
|
194
|
+
**{key: value for key, value in os.environ.items() if key.startswith(('WILDSHARD_APPLY_TEST', 'WILDSHARD_CONFIG_TEST'))}}
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def cook_rebuild():
|
|
198
|
+
"""rebuild.sh's cook step alone, as root, from the root-owned copy. It exits non-zero unless the worker answers /health.
|
|
199
|
+
It runs in its own session with SIGPIPE and SIGHUP ignored (restore_signals=False keeps them so), so a dropped ssh
|
|
200
|
+
caller can't kill it halfway through a checkout or an install."""
|
|
201
|
+
return subprocess.run(['bash' if TEST else '/usr/bin/bash', helper('rebuild'), '--cook'], cwd='/', env=helper_env(),
|
|
202
|
+
restore_signals=False, start_new_session=True).returncode == 0
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def say(line, error=False):
|
|
206
|
+
"""Print, but never let a caller that went away stop a move or its rollback."""
|
|
207
|
+
try:
|
|
208
|
+
print(line, file=sys.stderr if error else sys.stdout, flush=True)
|
|
209
|
+
except OSError:
|
|
210
|
+
pass
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def show_cook():
|
|
214
|
+
rows = [row for row in read_rows(f'{ETC}/cook.settings') if key_of(row) in COOK_KEYS]
|
|
215
|
+
for row in rows:
|
|
216
|
+
print(row)
|
|
217
|
+
if not rows:
|
|
218
|
+
print('note no cook.settings: the cook worker runs what cook.env names')
|
|
219
|
+
return 0
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def cook(args):
|
|
223
|
+
if len(args) != 2 or re.fullmatch(COOK_TAG, args[1]) is None:
|
|
224
|
+
stop('usage: wildshard-config cook vX.Y.Z')
|
|
225
|
+
tag, rebuild = args[1], helper('rebuild')
|
|
226
|
+
try:
|
|
227
|
+
with open(rebuild, encoding='utf-8') as handle:
|
|
228
|
+
knows = '[ "$1" = --cook ]' in handle.read()
|
|
229
|
+
except OSError:
|
|
230
|
+
knows = False
|
|
231
|
+
if not knows:
|
|
232
|
+
stop(f'{rebuild} has no --cook yet: apply a signed tag that carries it first (wildshard-apply <tag> harden)')
|
|
233
|
+
checked = subprocess.run([helper('apply'), tag, 'verify'], cwd='/', env=helper_env(), capture_output=True, text=True)
|
|
234
|
+
found = re.search(r'^commit\s+([0-9a-f]{40})$', checked.stdout, re.M)
|
|
235
|
+
if checked.returncode != 0 or found is None:
|
|
236
|
+
reason = ((checked.stderr or checked.stdout).strip().splitlines() or ['no commit'])[-1]
|
|
237
|
+
stop(f'{tag} is not a tag a signed release names: {reason}')
|
|
238
|
+
commit = found.group(1)
|
|
239
|
+
# One move at a time, held through the rebuild and any rollback, as `set` holds its channel.
|
|
240
|
+
import fcntl
|
|
241
|
+
lock = os.fdopen(os.open(f'{ETC}/.cook.settings.lock', os.O_WRONLY | os.O_CREAT | os.O_NOFOLLOW | os.O_CLOEXEC, 0o600), 'w')
|
|
242
|
+
fcntl.flock(lock, fcntl.LOCK_EX)
|
|
243
|
+
# From here on a dropped caller changes nothing: no hangup, no broken pipe, and any failure rolls back.
|
|
244
|
+
import signal
|
|
245
|
+
signal.signal(signal.SIGHUP, signal.SIG_IGN)
|
|
246
|
+
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
|
|
247
|
+
path = f'{ETC}/cook.settings'
|
|
248
|
+
before = read_rows(path)
|
|
249
|
+
rows = [row for row in (list(before) or list(COOK_HEADER)) if key_of(row) not in COOK_KEYS]
|
|
250
|
+
rows += [f'COOK_ENGINE_REF={tag}', f'WILDSHARD_BUILD={commit}']
|
|
251
|
+
try:
|
|
252
|
+
if rows == before:
|
|
253
|
+
say(f'ok cook.settings already names {tag}')
|
|
254
|
+
else:
|
|
255
|
+
write_rows(path, rows, 'cook')
|
|
256
|
+
say(f'doing cook {tag} at {commit}')
|
|
257
|
+
if cook_rebuild():
|
|
258
|
+
say(f'ok the cook worker runs {tag} ({commit[:8]})')
|
|
259
|
+
return 0
|
|
260
|
+
except BaseException:
|
|
261
|
+
pass
|
|
262
|
+
if rows == before:
|
|
263
|
+
say(f'stop the cook worker is not healthy on {tag}: look at journalctl -u wildshard-cook', error=True)
|
|
264
|
+
return 2
|
|
265
|
+
# It did not come back: the old tag goes back and is rebuilt, so a bad move never leaves the cook down.
|
|
266
|
+
if before:
|
|
267
|
+
write_rows(path, before, 'cook')
|
|
268
|
+
elif os.path.exists(path):
|
|
269
|
+
os.unlink(path)
|
|
270
|
+
say(f'undo the cook worker did not come up on {tag}; the old tag is back', error=True)
|
|
271
|
+
if not cook_rebuild():
|
|
272
|
+
say('stop the cook worker is not healthy on its old tag either: look at journalctl -u wildshard-cook', error=True)
|
|
273
|
+
return 2
|
|
274
|
+
return 1
|
|
275
|
+
|
|
276
|
+
|
|
170
277
|
def main(argv):
|
|
171
278
|
production = '--production' in argv
|
|
172
279
|
args = [arg for arg in argv if arg != '--production']
|
|
280
|
+
if args and args[0] == 'cook':
|
|
281
|
+
return cook(args)
|
|
282
|
+
if args[:2] == ['show', 'cook'] and len(args) == 2:
|
|
283
|
+
return show_cook()
|
|
284
|
+
if args[:2] == ['set', 'cook']:
|
|
285
|
+
stop('the cook worker moves with: wildshard-config cook vX.Y.Z')
|
|
173
286
|
if not args or args[0] not in ('show', 'set', 'split'):
|
|
174
|
-
stop('usage: wildshard-config show <channel> | set <channel> <KEY> <value> [<KEY> <value>]... [--production] | split <channel>'
|
|
287
|
+
stop('usage: wildshard-config show <channel> | set <channel> <KEY> <value> [<KEY> <value>]... [--production] | split <channel> '
|
|
288
|
+
'| cook vX.Y.Z | show cook')
|
|
175
289
|
verb = args[0]
|
|
176
290
|
if len(args) < 2 or args[1] not in CHANNELS:
|
|
177
291
|
stop('the channel is production or staging')
|
package/src/client/app/entry.ts
CHANGED
|
@@ -437,7 +437,7 @@ async function startSelected(): Promise<void> {
|
|
|
437
437
|
const imports = prepareBootImports(bootAwait('app:common-service-imports', Promise.all([speciesModule, iconsModule, pickupsModule, pickupRowsModule, propsModule,
|
|
438
438
|
starterModule, hoverboardModule, voicesModule, boarModule, familiesModule, sourceModule, runtimeModule,
|
|
439
439
|
gridEntryModule, pathsModule, prefetchModule])));
|
|
440
|
-
const [{ sharedWeaponVoices, declaredWeaponVoices }, { BOAR_LOOK }, { declaredKitItemFamilies },
|
|
440
|
+
const [{ sharedWeaponVoices, declaredWeaponVoices }, { BOAR_LOOK }, { declaredKitItemFamilies, declaredItemIcon },
|
|
441
441
|
{ configuredShardfile, installShardfileProduct, installManifestShardfile, preparePageResidency }, { browserShardfileOptions },
|
|
442
442
|
{ pageGridRecovery }, { loadingPath }, { gridPrefetchStatus }] = await Promise.all([
|
|
443
443
|
voicesModule, boarModule, familiesModule, sourceModule, runtimeModule, gridEntryModule, pathsModule,
|
|
@@ -475,12 +475,11 @@ async function startSelected(): Promise<void> {
|
|
|
475
475
|
if (path === 'grid') modules('grid');
|
|
476
476
|
// Hybrid shardfile entries retain real TypeScript stages until their page is data-only.
|
|
477
477
|
loading.setPath(loadingPath(path, game.shard.boot?.steps, path === 'shardfile' && source === null && game.shard.shardfile === undefined));
|
|
478
|
-
const declaredIcons = ['lock', 'check', 'poi', 'you', 'map', 'pack', 'star', 'book', 'heart', 'pin', 'laurel', 'sword', 'glyph', 'coin', 'purse', 'crossbow', 'rifle', 'lever', 'longbow', 'grapple', 'horse'] as const;
|
|
479
478
|
const bindings: Parameters<typeof installShardfileProduct>[2] = {
|
|
480
479
|
imageOwner,
|
|
481
480
|
instance: page.instance ?? (source === null ? 'template-solo' : `standalone-${source.identity.slug}`), catalogue: [], items: declaredKitItemFamilies(), voices: declaredWeaponVoices,
|
|
482
481
|
...(page.residency === undefined ? {} : { residency: page.residency }),
|
|
483
|
-
icon:
|
|
482
|
+
icon: declaredItemIcon,
|
|
484
483
|
recipes: new Map([['kit.look.boar', (row, species) => { if (row.animation.recipe !== 'kit.pose.quadruped') throw new Error('Unknown boar pose recipe'); return { ...BOAR_LOOK, id: row.id, species: species.id, kind: species.kind }; }]]),
|
|
485
484
|
};
|
|
486
485
|
imports.check();
|