-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdeploy.sh
More file actions
66 lines (53 loc) · 1.95 KB
/
deploy.sh
File metadata and controls
66 lines (53 loc) · 1.95 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
#!/usr/bin/env bash
set -euo pipefail
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"; }
# Expected env vars (set by deploy.yml when using default script):
# REPO_URL - Git URL to clone (e.g. https://github.com/owner/repo.git)
# BRANCH - Branch to deploy (e.g. main)
# Optional:
# DEPLOY_DIR - Directory to clone into (default: /opt/boost-data-collector)
#
# Note: .env must be placed manually on the server at $DEPLOY_DIR/.env before deploying.
DEPLOY_DIR="${DEPLOY_DIR:-/opt/boost-data-collector}"
if [[ -z "${REPO_URL:-}" || -z "${BRANCH:-}" ]]; then
log "ERROR: REPO_URL and BRANCH must be set."
exit 1
fi
command -v git >/dev/null 2>&1 || { log "ERROR: git is not installed."; exit 1; }
command -v make >/dev/null 2>&1 || { log "ERROR: make is not installed."; exit 1; }
if [[ -d "$DEPLOY_DIR/.git" ]]; then
log "Pulling latest in $DEPLOY_DIR..."
git -C "$DEPLOY_DIR" fetch origin
git -C "$DEPLOY_DIR" checkout "$BRANCH"
git -C "$DEPLOY_DIR" reset --hard "origin/$BRANCH"
else
log "Cloning $REPO_URL (branch: $BRANCH) into $DEPLOY_DIR..."
mkdir -p "$(dirname "$DEPLOY_DIR")"
git clone --branch "$BRANCH" "$REPO_URL" "$DEPLOY_DIR"
fi
if [[ ! -f "$DEPLOY_DIR/.env" ]]; then
log "ERROR: .env not found. Place .env manually in $DEPLOY_DIR before deploying."
exit 1
fi
cd "$DEPLOY_DIR"
log "Stopping existing containers..."
make down || true
log "Building and starting stack..."
make build
make up
log "Waiting for stack to be healthy..."
max_attempts=12
attempt=0
until make health >/dev/null 2>&1; do
attempt=$((attempt + 1))
if [[ $attempt -ge $max_attempts ]]; then
log "ERROR: Health check failed after ${max_attempts} attempts. Aborting."
exit 1
fi
log " Health check attempt ${attempt}/${max_attempts} failed, retrying in 5 s..."
sleep 5
done
log "Stack is healthy."
log "Sending startup notification..."
DEPLOY_BRANCH="$BRANCH" make notify || log "WARNING: Startup notification failed (non-fatal)."
log "Deploy completed."