-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·69 lines (53 loc) · 2.01 KB
/
deploy.sh
File metadata and controls
executable file
·69 lines (53 loc) · 2.01 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
#!/bin/bash
# LeCommit Deployment Script
# This script builds, pushes, and deploys updates to your Vultr VPS
set -e # Exit on any error
# Configuration
VPS_IP="199.247.14.12"
REGISTRY_URL="lhr.vultrcr.com/lecommit1"
IMAGE_NAME="lecommit"
CONTAINER_NAME="lecommit-app"
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${GREEN}🚀 Starting LeCommit deployment...${NC}"
# Step 1: Build the Docker image for AMD64
echo -e "${YELLOW}📦 Building Docker image for linux/amd64...${NC}"
docker buildx build --platform linux/amd64 -t ${REGISTRY_URL}/${IMAGE_NAME}:latest .
# Step 2: Push to Vultr Container Registry
echo -e "${YELLOW}⬆️ Pushing image to Vultr Container Registry...${NC}"
docker push ${REGISTRY_URL}/${IMAGE_NAME}:latest
# Step 3: Deploy to VPS
echo -e "${YELLOW}🔄 Deploying to VPS...${NC}"
# SSH into VPS and run deployment commands
ssh root@${VPS_IP} << 'ENDSSH'
set -e
echo "🔽 Pulling latest image..."
docker pull lhr.vultrcr.com/lecommit1/lecommit:latest
echo "🛑 Stopping old container..."
docker stop lecommit-app || true
docker rm lecommit-app || true
echo "🚀 Starting new container..."
docker run -d \
--name lecommit-app \
--restart unless-stopped \
-p 80:3000 \
--env-file /opt/lecommit/.env.prod \
lhr.vultrcr.com/lecommit1/lecommit:latest
echo "🧹 Cleaning up old images..."
docker image prune -f
echo "✅ Deployment complete! Checking status..."
docker ps | grep lecommit-app
ENDSSH
echo -e "${GREEN}✨ Deployment completed successfully!${NC}"
echo -e "${GREEN}🌐 Your app is live at: http://${VPS_IP}${NC}"
# Optional: Check if the app is responding
echo -e "${YELLOW}🔍 Checking app status...${NC}"
if curl -s -o /dev/null -w "%{http_code}" http://${VPS_IP} | grep -q "200"; then
echo -e "${GREEN}✅ App is responding correctly!${NC}"
else
echo -e "${RED}⚠️ Warning: App might not be responding correctly. Check logs with:${NC}"
echo -e "${RED} ssh root@${VPS_IP} 'docker logs lecommit-app'${NC}"
fi