shuziren/deploy.sh

41 lines
1.0 KiB
Bash
Raw Normal View History

2026-10-20 16:32:45 +08:00
#!/usr/bin/env sh
set -eu
project_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
cd "$project_dir"
mkdir -p "$project_dir/logs"
chmod 777 "$project_dir/logs"
if ! command -v docker >/dev/null 2>&1; then
echo "Docker is required but was not found." >&2
exit 1
fi
if ! docker compose version >/dev/null 2>&1; then
echo "Docker Compose v2 is required but was not found." >&2
exit 1
fi
docker compose up -d --build --remove-orphans
attempt=0
while [ "$attempt" -lt 20 ]; do
status=$(docker inspect --format='{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' shuziren 2>/dev/null || true)
if [ "$status" = "healthy" ]; then
echo "Published successfully: http://SERVER_IP:9000"
docker compose ps
exit 0
fi
if [ "$status" = "exited" ] || [ "$status" = "dead" ]; then
docker compose logs --tail=100
exit 1
fi
attempt=$((attempt + 1))
sleep 3
done
echo "Container started, but health check did not become ready in time." >&2
docker compose ps
docker compose logs --tail=100
exit 1