-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·86 lines (68 loc) · 2.18 KB
/
deploy.sh
File metadata and controls
executable file
·86 lines (68 loc) · 2.18 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
85
86
#!/bin/bash
# JobSync Deployment Script
# Usage: ./deploy.sh [branch-name]
# Example: ./deploy.sh main
# Example: ./deploy.sh develop
set -e # Exit on error
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Default branch
DEFAULT_BRANCH="main"
BRANCH="${1:-$DEFAULT_BRANCH}"
echo -e "${YELLOW}========================================${NC}"
echo -e "${YELLOW}JobSync Deployment Script${NC}"
echo -e "${YELLOW}========================================${NC}"
echo ""
# Get script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
echo -e "${GREEN}[1/5]${NC} Current directory: $SCRIPT_DIR"
echo ""
# Detect Docker Compose (standalone v2 or plugin)
if command -v docker-compose >/dev/null 2>&1; then
COMPOSE_CMD="docker-compose"
elif docker compose version >/dev/null 2>&1; then
COMPOSE_CMD="docker compose"
else
echo -e "${RED}Error: Docker Compose not found${NC}"
exit 1
fi
echo -e "Using: ${YELLOW}$COMPOSE_CMD${NC}"
echo ""
# Check if git repository
if [ ! -d ".git" ]; then
echo -e "${RED}Error: Not a git repository${NC}"
exit 1
fi
# Fetch latest changes
echo -e "${GREEN}[2/5]${NC} Fetching latest changes from GitHub..."
git fetch origin
# Checkout and pull the specified branch
echo -e "${GREEN}[3/5]${NC} Checking out branch: ${YELLOW}$BRANCH${NC}"
git checkout "$BRANCH"
git pull origin "$BRANCH"
# Stop existing containers
echo -e "${GREEN}[4/5]${NC} Stopping existing containers..."
$COMPOSE_CMD down
# Pull latest images and start containers
echo -e "${GREEN}[5/5]${NC} Pulling latest images and starting containers..."
$COMPOSE_CMD pull
$COMPOSE_CMD up -d --force-recreate
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Deployment completed successfully!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "Branch: ${YELLOW}$BRANCH${NC}"
echo -e "Checking container status..."
echo ""
# Show running containers
$COMPOSE_CMD ps
echo ""
echo -e "${GREEN}Deployment logs (last 20 lines):${NC}"
$COMPOSE_CMD logs --tail=20
echo ""
echo -e "${YELLOW}Tip:${NC} View live logs with: ${YELLOW}$COMPOSE_CMD logs -f${NC}"