-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
52 lines (38 loc) · 1.57 KB
/
deploy.sh
File metadata and controls
52 lines (38 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Pulls the latest pre-built image from GHCR and restarts the server.
# Usage: bash deploy.sh
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
ENV_FILE=".env"
if [ ! -f "$ENV_FILE" ]; then
echo "ERROR: .env not found. Create it from .env.example (at repo root)."
exit 1
fi
# shellcheck disable=SC1090
source "$ENV_FILE"
if [ -z "${GHCR_USERNAME:-}" ] || [ -z "${GHCR_PAT:-}" ]; then
echo "ERROR: GHCR_USERNAME and GHCR_PAT must be set in $ENV_FILE"
exit 1
fi
if [ -z "${DATABASE_URL:-}" ] && [ -z "${DB_PASSWORD:-}" ]; then
echo "ERROR: Set DATABASE_URL or DB_PASSWORD in $ENV_FILE"
exit 1
fi
if [ -z "${DATABASE_URL:-}" ]; then
DATABASE_URL="postgresql://${DB_USER:-interlock}:${DB_PASSWORD}@postgres:5432/${DB_NAME:-interlock}"
fi
if [ -z "${JWT_SECRET:-}" ] || [ -z "${ENCRYPTION_KEY:-}" ]; then
echo "ERROR: JWT_SECRET and ENCRYPTION_KEY must be set in $ENV_FILE"
exit 1
fi
echo "==> Logging in to GitHub Container Registry..."
echo "$GHCR_PAT" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin
echo "==> Pulling latest Go backend image..."
docker compose -f docker-compose.prod.yml --env-file "$ENV_FILE" pull server-go
echo "==> Running database migrations..."
docker compose -f docker-compose.prod.yml --env-file "$ENV_FILE" run --rm -e DATABASE_URL="$DATABASE_URL" server-go migrate up
echo "==> Restarting containers..."
docker compose -f docker-compose.prod.yml --env-file "$ENV_FILE" up -d
echo "==> Deploy complete. Checking health..."
sleep 5
docker compose -f docker-compose.prod.yml --env-file "$ENV_FILE" ps