Repository navigation
Expand file tree
/
Copy pathdeploy.sh
More file actions
65 lines (55 loc) · 1.7 KB
/
Copy pathdeploy.sh
File metadata and controls
65 lines (55 loc) · 1.7 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
#!/bin/bash
# DevTrack Production Deployment Script
# Usage: ./deploy.sh [--no-build]
#
# Deploys the stack defined in docker-compose.prod.yml (api, frontend, workers,
# redis, mongo). Settings come from .env.production in the repo root.
set -e
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
COMPOSE_FILE="docker-compose.prod.yml"
ENV_FILE=".env.production"
COMPOSE=(docker compose -f "$COMPOSE_FILE")
echo -e "${GREEN}==> DevTrack Deployment${NC}"
# Parse args
SKIP_BUILD=false
if [[ "$1" == "--no-build" ]]; then
SKIP_BUILD=true
fi
# Check for the production env file
if [ ! -f "$ENV_FILE" ]; then
echo -e "${YELLOW}WARNING: $ENV_FILE not found.${NC}"
echo "Create $ENV_FILE in the repo root (see DEPLOYMENT.md for the variables) and run again."
exit 1
fi
COMPOSE+=(--env-file "$ENV_FILE")
# Build containers
if [ "$SKIP_BUILD" = false ]; then
echo -e "\n${GREEN}==> Building containers...${NC}"
"${COMPOSE[@]}" build --parallel
fi
# Start services
echo -e "\n${GREEN}==> Starting services...${NC}"
"${COMPOSE[@]}" up -d
# Wait for the api service to answer its health endpoint
echo -e "\n${GREEN}==> Checking health...${NC}"
API_HEALTHY=false
for i in {1..30}; do
if "${COMPOSE[@]}" exec -T api node -e "fetch('http://127.0.0.1:3001/health').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))" > /dev/null 2>&1; then
API_HEALTHY=true
break
fi
echo "Waiting for api... ($i/30)"
sleep 2
done
if [ "$API_HEALTHY" = true ]; then
echo -e "\n${GREEN}==> Deployment successful!${NC}"
echo -e "\nServices:"
"${COMPOSE[@]}" ps
else
echo -e "\n${YELLOW}API health check failed. Check logs:${NC}"
"${COMPOSE[@]}" logs api
exit 1
fi