shuziren/deploy.sh

54 lines
1.4 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
2026-10-27 15:25:29 +08:00
# Force a fresh image so replaced media files cannot be hidden by build cache.
2026-10-20 17:21:57 +08:00
docker compose build --no-cache shuziren
docker compose up -d --force-recreate --remove-orphans shuziren
sync_static_files() {
if [ -z "${STATIC_DIRECTORY:-}" ]; then
return
fi
mkdir -p "$STATIC_DIRECTORY"
docker cp "shuziren:/app/dist/." "$STATIC_DIRECTORY/"
echo "Static frontend synchronized to: $STATIC_DIRECTORY"
}
2026-10-20 16:32:45 +08:00
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
2026-10-20 17:21:57 +08:00
sync_static_files
2026-10-20 16:32:45 +08:00
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