auto start container in deploy.sh

This commit is contained in:
guest
2026-05-11 17:51:17 +08:00
parent f52787deae
commit 734a20bbf0

View File

@@ -2,9 +2,9 @@
# Deploy/start the API. Choose runner with the first argument.
#
# Usage:
# ./deploy.sh # auto: conda if active, otherwise uv
# ./deploy.sh conda # host API via conda
# ./deploy.sh uv # host API via uv
# ./deploy.sh # db + minio containers, then host API (auto runner)
# ./deploy.sh conda # db + minio containers, then host API via conda
# ./deploy.sh uv # db + minio containers, then host API via uv
# ./deploy.sh docker # Docker stack: api + db + minio
# ./deploy.sh --help
@@ -17,14 +17,52 @@ usage() {
Deploy/start the API. Choose runner with the first argument.
Usage:
./deploy.sh # auto: conda if active, otherwise uv
./deploy.sh conda # host API via conda
./deploy.sh uv # host API via uv
./deploy.sh # db + minio containers, then host API (auto runner)
./deploy.sh conda # db + minio containers, then host API via conda
./deploy.sh uv # db + minio containers, then host API via uv
./deploy.sh docker # Docker stack: api + db + minio
./deploy.sh --help
EOF
}
ensure_host_dependency_containers() {
if [[ "${START_DEPENDENCY_CONTAINERS:-1}" == "0" ]]; then
echo "START_DEPENDENCY_CONTAINERS=0: not starting db/minio containers"
return
fi
local compose_file="${COMPOSE_FILE:-docker-compose.yml}"
echo "Starting dependency containers: db + minio (${compose_file})..."
docker compose -f "$ROOT/${compose_file}" up -d db minio
local db_container
db_container="$(docker compose -f "$ROOT/${compose_file}" ps -q db)"
if [[ -z "$db_container" ]]; then
echo "Failed to find db container after docker compose up." >&2
exit 1
fi
echo "Waiting for PostgreSQL container to become healthy..."
local status
for _ in {1..60}; do
status="$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$db_container")"
if [[ "$status" == "healthy" || "$status" == "running" ]]; then
echo "PostgreSQL container is ${status}."
return
fi
sleep 1
done
echo "PostgreSQL container did not become ready in time." >&2
docker compose -f "$ROOT/${compose_file}" ps db >&2
exit 1
}
start_host_api() {
ensure_host_dependency_containers
exec "$@"
}
runner="${1:-auto}"
case "$runner" in
-h|--help|help)
@@ -33,11 +71,12 @@ case "$runner" in
;;
auto)
shift || true
exec "$ROOT/start_api.sh" "$@"
start_host_api "$ROOT/start_api.sh" "$@"
;;
conda|uv|system|python)
shift || true
API_RUNNER="$runner" exec "$ROOT/start_api.sh" "$@"
export API_RUNNER="$runner"
start_host_api "$ROOT/start_api.sh" "$@"
;;
docker)
shift || true