55 lines
1.4 KiB
Bash
55 lines
1.4 KiB
Bash
#!/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
|
|
|
|
# Do not reuse an old frontend layer: media files must always come from the
|
|
# currently uploaded source package.
|
|
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"
|
|
}
|
|
|
|
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
|
|
sync_static_files
|
|
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
|