meshtastic-metrics-exporter/.github/workflows/main.yml

69 lines
2 KiB
YAML
Raw Normal View History

2024-07-09 23:22:51 -07:00
name: Meshtastic Metrics Exporter Health Check
2024-07-09 23:18:29 -07:00
on:
pull_request:
branches: [ main ]
jobs:
check-containers:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Start Docker Compose
run: docker-compose up -d
- name: Wait for containers to start
2024-07-09 23:22:51 -07:00
run: sleep 60 # 1 Minute
2024-07-09 23:18:29 -07:00
2024-07-09 23:29:47 -07:00
- name: Check container statuses and logs
2024-07-09 23:18:29 -07:00
run: |
2024-07-09 23:22:51 -07:00
services=("prometheus" "grafana" "exporter" "postgres")
2024-07-09 23:18:29 -07:00
for service in "${services[@]}"
do
container_id=$(docker-compose ps -q $service)
if [ -z "$container_id" ]; then
echo "Error: Container for $service not found"
2024-07-09 23:29:47 -07:00
docker-compose logs $service
2024-07-09 23:18:29 -07:00
exit 1
fi
status=$(docker inspect --format='{{.State.Status}}' $container_id)
restarts=$(docker inspect --format='{{.RestartCount}}' $container_id)
if [ "$status" != "running" ]; then
echo "Error: Container $service ($container_id) is not running. Current status: $status"
2024-07-09 23:29:47 -07:00
echo "Last logs for $service:"
docker-compose logs --tail=50 $service
2024-07-09 23:18:29 -07:00
exit 1
fi
if [ "$restarts" -gt 0 ]; then
echo "Error: Container $service ($container_id) has restarted $restarts times"
2024-07-09 23:29:47 -07:00
echo "Last logs for $service:"
docker-compose logs --tail=50 $service
2024-07-09 23:18:29 -07:00
exit 1
fi
echo "Container $service is running properly and has not restarted."
done
2024-07-09 23:22:51 -07:00
- name: Check exposed ports
run: |
2024-07-09 23:44:57 -07:00
expected_ports=("9090" "3000")
2024-07-09 23:22:51 -07:00
for port in "${expected_ports[@]}"
do
if ! netstat -tuln | grep -q ":$port "; then
echo "Error: Port $port is not exposed"
exit 1
fi
echo "Port $port is correctly exposed"
done
2024-07-09 23:18:29 -07:00
- name: Clean up
if: always()
2024-07-09 23:22:51 -07:00
run: docker-compose down -v