diff --git a/.github/workflows/run-docker-compose-prod.yml b/.github/workflows/run-docker-compose-prod.yml index 1bd0e25a..2934f891 100644 --- a/.github/workflows/run-docker-compose-prod.yml +++ b/.github/workflows/run-docker-compose-prod.yml @@ -18,21 +18,62 @@ jobs: - name: Modify Dockerfile to disable USER www (which is not supported by GitHub Actions, as it runs as root) run: | sed -i '/USER www/s/^/#/' ./Dockerfile - - name: Set up Docker Compose - run: | - # Build the images and start the services - docker compose -f docker-compose.prod.yml up -d - # Ensure the database is ready - docker compose exec -T ogame-db bash -c 'until mariadb -h "ogame-db" -u "root" -p"toor" -e "SELECT 1"; do sleep 1; done' - name: Set Permissions - run: docker compose exec -T ogame-app chmod -R 777 /var/www + run: sudo chmod -R 777 /var/www - name: Copy .env - run: docker compose exec -T ogame-app cp .env.example-prod .env - - name: Run Laravel setup commands + run: sudo cp .env.example-prod .env + - name: Build and start the services run: | - docker compose exec -T ogame-app composer install --no-dev - docker compose exec -T ogame-app php artisan key:generate - - name: Run DB Migrations - run: docker compose exec -T ogame-app php artisan migrate --force - - name: Run configuration cache commands - run: docker compose exec -T ogame-app php artisan cache:clear && docker compose exec -T ogame-app php artisan config:cache && docker compose exec -T ogame-app php artisan route:cache && docker compose exec -T ogame-app php artisan view:cache \ No newline at end of file + # Build the images and start the services + docker compose -f docker-compose.prod.yml up -d + - name: Test if the services are running + uses: nick-fields/retry@v3 + with: + timeout_minutes: 5 + max_attempts: 5 + command: | + sleep 15 + + # Array of endpoints to test + declare -A endpoints=( + ["Web"]="https://localhost:443" + ) + + failed=false + + # Test HTTP endpoints + for name in "${!endpoints[@]}"; do + url="${endpoints[$name]}" + echo "Testing $name at $url" + + # Store both response body and HTTP code + response=$(curl -k -s -w "\nHTTP_CODE=%{http_code}" "$url") + http_code=$(echo "$response" | grep "HTTP_CODE=" | cut -d= -f2) + body=$(echo "$response" | sed '$d') # Remove the last line (HTTP_CODE) + + if [ "$http_code" -ne 200 ]; then + echo "❌ $name failed with HTTP $http_code at $url" + echo "Response body:" + echo "$body" + failed=true + else + echo "✅ $name responded with HTTP 200" + fi + done + + # Exit with error if any service failed + if [ "$failed" = true ]; then + # Get container logs + echo "Container Logs ogame-app:" + docker compose logs ogame-app + echo "Container Logs ogame-db:" + docker compose logs ogame-db + echo "Container Logs ogame-webserver:" + docker compose logs ogame-webserver + echo "Container Logs scheduler:" + docker compose logs scheduler + + # Restart containers for next test in case of failure + docker compose restart + exit 1 + fi \ No newline at end of file diff --git a/.github/workflows/run-tests-docker-compose-prod.yml b/.github/workflows/run-tests-docker-compose-prod.yml index 70dba9df..15c9b747 100644 --- a/.github/workflows/run-tests-docker-compose-prod.yml +++ b/.github/workflows/run-tests-docker-compose-prod.yml @@ -20,24 +20,14 @@ jobs: - name: Modify Dockerfile to disable USER www (which is not supported by GitHub Actions, as it runs as root) run: | sed -i '/USER www/s/^/#/' ./Dockerfile + - name: Set Permissions + run: sudo chmod -R 777 /var/www + - name: Copy .env + run: sudo cp .env.example-prod .env - name: Set up Docker Compose run: | # Build the images and start the services docker compose -f docker-compose.prod.yml up -d - # Ensure the database is ready - docker compose exec -T ogame-db bash -c 'until mariadb -h "ogame-db" -u "root" -p"toor" -e "SELECT 1"; do sleep 1; done' - - name: Set Permissions - run: docker compose exec -T ogame-app chmod -R 777 /var/www - - name: Copy .env - run: docker compose exec -T ogame-app cp .env.example-prod .env - - name: Run Laravel setup commands - run: | - docker compose exec -T ogame-app composer install - docker compose exec -T ogame-app php artisan key:generate - - name: Run DB Migrations - run: docker compose exec -T ogame-app php artisan migrate --force - - name: Run configuration cache commands - run: docker compose exec -T ogame-app php artisan cache:clear && docker compose exec -T ogame-app php artisan config:cache && docker compose exec -T ogame-app php artisan route:cache && docker compose exec -T ogame-app php artisan view:cache - name: Run Tests run: docker compose exec -T ogame-app php artisan test - name: Run custom Race Condition Tests diff --git a/.github/workflows/run-tests-docker-compose.yml b/.github/workflows/run-tests-docker-compose.yml index bd432200..3f579770 100644 --- a/.github/workflows/run-tests-docker-compose.yml +++ b/.github/workflows/run-tests-docker-compose.yml @@ -18,24 +18,14 @@ jobs: - name: Modify Dockerfile to disable USER www (which is not supported by GitHub Actions, as it runs as root) run: | sed -i '/USER www/s/^/#/' ./Dockerfile + - name: Set Permissions + run: sudo chmod -R 777 /var/www + - name: Copy .env + run: sudo cp .env.example .env - name: Set up Docker Compose run: | # Build the images and start the services docker compose -f docker-compose.yml up -d - # Ensure the database is ready - docker compose exec -T ogame-db bash -c 'until mariadb -h "ogame-db" -u "root" -p"toor" -e "SELECT 1"; do sleep 1; done' - - name: Set Permissions - run: docker compose exec -T ogame-app chmod -R 777 /var/www - - name: Copy .env - run: docker compose exec -T ogame-app cp .env.example .env - - name: Run Laravel setup commands - run: | - docker compose exec -T ogame-app composer install - docker compose exec -T ogame-app php artisan key:generate - - name: Run DB Migrations - run: docker compose exec -T ogame-app php artisan migrate - - name: Run configuration cache commands - run: docker compose exec -T ogame-app php artisan cache:clear && docker compose exec -T ogame-app php artisan config:cache && docker compose exec -T ogame-app php artisan route:cache && docker compose exec -T ogame-app php artisan view:cache - name: Run Tests run: docker compose exec -T ogame-app php artisan test - name: Run custom Race Condition Tests