Окоёмов Олег Валерьевич #302
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Compose Test | |
| on: | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test-compose: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Start services | |
| run: docker compose up -d | |
| - name: Check DB init script exit status | |
| run: | | |
| timeout=20 | |
| while [[ "$(docker compose ps -a --format '{{.State}}' dbinit)" != "exited" ]]; do | |
| ((timeout--)) | |
| if [ $timeout -eq 0 ]; then | |
| echo "DB init took too long" | |
| exit 1 | |
| fi | |
| sleep 1 | |
| done | |
| if [[ $(docker compose ps -a --format '{{.ExitCode}}' dbinit) ]]; then | |
| echo "DB initialized successfully!" | |
| else | |
| echo "Failed to initialize the DB" | |
| echo "ExitCode: $(docker compose ps -a --format '{{.ExitCode}}' dbinit)" | |
| exit 1 | |
| fi | |
| - name: Wait for web to be ready | |
| run: | | |
| timeout=60 | |
| while ! curl -f http://localhost:5000 >/dev/null 2>&1; do | |
| ((timeout--)) | |
| if [ $timeout -eq 0 ]; then | |
| echo "Web service failed to start" | |
| exit 1 | |
| fi | |
| sleep 1 | |
| done | |
| - name: Test web response | |
| run: | | |
| response=$(curl -s http://localhost:5000/ping) | |
| if [[ "$response" != "pong" ]]; then | |
| echo "Expected 'pong', got: $response" | |
| exit 1 | |
| fi | |
| echo "Web test passed!" | |
| - name: Test PostgreSQL connection | |
| run: | | |
| docker compose exec -T db pg_isready -U user -d app | |
| - name: Show logs on failure | |
| if: failure() | |
| run: docker compose logs |