Skip to content

Commit 54ebea9

Browse files
committed
Add CI workflow for Docker Compose testing
- Add test-docker-compose-ci.yml workflow to test Docker Compose setup - Test 'docker-compose up -d nginx-exporter' command functionality - Verify nginx-exporter container starts correctly and serves metrics - Test full monitoring stack integration (nginx, prometheus, grafana) - Validate service connectivity and metrics collection - Include proper error handling and cleanup procedures - Add detailed logging for troubleshooting failures - Follow project CI conventions and use consistent action versions
1 parent 3d7ff39 commit 54ebea9

File tree

1 file changed

+286
-0
lines changed

1 file changed

+286
-0
lines changed
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
name: Docker Compose Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'docker-compose.yml'
9+
- 'examples/docker-compose/**'
10+
- '.github/workflows/test-docker-compose-ci.yml'
11+
pull_request:
12+
branches:
13+
- main
14+
paths:
15+
- 'docker-compose.yml'
16+
- 'examples/docker-compose/**'
17+
- '.github/workflows/test-docker-compose-ci.yml'
18+
19+
defaults:
20+
run:
21+
shell: bash
22+
23+
concurrency:
24+
group: ${{ github.ref_name }}-test-docker-compose-ci
25+
cancel-in-progress: true
26+
27+
permissions:
28+
contents: read
29+
30+
jobs:
31+
docker-compose-nginx-exporter:
32+
name: Docker Compose - NGINX Exporter
33+
runs-on: ubuntu-24.04
34+
steps:
35+
- name: Checkout Repository
36+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
37+
38+
- name: Setup Docker Buildx
39+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
40+
41+
- name: Validate Docker Compose configuration
42+
run: |
43+
echo "Validating Docker Compose configuration..."
44+
docker-compose config --quiet
45+
echo "✓ Docker Compose configuration is valid"
46+
47+
- name: Start NGINX Exporter with dependencies
48+
run: |
49+
echo "Starting NGINX Exporter and its dependencies..."
50+
docker-compose up -d nginx-exporter
51+
echo "✓ NGINX Exporter started successfully"
52+
53+
- name: Wait for services to be ready
54+
run: |
55+
echo "Waiting for services to be ready..."
56+
57+
# Wait for NGINX to be ready
58+
for i in {1..30}; do
59+
if curl -s http://localhost:8081/stub_status > /dev/null 2>&1; then
60+
echo "✓ NGINX stub_status is ready"
61+
break
62+
fi
63+
echo "Waiting for NGINX stub_status... (attempt $i/30)"
64+
sleep 2
65+
done
66+
67+
# Wait for NGINX Exporter to be ready
68+
for i in {1..30}; do
69+
if curl -s http://localhost:9113/metrics > /dev/null 2>&1; then
70+
echo "✓ NGINX Exporter metrics endpoint is ready"
71+
break
72+
fi
73+
echo "Waiting for NGINX Exporter metrics... (attempt $i/30)"
74+
sleep 2
75+
done
76+
77+
- name: Verify container status
78+
run: |
79+
echo "Verifying container status..."
80+
docker-compose ps
81+
82+
# Check if nginx-exporter container is running
83+
if ! docker-compose ps nginx-exporter | grep -q "Up"; then
84+
echo "❌ NGINX Exporter container is not running"
85+
docker-compose logs nginx-exporter
86+
exit 1
87+
fi
88+
echo "✓ NGINX Exporter container is running"
89+
90+
# Check if nginx container is running
91+
if ! docker-compose ps nginx | grep -q "Up"; then
92+
echo "❌ NGINX container is not running"
93+
docker-compose logs nginx
94+
exit 1
95+
fi
96+
echo "✓ NGINX container is running"
97+
98+
- name: Test NGINX stub_status endpoint
99+
run: |
100+
echo "Testing NGINX stub_status endpoint..."
101+
response=$(curl -s http://localhost:8081/stub_status)
102+
103+
if [[ -z "$response" ]]; then
104+
echo "❌ NGINX stub_status endpoint returned empty response"
105+
exit 1
106+
fi
107+
108+
# Check if response contains expected metrics
109+
if echo "$response" | grep -q "Active connections:"; then
110+
echo "✓ NGINX stub_status endpoint is working correctly"
111+
else
112+
echo "❌ NGINX stub_status endpoint response is invalid"
113+
echo "Response: $response"
114+
exit 1
115+
fi
116+
117+
- name: Test NGINX Exporter metrics endpoint
118+
run: |
119+
echo "Testing NGINX Exporter metrics endpoint..."
120+
response=$(curl -s http://localhost:9113/metrics)
121+
122+
if [[ -z "$response" ]]; then
123+
echo "❌ NGINX Exporter metrics endpoint returned empty response"
124+
exit 1
125+
fi
126+
127+
# Check if response contains expected NGINX metrics
128+
if echo "$response" | grep -q "nginx_connections_accepted"; then
129+
echo "✓ NGINX Exporter metrics endpoint is working correctly"
130+
else
131+
echo "❌ NGINX Exporter metrics endpoint response is invalid"
132+
echo "Response: $response"
133+
exit 1
134+
fi
135+
136+
- name: Verify metrics collection
137+
run: |
138+
echo "Verifying metrics collection..."
139+
140+
# Generate some traffic to NGINX
141+
echo "Generating traffic to NGINX..."
142+
for i in {1..5}; do
143+
curl -s http://localhost:80 > /dev/null || true
144+
sleep 1
145+
done
146+
147+
# Wait a moment for metrics to be updated
148+
sleep 3
149+
150+
# Check if metrics are being collected
151+
metrics=$(curl -s http://localhost:9113/metrics)
152+
153+
# Verify nginx_up metric exists and is 1
154+
if echo "$metrics" | grep -q "nginx_up 1"; then
155+
echo "✓ NGINX Exporter is successfully collecting metrics"
156+
else
157+
echo "❌ NGINX Exporter is not collecting metrics correctly"
158+
echo "nginx_up metric:"
159+
echo "$metrics" | grep "nginx_up" || echo "nginx_up metric not found"
160+
exit 1
161+
fi
162+
163+
# Verify connection metrics exist
164+
if echo "$metrics" | grep -q "nginx_connections_accepted"; then
165+
echo "✓ Connection metrics are being collected"
166+
else
167+
echo "❌ Connection metrics are not being collected"
168+
exit 1
169+
fi
170+
171+
- name: Test service connectivity
172+
run: |
173+
echo "Testing service connectivity..."
174+
175+
# Test that services can communicate internally
176+
docker exec nginx-prometheus-exporter curl -f http://nginx:8081/stub_status > /dev/null
177+
echo "✓ Services can communicate internally"
178+
179+
- name: Show container logs on failure
180+
if: failure()
181+
run: |
182+
echo "=== NGINX Exporter Logs ==="
183+
docker-compose logs nginx-exporter
184+
echo "=== NGINX Logs ==="
185+
docker-compose logs nginx
186+
echo "=== App Logs ==="
187+
docker-compose logs app || true
188+
echo "=== Container Status ==="
189+
docker-compose ps
190+
191+
- name: Cleanup
192+
if: always()
193+
run: |
194+
echo "Cleaning up..."
195+
docker-compose down -v
196+
docker system prune -f
197+
198+
docker-compose-full-stack:
199+
name: Docker Compose - Full Stack
200+
runs-on: ubuntu-24.04
201+
steps:
202+
- name: Checkout Repository
203+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
204+
205+
- name: Setup Docker Buildx
206+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
207+
208+
- name: Start full monitoring stack
209+
run: |
210+
echo "Starting full monitoring stack..."
211+
docker-compose up -d
212+
echo "✓ Full monitoring stack started successfully"
213+
214+
- name: Wait for all services to be ready
215+
run: |
216+
echo "Waiting for all services to be ready..."
217+
218+
# Wait for all services to be healthy
219+
services=("nginx:8081/stub_status" "nginx-exporter:9113/metrics" "prometheus:9090/-/ready" "grafana:3000/api/health")
220+
221+
for service in "${services[@]}"; do
222+
IFS=':' read -r host_port path <<< "$service"
223+
224+
for i in {1..60}; do
225+
if curl -s "http://localhost:${host_port}${path}" > /dev/null 2>&1; then
226+
echo "✓ Service ${host_port} is ready"
227+
break
228+
fi
229+
echo "Waiting for service ${host_port}... (attempt $i/60)"
230+
sleep 2
231+
done
232+
done
233+
234+
- name: Verify all containers are running
235+
run: |
236+
echo "Verifying all containers are running..."
237+
docker-compose ps
238+
239+
# Check that all expected services are up
240+
services=("nginx" "nginx-exporter" "prometheus" "grafana" "app")
241+
242+
for service in "${services[@]}"; do
243+
if ! docker-compose ps "$service" | grep -q "Up"; then
244+
echo "❌ Service $service is not running"
245+
docker-compose logs "$service"
246+
exit 1
247+
fi
248+
echo "✓ Service $service is running"
249+
done
250+
251+
- name: Test full stack integration
252+
run: |
253+
echo "Testing full stack integration..."
254+
255+
# Test Prometheus can scrape NGINX Exporter
256+
prometheus_targets=$(curl -s http://localhost:9090/api/v1/targets)
257+
if echo "$prometheus_targets" | grep -q "nginx-exporter:9113"; then
258+
echo "✓ Prometheus is configured to scrape NGINX Exporter"
259+
else
260+
echo "❌ Prometheus is not configured to scrape NGINX Exporter"
261+
exit 1
262+
fi
263+
264+
# Test Grafana is accessible
265+
grafana_health=$(curl -s http://localhost:3000/api/health)
266+
if echo "$grafana_health" | grep -q "ok"; then
267+
echo "✓ Grafana is healthy"
268+
else
269+
echo "❌ Grafana is not healthy"
270+
exit 1
271+
fi
272+
273+
- name: Show container logs on failure
274+
if: failure()
275+
run: |
276+
echo "=== All Container Logs ==="
277+
docker-compose logs
278+
echo "=== Container Status ==="
279+
docker-compose ps
280+
281+
- name: Cleanup
282+
if: always()
283+
run: |
284+
echo "Cleaning up..."
285+
docker-compose down -v
286+
docker system prune -f

0 commit comments

Comments
 (0)