From 6c5d0c62d00e58907f2c754976f801448f287a13 Mon Sep 17 00:00:00 2001 From: bsodfather Date: Tue, 1 Sep 2026 01:38:15 +0300 Subject: [PATCH] fix(deploy): back up artifacts after failed rollout --- scripts/deploy-community.sh | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/scripts/deploy-community.sh b/scripts/deploy-community.sh index a9129cd..3bf31ac 100755 --- a/scripts/deploy-community.sh +++ b/scripts/deploy-community.sh @@ -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" \ + storage_root="$(env_value_from "$backup_env_file" CRANK_STORAGE_ROOT /var/lib/crank/storage)" + 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