You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.0 KiB
89 lines
2.0 KiB
#!/usr/bin/env bash |
|
# Production Docker Compose helper — run ./scripts/deploy_prod.sh --help |
|
|
|
set -euo pipefail |
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
|
cd "$ROOT" |
|
|
|
COMPOSE="${COMPOSE:-docker compose}" |
|
COMPOSE_FILE="${COMPOSE_FILE:-compose.prod.yml}" |
|
ENV_FILE="${ENV_FILE:-.env.prod}" |
|
|
|
APP_IMAGES=(setup relay migrator) |
|
|
|
usage() { |
|
cat <<'EOF' |
|
Production Docker Compose helper (compose.prod.yml). |
|
|
|
./scripts/deploy_prod.sh build build app images (setup, relay, migrator) |
|
./scripts/deploy_prod.sh push push those images (run docker login first) |
|
./scripts/deploy_prod.sh build-push build then push |
|
./scripts/deploy_prod.sh pull pull images |
|
./scripts/deploy_prod.sh up start stack (detached) |
|
./scripts/deploy_prod.sh deploy pull then up -d (typical on server) |
|
./scripts/deploy_prod.sh down stop stack |
|
./scripts/deploy_prod.sh ps docker compose ps |
|
./scripts/deploy_prod.sh logs [svc] follow logs (default: all services) |
|
|
|
Env: ENV_FILE (default .env.prod), COMPOSE_FILE, TAG, COMPOSE (default "docker compose") |
|
EOF |
|
exit "${1:-0}" |
|
} |
|
|
|
require_env_file() { |
|
if [[ ! -f "$ENV_FILE" ]]; then |
|
echo "error: missing env file: $ENV_FILE" >&2 |
|
echo " cp .env.prod.example .env.prod && edit, or set ENV_FILE=..." >&2 |
|
exit 1 |
|
fi |
|
} |
|
|
|
compose() { |
|
require_env_file |
|
$COMPOSE --env-file "$ENV_FILE" -f "$COMPOSE_FILE" "$@" |
|
} |
|
|
|
cmd="${1:-}" |
|
[[ -z "$cmd" ]] && usage 1 |
|
[[ "$cmd" == "-h" || "$cmd" == "--help" ]] && usage 0 |
|
shift || true |
|
|
|
case "$cmd" in |
|
help) |
|
usage 0 |
|
;; |
|
build) |
|
compose build "${APP_IMAGES[@]}" |
|
;; |
|
push) |
|
compose push "${APP_IMAGES[@]}" |
|
;; |
|
build-push) |
|
compose build "${APP_IMAGES[@]}" |
|
compose push "${APP_IMAGES[@]}" |
|
;; |
|
pull) |
|
compose pull |
|
;; |
|
up) |
|
compose up -d |
|
;; |
|
deploy) |
|
compose pull |
|
compose up -d |
|
;; |
|
down) |
|
compose down |
|
;; |
|
ps) |
|
compose ps "$@" |
|
;; |
|
logs) |
|
compose logs -f "$@" |
|
;; |
|
*) |
|
echo "error: unknown command: $cmd" >&2 |
|
usage 1 |
|
;; |
|
esac
|
|
|