-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeploy-services.sh
executable file
·131 lines (111 loc) · 3.26 KB
/
deploy-services.sh
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
#!/bin/bash
# Help message
show_help() {
echo "Usage: ./deploy-services.sh [OPTIONS]"
echo
echo "Options:"
echo " -f, --env-file FILE Use specified environment file"
echo " -p, --project-name NAME Set docker compose project name"
echo " -c, --collector-profile STR Set collector profile string"
echo " -t, --image-tag TAG Set docker image tag"
echo " -h, --help Show this help message"
echo
echo "Examples:"
echo " ./deploy-services.sh --env-file .env-pre-mainnet-AAVEV3-ETH"
echo " ./deploy-services.sh --project-name snapshotter-lite-v2-123-aavev3"
}
# Initialize variables
ENV_FILE=""
PROJECT_NAME=""
COLLECTOR_PROFILE=""
IMAGE_TAG="latest"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-f|--env-file)
ENV_FILE="$2"
shift 2
;;
-p|--project-name)
PROJECT_NAME="$2"
shift 2
;;
-c|--collector-profile)
COLLECTOR_PROFILE="$2"
shift 2
;;
-t|--image-tag)
IMAGE_TAG="$2"
shift 2
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Validate required parameters
if [ -z "$ENV_FILE" ]; then
echo "Error: Environment file must be specified"
exit 1
fi
if [ ! -f "$ENV_FILE" ]; then
echo "Error: Environment file $ENV_FILE not found"
exit 1
fi
# Source the environment file
source "$ENV_FILE"
# Validate required variables
required_vars=("FULL_NAMESPACE" "SLOT_ID" "DOCKER_NETWORK_NAME")
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
echo "Error: Required variable $var is not set"
exit 1
fi
done
# Cleanup and create required directories
echo "🧹 Cleaning up existing directories..."
rm -rf "./logs-${FULL_NAMESPACE_LOWER}"
echo "📁 Creating fresh directories..."
mkdir -p "./logs-${FULL_NAMESPACE_LOWER}"
# Docker pull locking mechanism
DOCKER_PULL_LOCK="/tmp/powerloom_docker_pull.lock"
handle_docker_pull() {
while [ -f "$DOCKER_PULL_LOCK" ]; do
echo "Another Docker pull in progress, waiting..."
sleep 5
done
touch "$DOCKER_PULL_LOCK"
trap 'rm -f $DOCKER_PULL_LOCK' EXIT
# Determine docker compose command
if command -v docker-compose >/dev/null 2>&1; then
DOCKER_COMPOSE_CMD="docker-compose"
else
DOCKER_COMPOSE_CMD="docker compose"
fi
# Build compose arguments
COMPOSE_ARGS=(
--env-file "$ENV_FILE"
-p "${PROJECT_NAME:-snapshotter-lite-v2-${FULL_NAMESPACE}}"
-f docker-compose.yaml
)
# Add optional profiles
[ -n "$IPFS_URL" ] && COMPOSE_ARGS+=("--profile" "ipfs")
[ -n "$COLLECTOR_PROFILE" ] && COMPOSE_ARGS+=($COLLECTOR_PROFILE)
# Set image tag and ensure network exists
export IMAGE_TAG
export DOCKER_NETWORK_NAME
# Execute docker compose pull
$DOCKER_COMPOSE_CMD "${COMPOSE_ARGS[@]}" pull
rm -f "$DOCKER_PULL_LOCK"
}
# Main deployment
echo "🚀 Deploying with configuration from: $ENV_FILE"
handle_docker_pull
# Deploy services
$DOCKER_COMPOSE_CMD "${COMPOSE_ARGS[@]}" up -V