41 lines
1.6 KiB
Bash
Executable File
41 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
env_file="${1:-compose/.env}"
|
|
compose_file="${ADMIN_COMPOSE_FILE:-compose/docker-compose.admin.yml}"
|
|
infra_compose_file="${COMPOSE_FILE:-compose/docker-compose.infra.yml}"
|
|
|
|
if [[ ! -r "$env_file" ]]; then
|
|
printf 'Environment file not found: %s\n' "$env_file" >&2
|
|
exit 1
|
|
fi
|
|
env_value() {
|
|
awk -F= -v key="$1" '$1 == key {sub(/^[^=]*=/, ""); print; exit}' "$env_file"
|
|
}
|
|
|
|
project_name="$(env_value ADMIN_COMPOSE_PROJECT_NAME)"
|
|
backend_image="$(env_value ADMIN_BACKEND_IMAGE)"
|
|
frontend_image="$(env_value ADMIN_FRONTEND_IMAGE)"
|
|
if [[ -z "$(env_value ADMIN_INITIAL_PASSWORD)" ]]; then
|
|
infra_compose=(docker compose --env-file "$env_file" -f "$infra_compose_file")
|
|
super_admin_count="$("${infra_compose[@]}" exec -T postgres psql \
|
|
--username "$(env_value POSTGRES_USER)" --dbname "$(env_value ADMIN_POSTGRES_DB)" \
|
|
--tuples-only --no-align \
|
|
--command "SELECT count(*) FROM poly_admin_users WHERE role_type = 'SUPER_ADMIN'" 2>/dev/null || true)"
|
|
if [[ "$super_admin_count" != "1" ]]; then
|
|
printf 'Initial admin password is unset and no SUPER_ADMIN exists; run scripts/set-admin-credentials.sh first.\n' >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
for image in "$backend_image" "$frontend_image"; do
|
|
if [[ -z "$image" ]] || ! docker image inspect "$image" >/dev/null 2>&1; then
|
|
printf 'Configured admin image is unavailable: %s\n' "$image" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
compose_command=(docker compose --project-name "$project_name" --env-file "$env_file" -f "$compose_file")
|
|
"${compose_command[@]}" config --quiet
|
|
"${compose_command[@]}" up -d
|
|
"${compose_command[@]}" ps --all
|