-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·42 lines (32 loc) · 1.06 KB
/
deploy.sh
File metadata and controls
executable file
·42 lines (32 loc) · 1.06 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
#!/bin/bash
# Auto-deploy script for Klimadashboard API
# Pulls latest code from GitHub and rebuilds if changed.
#
# Usage:
# ./deploy.sh # Run once
# crontab: */5 * * * * # Run every 5 minutes via cron
#
# Setup (run once on server):
# cd /opt/klimadashboard-api
# git clone https://github.com/klimadashboard/api.git .
# cp .env.example .env # edit with your values
# chmod +x deploy.sh
# docker compose up -d --build
set -e
DEPLOY_DIR="/opt/klimadashboard-api"
LOG_FILE="/var/log/klimadashboard-api-deploy.log"
cd "$DEPLOY_DIR"
# Fetch latest changes
git fetch origin main --quiet
# Check if there are new commits
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse origin/main)
if [ "$LOCAL" = "$REMOTE" ]; then
# No changes — exit silently (don't spam the log)
exit 0
fi
# New commits found — pull and rebuild
echo "[$(date -Iseconds)] Deploying $LOCAL → $REMOTE" >> "$LOG_FILE"
git pull origin main --quiet
docker compose up -d --build --quiet-pull >> "$LOG_FILE" 2>&1
echo "[$(date -Iseconds)] Deploy complete" >> "$LOG_FILE"