-
Notifications
You must be signed in to change notification settings - Fork 283
64 lines (56 loc) · 2.51 KB
/
test-docker-compose.yml
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
name: Test Docker Compose
on: [ push, pull_request ]
jobs:
test:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/[email protected]
- name: Validate
run: docker compose -f docker-compose.standalone.yml config -q
- name: Check Service Health
# language=sh
run: |
sed -i 's|pull_policy: always|pull_policy: never|g' docker-compose.standalone.yml
echo "Docker compose file to run with:"
cat docker-compose.standalone.yml
docker build -t "ghcr.io/turms-im/turms-admin:latest" -f turms-admin/Dockerfile .
docker build -t "ghcr.io/turms-im/turms-gateway:latest" -f turms-gateway/Dockerfile .
docker build -t "ghcr.io/turms-im/turms-service:latest" -f turms-service/Dockerfile .
export COMPOSE_PROFILES="conference,elasticsearch,storage"
export ENV=prod
docker compose -f docker-compose.standalone.yml up -d
sleep 10
RETRY=0
INSTANCE_IDS=$(docker compose -f docker-compose.standalone.yml ps -q)
DISPLAY_NAMES=$(echo "$INSTANCE_IDS" | xargs -I {} docker inspect --format="{{.Name}} ({{.ID}})" {})
echo "Services for checking health: $DISPLAY_NAMES"
while true
do
ALL_HEALTHY=true
for INSTANCE_ID in $INSTANCE_IDS; do
HEALTH_STATUS=$(docker inspect --format="{{if .Config.Healthcheck}}{{print .State.Health.Status}}{{end}}" "$INSTANCE_ID")
DISPLAY_NAME=$(docker inspect --format="{{.Name}} ({{.ID}})" "$INSTANCE_ID")
if [ -z "$HEALTH_STATUS" ]; then
echo "Service $DISPLAY_NAME does not have a health check configured, passing through"
elif [ "$HEALTH_STATUS" = "healthy" ]; then
echo "Service $DISPLAY_NAME is healthy"
else
LOGS=$(docker inspect --format="{{json .State.Health}}" $INSTANCE_ID | jq)
echo "Service $DISPLAY_NAME is not healthy: $LOGS"
ALL_HEALTHY=false
break
fi
done
if [ $ALL_HEALTHY = true ]; then
echo "All services are healthy"
break
fi
if [ $RETRY -eq 5 ]; then
echo "Failed to start services, some services are not healthy"
exit 1
fi
echo "Some services are not healthy. Retry times: $RETRY. Retrying..."
sleep 10
((RETRY++))
done