-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
59 lines (48 loc) · 1.7 KB
/
update.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
#!/bin/bash
# Exit in case of error
set -e
echo "Load .env file"
# Load local .env
if [ -f .env ]; then
# Load Environment Variables
export $(cat .env | grep -v '#' | awk '/=/ {print $1}')
fi
docker stack rm deploy-party
sleep 10
docker pull ghcr.io/lennetech/deploy.party/app:latest
docker pull ghcr.io/lennetech/deploy.party/api:latest
docker stack deploy -c docker-compose.yml deploy-party
echo "--------------------------------------------------------------------------------"
echo "Waiting for deploy.party to start..."
sleep 10
TIMEOUT=180
START_TIME=$(date +%s)
BAR_LENGTH=50
while true; do
CONTAINER_ID=$(docker ps --filter "ancestor=ghcr.io/lennetech/deploy.party/app:latest" --format "{{.ID}}")
STATUS=$(docker inspect --format='{{.State.Health.Status}}' "$CONTAINER_ID" 2>/dev/null)
if [ "$STATUS" = "healthy" ]; then
PROGRESS=100
FILLED=$((PROGRESS * BAR_LENGTH / 100))
EMPTY=$((BAR_LENGTH - FILLED))
BAR=$(printf "%0.s#" $(seq 1 $FILLED))
SPACES=$(printf "%0.s " $(seq 1 $EMPTY))
printf "\r[%s%s] %d%%" "$BAR" "$SPACES" "$PROGRESS"
sleep 10
echo "\nSuccessfully updated deploy.party!"
exit 0
fi
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
echo "\nThe container did not reach the 'healthy' status within the timeout period."
exit 1
fi
PROGRESS=$((ELAPSED_TIME * 100 / TIMEOUT))
FILLED=$((PROGRESS * BAR_LENGTH / 100))
EMPTY=$((BAR_LENGTH - FILLED))
BAR=$(printf "%0.s#" $(seq 1 $FILLED))
SPACES=$(printf "%0.s " $(seq 1 $EMPTY))
printf "\r[%s%s] %d%%" "$BAR" "$SPACES" "$PROGRESS"
sleep 2
done