fix(deploy): back up artifacts after failed rollout
CI / Rust Checks (push) Successful in 12m34s
CI / UI Checks (push) Successful in 6s
CI / Community Image Smoke (push) Successful in 1m12s
CI / Frontend E2E (push) Failing after 5m42s
CI / Deploy (push) Has been skipped

This commit is contained in:
2026-09-01 01:38:15 +03:00
parent dd5dbba1f6
commit 6c5d0c62d0
+30 -3
View File
@@ -63,6 +63,34 @@ wait_for_stack() {
return 1
}
find_artifact_container() {
expected_root="$1"
expected_mount="$(printf 'volume\t%s' "$expected_root")"
for service in admin-api artifact-storage-init; do
candidates="$(compose ps -aq "$service" 2>/dev/null || true)"
# Intentional word splitting: Docker container IDs cannot contain whitespace.
# shellcheck disable=SC2086
set -- $candidates
if [ "$#" -gt 1 ]; then
echo "Artifact backup found multiple $service containers; refusing an ambiguous volume source" >&2
return 1
fi
if [ "$#" -eq 1 ]; then
candidate="$1"
oneoff="$(docker inspect --format '{{index .Config.Labels "com.docker.compose.oneoff"}}' "$candidate" 2>/dev/null || true)"
mounts="$(docker inspect --format '{{range .Mounts}}{{printf "%s\t%s\n" .Type .Destination}}{{end}}' "$candidate" 2>/dev/null || true)"
if [ "$oneoff" != "True" ] && [ "$oneoff" != "true" ] \
&& printf '%s\n' "$mounts" | grep -Fxq "$expected_mount"; then
printf '%s' "$candidate"
return 0
fi
fi
done
return 1
}
create_backup() {
timestamp="$(date -u +%Y%m%dT%H%M%SZ)"
backup_dir="$(pwd)/backups/${timestamp}"
@@ -101,10 +129,9 @@ create_backup() {
--username "$postgres_user" --dbname "$postgres_db" \
--format custom --file /backup/postgres.dump
admin_container="$(compose ps -q admin-api 2>/dev/null || true)"
if [ -n "$admin_container" ]; then
storage_root="$(env_value_from "$backup_env_file" CRANK_STORAGE_ROOT /var/lib/crank/storage)"
docker run --rm --volumes-from "$admin_container" \
if artifact_container="$(find_artifact_container "$storage_root")"; then
docker run --rm --volumes-from "$artifact_container:ro" \
-v "$backup_dir:/backup" alpine:3.21 \
tar -C "$storage_root" -czf /backup/artifacts.tar.gz .
elif [ "$previous_deployment" = true ]; then