-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
Β·142 lines (118 loc) Β· 3.96 KB
/
deploy.sh
File metadata and controls
executable file
Β·142 lines (118 loc) Β· 3.96 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
set -e
echo "π Starting deployment..."
sudo chmod 666 /var/run/docker.sock || true
# Create Docker network if it doesn't exist
if ! docker network ls | grep -q gamers-network; then
echo "π Creating Docker network..."
docker network create gamers-network
echo "β
Network created"
else
echo "β
Network already exists"
fi
# Prepare certbot directories
echo "π Preparing certbot directories..."
mkdir -p nginx/ssl/certbot nginx/certbot/webroot nginx/static logs
echo "β
Directories ready"
# Write Riot Games verification file from secret
if [ -n "$RIOT_VERIFICATION_CODE" ]; then
echo "$RIOT_VERIFICATION_CODE" > nginx/static/riot.txt
echo "β
riot.txt created"
fi
# Prepare grafana provisioning
echo "π Preparing grafana provisioning..."
mkdir -p grafana/provisioning/datasources grafana/provisioning/dashboards grafana/dashboards
echo "β
Grafana provisioning directories ready"
# Prepare prometheus config
echo "π Preparing prometheus config..."
sudo mkdir -p prometheus rabbitmq
sudo chown -R "$(whoami)" prometheus rabbitmq
# Remove if mistakenly created as a directory by Docker (root-owned)
if [ -d prometheus/prometheus.yml ]; then
rm -rf prometheus/prometheus.yml
fi
if [ ! -f prometheus/prometheus.yml ]; then
cat > prometheus/prometheus.yml << 'EOF'
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "gamers-api"
static_configs:
- targets: ["web-app:8080"]
metrics_path: /metrics
- job_name: "mysql"
static_configs:
- targets: ["gamers-mysql-exporter:9104"]
- job_name: "redis"
static_configs:
- targets: ["gamers-redis-exporter:9121"]
- job_name: "rabbitmq"
static_configs:
- targets: ["gamers-rabbitmq:15692"]
metrics_path: /metrics
EOF
echo "β
prometheus.yml created"
else
echo "β
prometheus.yml already exists"
fi
# Prepare rabbitmq config
echo "π Preparing rabbitmq config..."
# Remove if mistakenly created as a directory by Docker (root-owned)
if [ -d rabbitmq/enabled_plugins ]; then
rm -rf rabbitmq/enabled_plugins
fi
if [ ! -f rabbitmq/enabled_plugins ]; then
echo "[rabbitmq_management,rabbitmq_prometheus]." > rabbitmq/enabled_plugins
echo "β
enabled_plugins created"
else
echo "β
enabled_plugins already exists"
fi
# Stop and remove old containers
if [ "${RESET_VOLUMES}" = "true" ]; then
echo "ποΈ RESET_VOLUMES=true: Removing containers and volumes..."
docker-compose down -v --remove-orphans || true
else
echo "π Stopping old containers..."
docker-compose down || true
fi
# Pull latest images
echo "π₯ Pulling latest images..."
docker-compose pull
# Read DOMAIN from .env
DOMAIN=$(grep -E '^DOMAIN=' .env | cut -d'=' -f2 | tr -d '"' | tr -d "'")
if [ -z "$DOMAIN" ]; then
echo "β DOMAINμ΄ .envμ μ€μ λμ§ μμμ΅λλ€."
exit 1
fi
# Issue certificate if not exists, otherwise start full stack directly
if [ ! -d "./nginx/ssl/certbot/live/$DOMAIN" ]; then
echo "π SSL μΈμ¦μκ° μμ΅λλ€. Let's Encrypt λ°κΈμ μμν©λλ€..."
chmod +x init-letsencrypt.sh
./init-letsencrypt.sh
else
echo "β
SSL μΈμ¦μκ° μ΄λ―Έ μ‘΄μ¬ν©λλ€."
# Start infra services first
echo "π Starting infrastructure services..."
docker-compose up -d mysql redis rabbitmq
# Run migrator in foreground so logs are visible
echo "π Running migrator (foreground)..."
if ! docker-compose up --no-deps gamers-migrator; then
echo "β Migration failed! Logs:"
docker-compose logs gamers-migrator
exit 1
fi
# Start remaining services
echo "π Starting application services..."
docker-compose up -d
fi
# Wait for services to be healthy
echo "β³ Waiting for services to be healthy..."
sleep 10
# Check container status
echo "π Container status:"
docker-compose ps
echo "β
Deployment completed successfully!"