mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-04 20:41:51 +08:00
refactor(deploy,update): drop standalone edition and add sandbox upgrade confirmation
- Remove standalone Docker edition (Dockerfile.standalone, docker-compose.standalone.yml, release.yml standalone jobs, and dual-edition env/script branches). - Remove deploy_edition field from /api/update/check and dual-edition UI/i18n branching in UpdateCard. - Replace window.confirm on upgrade with AlertDialog informing users of the irreversible Standalone -> Sandbox security upgrade.
This commit is contained in:
1 parent
8efd26b8b7
commit
f5b446e3bf
15 files changed
+330
-944
No files matched your search
+68
-89
@@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# Automated regression tests for dual-edition deployment (standalone / sandbox),
|
||||
# migration from legacy v0.3.32, snapshot creation, manual rollback, DB restore,
|
||||
# Automated regression tests for Docker deployment, upgrade from legacy .env,
|
||||
# snapshot creation, manual rollback, DB restore, post-rollback upstream unpinning,
|
||||
# and automatic rollback on failed health check.
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||
trap 'chmod -R u+w "$TMP_DIR" 2>/dev/null || true; rm -rf "$TMP_DIR"' EXIT
|
||||
|
||||
pass() { printf 'PASS: %s\n' "$*"; }
|
||||
fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
|
||||
@@ -31,18 +31,10 @@ pass "shell syntax checks"
|
||||
cd "$TMP_DIR"
|
||||
# shellcheck source=scripts/deploy-lib.sh
|
||||
. "$REPO_ROOT/scripts/deploy-lib.sh"
|
||||
|
||||
assert_eq "$(normalize_standalone_tag "")" "standalone" "empty standalone tag"
|
||||
assert_eq "$(normalize_standalone_tag "latest")" "standalone" "latest -> standalone"
|
||||
assert_eq "$(normalize_standalone_tag "standalone")" "standalone" "standalone -> standalone"
|
||||
assert_eq "$(normalize_standalone_tag "v0.3.32")" "v0.3.32" "legacy pre-split tag preserved"
|
||||
assert_eq "$(normalize_standalone_tag "v0.3.17")" "v0.3.17" "older pre-split tag preserved"
|
||||
assert_eq "$(normalize_standalone_tag "v0.3.33")" "v0.3.33-standalone" "new tag mapped to -standalone"
|
||||
assert_eq "$(normalize_standalone_tag "v0.4.0")" "v0.4.0-standalone" "minor bump mapped to -standalone"
|
||||
assert_eq "$(normalize_standalone_tag "v0.3.33-standalone")" "v0.3.33-standalone" "already suffixed preserved"
|
||||
assert_eq "$(normalize_sandbox_tag "standalone")" "latest" "sandbox standalone -> latest"
|
||||
assert_eq "$(normalize_sandbox_tag "v0.3.33-standalone")" "v0.3.33" "sandbox strips -standalone"
|
||||
assert_eq "$(normalize_sandbox_tag "v0.3.33")" "v0.3.33" "sandbox keeps semver"
|
||||
assert_eq "$(normalize_tag "")" "latest" "empty tag -> latest"
|
||||
assert_eq "$(normalize_tag "standalone")" "latest" "legacy standalone -> latest"
|
||||
assert_eq "$(normalize_tag "v0.3.33-standalone")" "v0.3.33" "strips legacy -standalone suffix"
|
||||
assert_eq "$(normalize_tag "v0.3.33")" "v0.3.33" "keeps semver tag"
|
||||
|
||||
env_set FOO "/a/b|c&d" "$TMP_DIR/t.env"
|
||||
assert_eq "$(env_get FOO "$TMP_DIR/t.env")" "/a/b|c&d" "env_set/get preserves special chars"
|
||||
@@ -58,16 +50,19 @@ BIN_STUB="$TMP_DIR/bin"
|
||||
STATE_STUB="$TMP_DIR/stub-state"
|
||||
mkdir -p "$WORK/scripts" "$BIN_STUB" "$STATE_STUB/images"
|
||||
cp "$REPO_ROOT/install.sh" "$REPO_ROOT/update.sh" "$REPO_ROOT/.env.example" \
|
||||
"$REPO_ROOT/docker-compose.yml" "$REPO_ROOT/docker-compose.standalone.yml" "$WORK/"
|
||||
"$REPO_ROOT/docker-compose.yml" "$WORK/"
|
||||
cp "$REPO_ROOT/scripts/deploy-lib.sh" "$REPO_ROOT/scripts/artex-sandbox-firewall.sh" "$WORK/scripts/"
|
||||
chmod +x "$WORK/install.sh" "$WORK/update.sh" "$WORK/scripts/deploy-lib.sh" "$WORK/scripts/artex-sandbox-firewall.sh"
|
||||
|
||||
# Seed mock docker image store (v0.3.32 standalone image)
|
||||
printf 'sha256:old0332standalone\n' > "$STATE_STUB/images/sha256_old0332standalone"
|
||||
printf 'sha256:old0332standalone\n' > "$STATE_STUB/images/ruoji6_artex_v0.3.32"
|
||||
printf 'standalone\n' > "$STATE_STUB/running_edition"
|
||||
# Seed mock docker image store (existing installation before upgrade)
|
||||
printf 'sha256:old0332artex\n' > "$STATE_STUB/images/sha256_old0332artex"
|
||||
printf 'sha256:old0332artex\n' > "$STATE_STUB/images/ruoji6_artex_v0.3.32"
|
||||
printf 'sha256:old0332gw\n' > "$STATE_STUB/images/sha256_old0332gw"
|
||||
printf 'sha256:old0332gw\n' > "$STATE_STUB/images/ruoji6_artex-gateway_latest"
|
||||
printf 'sha256:old0332sbx\n' > "$STATE_STUB/images/sha256_old0332sbx"
|
||||
printf 'sha256:old0332sbx\n' > "$STATE_STUB/images/ruoji6_artex-sandbox_latest"
|
||||
printf 'ruoji6/artex:v0.3.32\n' > "$STATE_STUB/artex_image_ref"
|
||||
printf 'sha256:old0332standalone\n' > "$STATE_STUB/artex_image_id"
|
||||
printf 'sha256:old0332artex\n' > "$STATE_STUB/artex_image_id"
|
||||
printf 'ok\n' > "$STATE_STUB/health_mode"
|
||||
|
||||
cat > "$BIN_STUB/docker" <<'STUB'
|
||||
@@ -88,14 +83,12 @@ case "${1:-}" in
|
||||
case "$sub" in
|
||||
version) echo "Docker Compose version v2.29.0"; exit 0 ;;
|
||||
ps)
|
||||
# ps -a -q <svc>
|
||||
svc="${!#}"
|
||||
ed="$(cat "$STATE/running_edition")"
|
||||
case "$svc" in
|
||||
artex) echo "cid-artex" ;;
|
||||
postgres) echo "cid-pg" ;;
|
||||
artex-gateway) [ "$ed" = "sandbox" ] && echo "cid-gw" || true ;;
|
||||
docker-socket-proxy) [ "$ed" = "sandbox" ] && echo "cid-dsp" || true ;;
|
||||
artex-gateway) echo "cid-gw" ;;
|
||||
docker-socket-proxy) echo "cid-dsp" ;;
|
||||
esac
|
||||
exit 0 ;;
|
||||
pull)
|
||||
@@ -104,20 +97,16 @@ case "${1:-}" in
|
||||
exit 0 ;;
|
||||
up)
|
||||
if [ "$cfile" = "docker-compose.yml" ]; then
|
||||
printf 'sandbox\n' > "$STATE/running_edition"
|
||||
printf 'ruoji6/artex:latest\n' > "$STATE/artex_image_ref"
|
||||
printf 'sha256:new0333sandbox\n' > "$STATE/artex_image_id"
|
||||
printf 'sha256:new0333sandbox\n' > "$STATE/images/sha256_new0333sandbox"
|
||||
printf 'sha256:new0333artex\n' > "$STATE/artex_image_id"
|
||||
printf 'sha256:new0333artex\n' > "$STATE/images/sha256_new0333artex"
|
||||
printf 'sha256:new0333gw\n' > "$STATE/images/sha256_new0333gw"
|
||||
printf 'sha256:new0333sbx\n' > "$STATE/images/ruoji6_artex-sandbox_latest"
|
||||
elif [ "$cfile" = "docker-compose.standalone.yml" ]; then
|
||||
printf 'standalone\n' > "$STATE/running_edition"
|
||||
fi
|
||||
exit 0 ;;
|
||||
esac ;;
|
||||
ps)
|
||||
ed="$(cat "$STATE/running_edition")"
|
||||
if [ "$ed" = "sandbox" ]; then echo "cid-sbx-1"; fi
|
||||
echo "cid-sbx-1"
|
||||
exit 0 ;;
|
||||
stop|pull|rmi)
|
||||
exit 0 ;;
|
||||
@@ -145,11 +134,8 @@ case "${1:-}" in
|
||||
cid-artex:*Config.Image*) cat "$STATE/artex_image_ref" ;;
|
||||
cid-artex:*.Image*) cat "$STATE/artex_image_id" ;;
|
||||
cid-artex:*State.Status*) echo "running" ;;
|
||||
cid-artex:*Config.Env*)
|
||||
[ "$(cat "$STATE/running_edition")" = "sandbox" ] && echo "ARTEX_SANDBOX_MODE=docker" || echo "ARTEX_SANDBOX_MODE=local"
|
||||
;;
|
||||
cid-gw:*Config.Image*) echo "ruoji6/artex-gateway:latest" ;;
|
||||
cid-gw:*.Image*) echo "sha256:new0333gw" ;;
|
||||
cid-gw:*.Image*) echo "sha256:old0332gw" ;;
|
||||
cid-pg:*State.Running*) echo "true" ;;
|
||||
esac
|
||||
exit 0 ;;
|
||||
@@ -183,7 +169,7 @@ exit 22
|
||||
STUB
|
||||
chmod +x "$BIN_STUB/curl"
|
||||
|
||||
# Create legacy v0.3.32 .env (no ARTEX_DEPLOY_EDITION, no ARTEX_HOST_DATA_DIR, no ARTEX_GATEWAY_TOKEN)
|
||||
# Create legacy .env (no ARTEX_HOST_DATA_DIR, no ARTEX_GATEWAY_TOKEN)
|
||||
cat > "$WORK/.env" <<'ENV'
|
||||
ARTEX_IMAGE=ruoji6/artex
|
||||
ARTEX_TAG=v0.3.32
|
||||
@@ -206,77 +192,70 @@ export PATH="$BIN_STUB:$PATH"
|
||||
export ARTEX_TEST_STUB_STATE="$STATE_STUB"
|
||||
export ARTEX_HEALTH_TIMEOUT=2
|
||||
|
||||
# 3a. Detect legacy v0.3.32 standalone deployment
|
||||
ed="$(cd "$WORK" && . ./scripts/deploy-lib.sh && detect_current_edition .env)"
|
||||
assert_eq "$ed" "standalone" "detect legacy v0.3.32 as standalone"
|
||||
pass "legacy standalone detection"
|
||||
|
||||
# 3b. Migrate legacy standalone -> sandbox
|
||||
# 3a. Upgrade legacy .env -> current Docker topology
|
||||
(
|
||||
cd "$WORK"
|
||||
./update.sh --migrate-sandbox --skip-git-pull --yes
|
||||
./update.sh --upgrade --tag v0.3.33 --skip-git-pull --yes
|
||||
)
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_DEPLOY_EDITION .env)" "sandbox" "edition migrated to sandbox"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_TAG .env)" "v0.3.33" "ARTEX_TAG updated"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_SANDBOX_MODE .env)" "docker" "ARTEX_SANDBOX_MODE set to docker"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_HOST_DATA_DIR .env)" "$WORK/data" "ARTEX_HOST_DATA_DIR populated"
|
||||
[ -n "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_GATEWAY_TOKEN .env)" ] || fail "ARTEX_GATEWAY_TOKEN not generated"
|
||||
[ -w "$WORK/data/tasks/5/findings/note.txt" ] || fail "migrated task file not writable"
|
||||
# Outside symlink target must still be 0400
|
||||
outside_perm="$(stat -f '%Lp' "$OUTSIDE_FILE" 2>/dev/null || stat -c '%a' "$OUTSIDE_FILE")"
|
||||
assert_eq "$outside_perm" "400" "symlink target permissions must not be modified"
|
||||
snap_mig="$(cat "$WORK/.artex-deploy/latest")"
|
||||
assert_contains "$WORK/.artex-deploy/snapshots/$snap_mig/meta.env" "SNAP_EDITION=standalone" "migration snapshot records standalone"
|
||||
assert_contains "$WORK/.artex-deploy/snapshots/$snap_mig/meta.env" "ARTEX_IMAGE_REF=ruoji6/artex:v0.3.32" "migration snapshot records v0.3.32 image"
|
||||
assert_contains "$WORK/.artex-deploy/snapshots/$snap_mig/meta.env" "HAS_PG_DUMP=1" "migration snapshot includes PG dump"
|
||||
assert_contains "$STATE_STUB/docker.log" "compose -f docker-compose.yml up -d --remove-orphans" "started sandbox compose"
|
||||
pass "legacy standalone -> sandbox migration"
|
||||
snap_upg="$(cat "$WORK/.artex-deploy/latest")"
|
||||
assert_contains "$WORK/.artex-deploy/snapshots/$snap_upg/meta.env" "ARTEX_IMAGE_REF=ruoji6/artex:v0.3.32" "upgrade snapshot records v0.3.32 image"
|
||||
assert_contains "$WORK/.artex-deploy/snapshots/$snap_upg/meta.env" "HAS_PG_DUMP=1" "upgrade snapshot includes PG dump"
|
||||
assert_contains "$STATE_STUB/docker.log" "compose -f docker-compose.yml up -d --remove-orphans" "started compose"
|
||||
pass "upgrade + legacy workspace permission migration"
|
||||
|
||||
# 3c. Rollback from sandbox back to legacy standalone (including --restore-db)
|
||||
# 3b. Manual rollback (including --restore-db)
|
||||
(
|
||||
cd "$WORK"
|
||||
./update.sh --rollback "$snap_mig" --restore-db --yes
|
||||
./update.sh --rollback "$snap_upg" --restore-db --yes
|
||||
)
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_DEPLOY_EDITION .env)" "standalone" "rolled back edition to standalone"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_STANDALONE_IMAGE .env)" "artex-rollback/artex" "rollback pinned local image repo"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_STANDALONE_TAG .env)" "$snap_mig" "rollback pinned local image tag"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_IMAGE .env)" "artex-rollback/artex" "rollback pinned local image repo"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_TAG .env)" "$snap_upg" "rollback pinned local image tag"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_GATEWAY_IMAGE .env)" "artex-rollback/gateway" "rollback pinned local gateway repo"
|
||||
assert_contains "$STATE_STUB/docker.log" "stop -t 10 cid-sbx-1" "stopped running sandbox container on rollback"
|
||||
assert_contains "$STATE_STUB/docker.log" "compose -f docker-compose.yml stop -t 15 artex-gateway" "gracefully stopped artex-gateway on rollback"
|
||||
assert_contains "$STATE_STUB/docker.log" "compose -f docker-compose.standalone.yml up -d --remove-orphans" "started standalone compose on rollback"
|
||||
assert_contains "$STATE_STUB/docker.log" "exec -i cid-pg psql" "restored PG dump when --restore-db passed"
|
||||
pass "sandbox -> standalone rollback + DB restore"
|
||||
pass "manual rollback + DB restore"
|
||||
|
||||
# 3d. Failed upgrade triggers automatic rollback
|
||||
printf 'fail-once\n' > "$STATE_STUB/health_mode"
|
||||
if ( cd "$WORK" && ./update.sh --upgrade --tag v0.3.34 --skip-git-pull --yes ); then
|
||||
fail "upgrade with failing health check should exit non-zero after auto-rollback"
|
||||
fi
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_DEPLOY_EDITION .env)" "standalone" "auto-rollback preserved standalone edition"
|
||||
pass "auto-rollback on failed upgrade health check"
|
||||
|
||||
# 3e. Switch sandbox -> standalone pinning legacy v0.3.32 tag (also verifies unpinning artex-rollback/* after rollback)
|
||||
printf 'sandbox\n' > "$STATE_STUB/running_edition"
|
||||
# 3c. Post-rollback upgrade unpins artex-rollback/* back to upstream
|
||||
printf 'ok\n' > "$STATE_STUB/health_mode"
|
||||
(
|
||||
cd "$WORK"
|
||||
./update.sh --switch-standalone --tag v0.3.32 --skip-git-pull --yes
|
||||
./update.sh --upgrade --tag v0.3.34 --skip-git-pull --yes
|
||||
)
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_STANDALONE_IMAGE .env)" "ruoji6/artex" "post-rollback switch unpinned artex-rollback/* standalone image"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_STANDALONE_TAG .env)" "v0.3.32" "switch-standalone kept v0.3.32 tag"
|
||||
pass "switch sandbox -> standalone with legacy tag and rollback unpin"
|
||||
# 3f. Fresh install for both editions
|
||||
for ed_opt in standalone sandbox; do
|
||||
FRESH="$TMP_DIR/fresh-$ed_opt"
|
||||
mkdir -p "$FRESH/scripts"
|
||||
cp "$REPO_ROOT/install.sh" "$REPO_ROOT/.env.example" \
|
||||
"$REPO_ROOT/docker-compose.yml" "$REPO_ROOT/docker-compose.standalone.yml" "$FRESH/"
|
||||
cp "$REPO_ROOT/scripts/deploy-lib.sh" "$REPO_ROOT/scripts/artex-sandbox-firewall.sh" "$FRESH/scripts/"
|
||||
chmod +x "$FRESH/install.sh" "$FRESH/scripts/deploy-lib.sh"
|
||||
( cd "$FRESH" && ./install.sh --edition "$ed_opt" --yes )
|
||||
assert_eq "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_DEPLOY_EDITION .env)" "$ed_opt" "fresh install edition=$ed_opt"
|
||||
if [ "$ed_opt" = "sandbox" ]; then
|
||||
assert_eq "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_HOST_DATA_DIR .env)" "$FRESH/data" "fresh sandbox sets ARTEX_HOST_DATA_DIR"
|
||||
[ -n "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_GATEWAY_TOKEN .env)" ] || fail "fresh sandbox sets ARTEX_GATEWAY_TOKEN"
|
||||
fi
|
||||
done
|
||||
pass "fresh dual-edition install.sh"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_IMAGE .env)" "ruoji6/artex" "post-rollback upgrade unpinned artex-rollback/* image"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_GATEWAY_IMAGE .env)" "ruoji6/artex-gateway" "post-rollback upgrade unpinned gateway image"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_TAG .env)" "v0.3.34" "post-rollback upgrade applied requested tag"
|
||||
pass "post-rollback upstream unpinning"
|
||||
|
||||
echo "ALL DEPLOY/MIGRATION/ROLLBACK TESTS PASSED"
|
||||
# 3d. Failed upgrade triggers automatic rollback
|
||||
printf 'fail-once\n' > "$STATE_STUB/health_mode"
|
||||
if ( cd "$WORK" && ./update.sh --upgrade --tag v0.3.35 --skip-git-pull --yes ); then
|
||||
fail "upgrade with failing health check should exit non-zero after auto-rollback"
|
||||
fi
|
||||
snap_auto="$(cat "$WORK/.artex-deploy/latest")"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_IMAGE .env)" "artex-rollback/artex" "auto-rollback pinned previous image"
|
||||
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_TAG .env)" "$snap_auto" "auto-rollback pinned snapshot tag"
|
||||
pass "auto-rollback on failed upgrade health check"
|
||||
|
||||
# 3e. Fresh install
|
||||
FRESH="$TMP_DIR/fresh"
|
||||
mkdir -p "$FRESH/scripts"
|
||||
cp "$REPO_ROOT/install.sh" "$REPO_ROOT/.env.example" "$REPO_ROOT/docker-compose.yml" "$FRESH/"
|
||||
cp "$REPO_ROOT/scripts/deploy-lib.sh" "$REPO_ROOT/scripts/artex-sandbox-firewall.sh" "$FRESH/scripts/"
|
||||
chmod +x "$FRESH/install.sh" "$FRESH/scripts/deploy-lib.sh"
|
||||
printf 'ok\n' > "$STATE_STUB/health_mode"
|
||||
( cd "$FRESH" && ./install.sh --docker --yes )
|
||||
assert_eq "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_SANDBOX_MODE .env)" "docker" "fresh install sets ARTEX_SANDBOX_MODE=docker"
|
||||
assert_eq "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_HOST_DATA_DIR .env)" "$FRESH/data" "fresh install sets ARTEX_HOST_DATA_DIR"
|
||||
[ -n "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_GATEWAY_TOKEN .env)" ] || fail "fresh install sets ARTEX_GATEWAY_TOKEN"
|
||||
pass "fresh install.sh"
|
||||
|
||||
echo "ALL DEPLOY/UPGRADE/ROLLBACK TESTS PASSED"
|
||||
Reference in new issue
Block a user