-
Notifications
You must be signed in to change notification settings - Fork 6
133 lines (117 loc) · 4.51 KB
/
container-healthchecks.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
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
name: "CI: Container Health Checks"
on:
# Allow manual triggering
workflow_dispatch:
# Allow being called by another GitHub Action
workflow_call:
pull_request:
branches: [ develop ]
env:
SLACK_EXCEPTION_WEBHOOK: "http://mock-slack:20100/slack-messages"
VRO_DEV_SECRETS_FOLDER: "${{ github.workspace }}/.cache/abd-vro-dev-secrets"
jobs:
container-healthcheck:
if: github.repository == 'department-of-veterans-affairs/abd-vro' &&
((github.event_name == 'pull_request' && startsWith(github.head_ref, 'dependabot/')) || github.event_name != 'pull_request')
runs-on: ubuntu-latest
steps:
- name: "Checkout source code"
uses: actions/checkout@v3
- name: "Checkout abd-vro-dev-secrets repo"
uses: actions/checkout@v3
with:
# Checkout using a PAT so that we can access the internal repo
token: ${{ secrets.ACCESS_TOKEN_CHECKOUT_INTERNAL_REPO }}
repository: 'department-of-veterans-affairs/abd-vro-dev-secrets'
path: "${{ env.VRO_DEV_SECRETS_FOLDER }}"
- name: "Docker build"
uses: ./.github/actions/build-images
- name: "Start containers: platform and api-gateway"
run: |
source scripts/setenv.sh
export -p | sed 's/declare -x //'
COMPOSE_PROFILES="gateway" ./gradlew :dockerComposeUp
- name: "Start containers: app and svc-*"
shell: bash
run: |
source scripts/setenv.sh
# Build and start Kafka mock required for svc-bie-kafka
./gradlew -p mocks :mock-bie-kafka:docker
COMPOSE_PROFILES="kafka" ./gradlew -p mocks :dockerComposeUp
COMPOSE_PROFILES="svc" ./gradlew :app:dockerComposeUp
- name: "Start containers: domain-cc"
shell: bash
run: |
source scripts/setenv.sh
./gradlew :domain-cc:dockerComposeUp
- name: "Start containers: domain-ee"
shell: bash
run: |
source scripts/setenv.sh
./gradlew :domain-ee:dockerComposeUp
- name: "Wait for containers to start"
run: |
STATUS="..."
while [ "$STATUS" != "All started" ]; do
echo "Waiting for containers to start..."
sleep 10
STATUS=$(docker container ls --format '{{.Names}} \t {{.Status}}' | grep "(health: starting)" \
|| echo "All started")
echo "$STATUS"
done
- name: "Check for unhealthy containers"
shell: bash
run: |
{
echo "## Docker containers"
echo '```'
docker ps --all
echo ''
echo '```'
} | tee -a $GITHUB_STEP_SUMMARY
# Ignore mocks and redis-service since they don't have health checks
# TODO: add health check for svc-bgs-api; ignore it for now
if docker container ls --format '{{.Names}} \t {{.Status}}' | grep -v "(healthy)" \
| grep -v "-mock-\|redis-service\|svc-bgs-api"; then
echo 'There are unexpected unhealthy containers!'
exit 2
fi
- name: "Check for exited containers"
shell: bash
run: |
# Ignore db-init since it is expected to exit once finished
# TODO: fix svc-bie-kafka so that it doesn't exit
if docker container ls --filter "status=exited" --format '{{.Names}} {{.Status}}' \
| grep -v "db-init\|svc-bie-kafka"; then
echo 'There are unexpected exited containers!'
exit 3
fi
- name: "Check for errors in container logs"
run: |
for C_NAME in $(docker container ls --format '{{.Names}}' | grep -v '-service1'); do
echo "## Searching $C_NAME container logs"
if docker logs "$C_NAME" 2>&1 | grep 'ERROR'; then
echo "::error::Unexpected ERROR in $C_NAME container logs"
ERROR_IN_LOGS=true
fi
done
if [ "$ERROR_IN_LOGS" ]; then
exit 4
fi
- name: "Collect docker logs"
if: always()
uses: jwalton/gh-docker-logs@v2
with:
dest: './healthchecks-container-logs'
- name: "Upload artifact"
if: always()
uses: actions/upload-artifact@v3
with:
name: healthchecks-container-logs
path: ./healthchecks-container-logs/**
retention-days: 14
- name: "Clean shutdown of all containers"
if: always()
shell: bash
run: |
COMPOSE_PROFILES="all" ./gradlew dockerComposeDown