-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdeploy-production.sh
More file actions
executable file
·77 lines (63 loc) · 2.06 KB
/
Copy pathdeploy-production.sh
File metadata and controls
executable file
·77 lines (63 loc) · 2.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
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
#!/bin/bash
#
# Deploy Lokole to Production
#
# Usage: ./deploy-production.sh
#
# This script connects to the production VM and updates the running containers
# to the latest images from Docker Hub.
#
set -e
VM_HOST="mailserver.lokole.ca"
VM_USER="opwen"
echo "🚀 Deploying Lokole to Production"
echo "=================================="
echo "Host: ${VM_USER}@${VM_HOST}"
echo ""
# Check if we can reach the VM
if ! ssh -o ConnectTimeout=5 -o BatchMode=yes ${VM_USER}@${VM_HOST} exit 2>/dev/null; then
echo "⚠️ Note: SSH key authentication not set up."
echo " You'll be prompted for password."
echo ""
fi
ssh ${VM_USER}@${VM_HOST} "bash -s" <<'REMOTE_SCRIPT'
set -e
cd ~/lokole || { echo "❌ Failed to cd to ~/lokole"; exit 1; }
echo "📥 Pulling latest code from GitHub..."
git fetch origin --prune
git reset --hard origin/master
echo "✓ Code updated"
echo ""
echo "🐳 Pulling latest Docker images..."
set -a # automatically export all variables
source secrets/azure.env
source secrets/cloudflare.env 2>/dev/null || true
source secrets/users.env 2>/dev/null || true
source secrets/sendgrid.env 2>/dev/null || true
set +a # stop auto-export
docker-compose -f docker/docker-compose.prod.yml pull
echo "✓ Images pulled"
echo ""
echo "🔄 Recreating containers..."
docker-compose -f docker/docker-compose.prod.yml up -d --force-recreate
echo "✓ Containers recreated"
echo ""
echo "⏳ Waiting for containers to stabilize..."
sleep 5
echo "📊 Container Status:"
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Image}}'
echo ""
echo "🧹 Cleaning up old images..."
docker system prune -a -f >/dev/null 2>&1 || true
echo "✓ Cleanup complete"
echo ""
echo "✅ Deployment Complete!"
REMOTE_SCRIPT
echo ""
echo "=================================="
echo "✅ Production deployment finished!"
echo ""
echo "Next steps:"
echo " - Check logs: ssh ${VM_USER}@${VM_HOST} 'docker logs docker_api_1 --tail 50'"
echo " - Check worker: ssh ${VM_USER}@${VM_HOST} 'docker logs docker_worker_1 --tail 50'"
echo " - Test API: curl https://${VM_HOST}/api/healthcheck/ping"