Марченко Вадим Витальевич #283
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 --wait | |
| - name: Test PostgreSQL connection | |
| run: | | |
| docker compose exec -T db pg_isready -U user -d app | |
| - name: Test sql init | |
| run: | | |
| check_query="SELECT EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'visitors');" | |
| check=`docker compose exec db psql -d app -U user -tAc "$check_query"` | |
| if [[ $check != "t" ]]; then | |
| echo "Expected 't', got: $check" | |
| exit 1 | |
| fi | |
| echo "SQL init test passed!" | |
| - 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: Show logs on failure | |
| if: failure() | |
| run: docker compose logs | |
| test-dev: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Start services | |
| run: docker compose -f docker-compose.dev.yml up -d --wait | |
| - 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/visits) | |
| if [[ "$response" != "-1" ]]; then | |
| echo "Expected '-1', got: $response" | |
| exit 1 | |
| fi | |
| echo "Web test passed!" | |
| - name: Show logs on failure | |
| if: failure() | |
| run: docker compose logs |