Run the complete PROMPT stack and CI verification in Docker
PROMPT Docker CI and deployment / verify-and-deploy (push) Successful in 14m10s

This commit is contained in:
2026-10-23 00:19:08 +08:00
parent 8b650fdf78
commit 818b1894e7
13 changed files with 296 additions and 268 deletions
+8 -30
View File
@@ -1,34 +1,12 @@
#!/usr/bin/env bash
set -Eeuo pipefail
NODE_SOURCE="${1:?Node executable is required}"
if ! command -v docker >/dev/null || ! docker compose version >/dev/null 2>&1; then
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y docker.io docker-compose-v2
systemctl enable --now docker
fi
if ! command -v ffmpeg >/dev/null; then
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y ffmpeg
fi
umask 027
IMAGE="${1:?Application image is required}"
# Preserve existing credentials and Docker project/volume names during migration.
if [ ! -f /etc/prompt.env ]; then
"$NODE_SOURCE" <<'NODE' > /etc/prompt.env
const {randomBytes}=require('crypto');
const password=randomBytes(32).toString('hex');
console.log(`POSTGRES_PASSWORD=${password}\nPG_PORT=18132\nS3_PORT=18133\nDATABASE_URL=postgresql://prompt:${password}@127.0.0.1:18132/prompt\nS3_ENDPOINT=http://127.0.0.1:18133\nS3_ACCESS_KEY=${randomBytes(16).toString('hex')}\nS3_SECRET_KEY=${randomBytes(32).toString('hex')}\nS3_BUCKET=prompt\nFFMPEG_PATH=/usr/bin/ffmpeg\nFFPROBE_PATH=/usr/bin/ffprobe`);
NODE
umask 077
TEMP_ENV=$(mktemp /etc/prompt.env.XXXXXX)
trap 'rm -f "$TEMP_ENV"' EXIT
docker run --rm --entrypoint node "$IMAGE" -e "const {randomBytes}=require('crypto');const hex=()=>randomBytes(32).toString('hex');console.log('POSTGRES_PASSWORD='+hex()+'\nS3_ACCESS_KEY='+hex()+'\nS3_SECRET_KEY='+hex()+'\nS3_BUCKET=prompt')" > "$TEMP_ENV"
mv "$TEMP_ENV" /etc/prompt.env
trap - EXIT
fi
chown root:prompt /etc/prompt.env
chmod 0640 /etc/prompt.env
install -d -m 0755 /opt/prompt/infra
install -m 0644 compose.yml /opt/prompt/infra/compose.yml
docker compose -p prompt --env-file /etc/prompt.env -f /opt/prompt/infra/compose.yml up -d
for attempt in $(seq 1 60); do
if docker compose -p prompt --env-file /etc/prompt.env -f /opt/prompt/infra/compose.yml exec -T postgres pg_isready -U prompt -d prompt >/dev/null 2>&1; then break; fi
if [ "$attempt" -eq 60 ]; then echo 'PostgreSQL startup timed out'; exit 1; fi
sleep 2
done
# Additive migrations follow this backup. Keep the most recent 10 database dumps.
install -d -o root -g root -m 0700 /var/lib/prompt/backups
docker compose -p prompt --env-file /etc/prompt.env -f /opt/prompt/infra/compose.yml exec -T postgres pg_dump -U prompt -d prompt -Fc > "/var/lib/prompt/backups/$(date -u +%Y%m%dT%H%M%S)-${2:-deploy}.dump"
find /var/lib/prompt/backups -name '*.dump' -printf '%T@ %p\n' | sort -rn | tail -n +11 | cut -d' ' -f2- | xargs -r rm --