-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·84 lines (73 loc) · 2.61 KB
/
setup.sh
File metadata and controls
executable file
·84 lines (73 loc) · 2.61 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
# NEST — zero-config deploy. Run: ./setup.sh
# Auto-generates all secrets on first run; preserves them on re-runs.
# Pulls latest images, starts the stack, waits for health.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
ENV_FILE=".env"
COMPOSE="docker compose"
# ---------------------------------------------------------------------------
# 1. Auto-generate .env if missing (or preserve existing)
# ---------------------------------------------------------------------------
generate_secret() { openssl rand -hex 32; }
if [[ ! -f "$ENV_FILE" ]]; then
PG_PASS="$(generate_secret)"
CLI_TOKEN="$(generate_secret)"
ENC_KEY="$(openssl rand -base64 32 | tr -d '\n\r')"
cat > "$ENV_FILE" <<EOF
# Auto-generated by setup.sh — do NOT delete (secrets are non-recoverable)
POSTGRES_PASSWORD=$PG_PASS
CLI_API_TOKEN=$CLI_TOKEN
ENCRYPTION_KEY=$ENC_KEY
POSTGRES_USER=postgres
POSTGRES_DB=nest
WEB_PORT=80
EOF
echo "Generated $ENV_FILE with new secrets."
else
echo "Using existing $ENV_FILE (re-run is safe)."
fi
# ---------------------------------------------------------------------------
# 2. Pull latest images
# ---------------------------------------------------------------------------
echo "Pulling latest images..."
$COMPOSE pull --quiet
# ---------------------------------------------------------------------------
# 3. Start stack
# ---------------------------------------------------------------------------
echo "Starting stack..."
$COMPOSE up -d --remove-orphans
# ---------------------------------------------------------------------------
# 4. Wait for health
# ---------------------------------------------------------------------------
echo "Waiting for services to be ready..."
WEB_PORT=$(grep '^WEB_PORT=' "$ENV_FILE" 2>/dev/null | cut -d= -f2 || echo "80")
WEB_PORT="${WEB_PORT:-80}"
HEALTH_URL="http://localhost:${WEB_PORT}/health"
ok=false
for i in $(seq 1 30); do
status=$(curl -s -o /dev/null -w "%{http_code}" "$HEALTH_URL" 2>/dev/null || echo "000")
if [[ "$status" == "200" ]]; then
ok=true
break
fi
sleep 2
done
if $ok; then
echo ""
echo "=== NEST ready ==="
echo " Web: http://localhost:${WEB_PORT}"
echo ""
echo " 1. Open the web app and register your account."
echo " 2. Go to Profile → generate an API token."
echo " 3. CLI: nest auth login http://localhost:${WEB_PORT} <your-token>"
echo ""
echo " Logs: $COMPOSE logs -f"
echo " Stop: $COMPOSE down"
else
echo ""
echo "Services did not become healthy in 60s."
echo " Check: $COMPOSE logs -f"
exit 1
fi