BrowserUse_and_ComputerUse_.../scripts/deploy_vps.sh

65 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
set -Eeuo pipefail
DEPLOY_BRANCH="${DEPLOY_BRANCH:-feature/api-for-subagent}"
HEALTH_URL="${HEALTH_URL:-http://127.0.0.1:8088/health}"
COMPOSE_FILES="${COMPOSE_FILES:-docker-compose.yml:docker-compose.vps.yml}"
log() {
printf '[deploy] %s\n' "$*"
}
fail() {
printf '[deploy] fatal: %s\n' "$*" >&2
exit 1
}
command -v git >/dev/null 2>&1 || fail "git is not installed"
command -v docker >/dev/null 2>&1 || fail "docker is not installed"
command -v curl >/dev/null 2>&1 || fail "curl is not installed"
docker compose version >/dev/null 2>&1 || fail "docker compose plugin is not available"
[ -d .git ] || fail "current directory is not a git checkout"
[ -f docker-compose.yml ] || fail "docker-compose.yml not found in current directory"
[ -f .env ] || fail ".env is missing; create it on the VPS with OPENAI_API_KEY and related runtime settings"
compose_args=()
IFS=':' read -r -a compose_files <<< "$COMPOSE_FILES"
for compose_file in "${compose_files[@]}"; do
if [ -f "$compose_file" ]; then
compose_args+=("-f" "$compose_file")
else
fail "compose file not found: ${compose_file}"
fi
done
log "fetching origin/${DEPLOY_BRANCH}"
git fetch --prune origin "+refs/heads/${DEPLOY_BRANCH}:refs/remotes/origin/${DEPLOY_BRANCH}"
log "checking out ${DEPLOY_BRANCH}"
git checkout -B "$DEPLOY_BRANCH" "origin/$DEPLOY_BRANCH"
git reset --hard "origin/$DEPLOY_BRANCH"
log "building Docker Compose services"
docker compose "${compose_args[@]}" build
log "starting Docker Compose stack"
docker compose "${compose_args[@]}" up -d --remove-orphans
log "current service state"
docker compose "${compose_args[@]}" ps
log "waiting for API health at ${HEALTH_URL}"
for attempt in {1..30}; do
if curl -fsS "$HEALTH_URL" >/dev/null; then
log "API is healthy"
exit 0
fi
log "health check failed, retry ${attempt}/30"
sleep 2
done
log "API did not become healthy; browser-api logs follow"
docker compose "${compose_args[@]}" logs --tail=120 browser-api || true
fail "health check failed: ${HEALTH_URL}"