mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
34 lines
1.2 KiB
Bash
Executable File
34 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
CONTAINER_NAME="${CONTAINER_NAME:-sprint-postgres}"
|
|
POSTGRES_IMAGE="${POSTGRES_IMAGE:-postgres:16-alpine}"
|
|
POSTGRES_USER="${POSTGRES_USER:-eussi}"
|
|
POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-password}"
|
|
POSTGRES_DB="${POSTGRES_DB:-issue}"
|
|
POSTGRES_PORT="${POSTGRES_PORT:-5432}"
|
|
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
echo "docker is required but not installed."
|
|
exit 1
|
|
fi
|
|
|
|
if docker ps -a --filter "name=^/${CONTAINER_NAME}$" --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
|
docker update --restart unless-stopped "${CONTAINER_NAME}" >/dev/null
|
|
docker start "${CONTAINER_NAME}" >/dev/null || true
|
|
echo "container '${CONTAINER_NAME}' already exists and is running (or starting)."
|
|
else
|
|
docker run -d \
|
|
--name "${CONTAINER_NAME}" \
|
|
--restart unless-stopped \
|
|
-e "POSTGRES_USER=${POSTGRES_USER}" \
|
|
-e "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}" \
|
|
-e "POSTGRES_DB=${POSTGRES_DB}" \
|
|
-p "${POSTGRES_PORT}:5432" \
|
|
"${POSTGRES_IMAGE}" >/dev/null
|
|
echo "container '${CONTAINER_NAME}' created and started."
|
|
fi
|
|
|
|
echo "connection string: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:${POSTGRES_PORT}/${POSTGRES_DB}"
|