Files
probably-rendering-one-more…/scripts/deploy-studio.sh
T
codex-bot a2330b22e2
python CI and deployment / verify-and-deploy (push) Successful in 7m23s
studio CI and deployment / verify-and-deploy (push) Failing after 5m28s
wiki CI and deployment / verify-and-deploy (push) Failing after 6m13s
Restructure into Wiki, Studio and Python monorepo with scoped CI
2026-10-25 21:13:43 +08:00

22 lines
1.0 KiB
Bash

#!/usr/bin/env bash
set -Eeuo pipefail
if [ "$(id -u)" -ne 0 ]; then exec sudo -n bash "$0" "$@"; fi
sha=${1:?release SHA required}
[[ "$sha" =~ ^[0-9a-f]{40}$ ]]
exec 9>/var/lock/prompt-studio.lock
flock -w 300 9
latest=$(git -c safe.directory="$PWD" ls-remote origin refs/heads/main | cut -f1)
[ "$latest" = "$sha" ] || exit 0
mkdir -p /opt/prompt-studio
previous=$(cat /opt/prompt-studio/image 2>/dev/null || true)
write_compose(){ printf 'services:\n studio:\n image: %s\n restart: unless-stopped\n ports: ["18134:3000"]\n' "$1" > /opt/prompt-studio/compose.yml; }
write_compose "prompt-studio:$sha"
rollback(){ if [ -n "$previous" ]; then write_compose "$previous"; docker compose -p prompt-studio -f /opt/prompt-studio/compose.yml up -d; fi; }
trap rollback ERR
docker compose -p prompt-studio -f /opt/prompt-studio/compose.yml up -d
for attempt in {1..40}; do
if curl -fsS http://127.0.0.1:18134/api/index >/dev/null; then printf '%s' "prompt-studio:$sha" > /opt/prompt-studio/image; exit 0; fi
sleep 2
done
false