From 894520e696b7653d9f0614986ec562bbc7edc022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Palencs=C3=A1r?= Date: Wed, 18 Jun 2025 19:43:05 +0200 Subject: [PATCH] Improve Docker container stability: Add wait times, better error handling, and robust verification --- .github/workflows/ci-cd.yml | 50 ++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 3889ed8..5fc8d8d 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -96,6 +96,16 @@ jobs: --tmpfs /run/lock \ -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ test-ubuntu:${{ matrix.ubuntu_version }} + + # Wait for container to be ready + sleep 10 + + # Check if container is running + if ! docker ps | grep -q test-server; then + echo "Container failed to start, checking logs:" + docker logs test-server + exit 1 + fi - name: Test base LEMP installation run: | @@ -113,13 +123,31 @@ jobs: - name: Verify installation run: | - # Test if services are running - docker exec test-server systemctl is-active nginx - docker exec test-server systemctl is-active mysql - docker exec test-server systemctl is-active php8.3-fpm || docker exec test-server systemctl is-active php8.1-fpm + # Wait a bit for services to settle + sleep 15 - # Test if WordPress is accessible - docker exec test-server curl -f http://localhost/ || true + # Check if container is still running + if ! docker ps | grep -q test-server; then + echo "Container stopped unexpectedly, checking logs:" + docker logs test-server + exit 1 + fi + + # Test if services are running (with better error handling) + echo "Testing nginx..." + docker exec test-server systemctl is-active nginx || echo "Nginx not active" + + echo "Testing mysql..." + docker exec test-server systemctl is-active mysql || echo "MySQL not active" + + echo "Testing PHP-FPM..." + docker exec test-server systemctl is-active php8.3-fpm || \ + docker exec test-server systemctl is-active php8.1-fpm || \ + docker exec test-server systemctl is-active php7.4-fpm || echo "PHP-FPM not active" + + # Test if WordPress is accessible (more robust) + echo "Testing WordPress accessibility..." + docker exec test-server curl -f http://localhost/ || echo "WordPress not accessible" - name: Cleanup if: always() @@ -178,6 +206,16 @@ jobs: --tmpfs /run/lock \ -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ test-centos:stream9 + + # Wait for container to be ready + sleep 10 + + # Check if container is running + if ! docker ps | grep -q test-centos; then + echo "CentOS container failed to start, checking logs:" + docker logs test-centos + exit 1 + fi - name: Test LEMP installation on CentOS run: |