-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (162 loc) · 5.9 KB
/
Copy pathtest-integration.yml
File metadata and controls
196 lines (162 loc) · 5.9 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: test integration
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
permissions:
contents: read
jobs:
docker-test:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
- name: set up docker buildx
uses: docker/setup-buildx-action@v3
- name: build docker image
run: |
docker build -t a-healthy-dns:test .
- name: test docker image with alias zone configuration
run: |
# Create an isolated network for deterministic container-to-container checks
docker network create --subnet 172.28.0.0/24 a-healthy-dns-test-net
# Start backend service that health checks can reach
docker run -d \
--name a-healthy-dns-backend \
--network a-healthy-dns-test-net \
--ip 172.28.0.10 \
nginx:alpine
# Start DNS server with hosted zone plus alias zones
docker run -d \
--name a-healthy-dns-test \
--network a-healthy-dns-test-net \
-p 53053:53053/udp \
-e DNS_HOSTED_ZONE="test.example.com" \
-e DNS_ALIAS_ZONES='["test.other.com","test.another.com"]' \
-e DNS_ZONE_RESOLUTIONS='{"www":{"ips":["172.28.0.10"],"health_port":80}}' \
-e DNS_NAME_SERVERS='["ns1.test.example.com"]' \
-e DNS_PORT="53053" \
-e DNS_TEST_MIN_INTERVAL="1" \
-e DNS_TEST_TIMEOUT="1" \
-e DNS_LOG_LEVEL="debug" \
a-healthy-dns:test
- name: wait for dns server to start
run: |
# Wait a bit for the server to fully start
sleep 5
# Check if containers are still running
docker ps | grep a-healthy-dns-backend
docker ps | grep a-healthy-dns-test
- name: test dns server functionality
run: |
set -euo pipefail
# Install dig for testing
sudo apt-get update && sudo apt-get install -y dnsutils
DNS_HOST="127.0.0.1"
DNS_PORT="53053"
BACKEND_IP="172.28.0.10"
wait_for_a_record() {
local fqdn="$1"
local answer
for _ in $(seq 1 20); do
answer="$(dig +short +time=1 +tries=1 @"${DNS_HOST}" -p "${DNS_PORT}" "${fqdn}" A)"
printf '%s\n' "${answer}" | grep -qx "${BACKEND_IP}" && {
echo "[OK] A ${fqdn}"
return 0
}
sleep 1
done
echo "[FAIL] A ${fqdn}"
dig +nocmd +noall +comments +answer @"${DNS_HOST}" -p "${DNS_PORT}" "${fqdn}" A || true
return 1
}
for fqdn in \
"www.test.example.com" \
"www.test.other.com" \
"www.test.another.com"; do
wait_for_a_record "${fqdn}"
done
- name: test health-check-driven dns state transitions
run: |
set -euo pipefail
DNS_HOST="127.0.0.1"
DNS_PORT="53053"
BACKEND_IP="172.28.0.10"
MAX_RETRIES=20
wait_for_a_record() {
local fqdn="$1"
local answer
for _ in $(seq 1 "${MAX_RETRIES}"); do
answer="$(dig +short +time=1 +tries=1 @"${DNS_HOST}" -p "${DNS_PORT}" "${fqdn}" A)"
printf '%s\n' "${answer}" | grep -qx "${BACKEND_IP}" && {
echo "[OK] A present: ${fqdn}"
return 0
}
sleep 1
done
echo "[FAIL] A never appeared: ${fqdn}"
dig +nocmd +noall +comments +answer @"${DNS_HOST}" -p "${DNS_PORT}" "${fqdn}" A || true
return 1
}
wait_for_a_record_gone() {
local fqdn="$1"
local answer
for _ in $(seq 1 "${MAX_RETRIES}"); do
answer="$(dig +short +time=1 +tries=1 @"${DNS_HOST}" -p "${DNS_PORT}" "${fqdn}" A)"
[ -z "${answer}" ] && {
echo "[OK] A removed: ${fqdn}"
return 0
}
sleep 1
done
echo "[FAIL] A still present after backend went down: ${fqdn}"
dig +nocmd +noall +comments +answer @"${DNS_HOST}" -p "${DNS_PORT}" "${fqdn}" A || true
return 1
}
# Verify state transitions for hosted zone and all alias zones
for fqdn in \
"www.test.example.com" \
"www.test.other.com" \
"www.test.another.com"; do
wait_for_a_record "${fqdn}"
done
# Stop backend — health checks will fail; DNS must remove A records from all zones
docker stop a-healthy-dns-backend
for fqdn in \
"www.test.example.com" \
"www.test.other.com" \
"www.test.another.com"; do
wait_for_a_record_gone "${fqdn}"
done
# Restart backend — health checks will succeed; DNS must re-add A records to all zones
docker start a-healthy-dns-backend
for fqdn in \
"www.test.example.com" \
"www.test.other.com" \
"www.test.another.com"; do
wait_for_a_record "${fqdn}"
done
- name: test docker-compose configuration
run: |
# Test that docker-compose example file is valid
if [ -f docker-compose.example.yml ]; then
# Install docker-compose
sudo apt-get install -y docker-compose
# Validate the compose file syntax
docker-compose -f docker-compose.example.yml config > /dev/null && echo "[OK] docker-compose.example.yml is valid"
else
echo "docker-compose.example.yml not found"
fi
- name: cleanup
if: always()
run: |
# Stop and remove test containers
docker stop a-healthy-dns-backend || true
docker stop a-healthy-dns-test || true
docker rm a-healthy-dns-backend || true
docker rm a-healthy-dns-test || true
# Remove test network
docker network rm a-healthy-dns-test-net || true
# Remove test image
docker rmi a-healthy-dns:test || true