Merge pull request #1 from kundanr2/development #2
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: Backend CI - Test, Build and Push Images to ACR | |
| on: | |
| # Trigger on pull requests into development branch | |
| pull_request: | |
| branches: | |
| - development | |
| paths: | |
| - 'backend/**' | |
| - '.github/workflows/backend_ci.yml' | |
| # Trigger on pushes to main branch | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'backend/**' | |
| - '.github/workflows/backend_ci.yml' | |
| # Manual trigger | |
| workflow_dispatch: | |
| env: | |
| ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} | |
| IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} | |
| jobs: | |
| test_and_lint_backends: | |
| runs-on: ubuntu-latest | |
| services: | |
| product_db: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_DB: products | |
| options: >- | |
| --health-cmd "pg_isready -U postgres" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| order_db: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_DB: orders | |
| ports: | |
| - 5433:5432 | |
| options: >- | |
| --health-cmd "pg_isready -U postgres" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| pip install --upgrade pip | |
| for req in backend/*/requirements.txt; do | |
| echo "Installing $req" | |
| pip install -r "$req" | |
| done | |
| pip install pytest httpx | |
| - name: Run product_service tests | |
| working-directory: backend/product_service | |
| env: | |
| POSTGRES_HOST: localhost | |
| POSTGRES_PORT: 5432 | |
| POSTGRES_DB: products | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| run: pytest tests --maxfail=1 --disable-warnings -q | |
| - name: Run order_service tests | |
| working-directory: backend/order_service | |
| env: | |
| POSTGRES_HOST: localhost | |
| POSTGRES_PORT: 5433 | |
| POSTGRES_DB: orders | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| run: pytest tests --maxfail=1 --disable-warnings -q | |
| build_and_push_images: | |
| runs-on: ubuntu-latest | |
| needs: test_and_lint_backends | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Azure Login | |
| uses: azure/login@v1 | |
| with: | |
| creds: ${{ secrets.AZURE_CREDENTIALS }} | |
| - name: Login to Azure Container Registry | |
| run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} | |
| - name: Build and Push Product Service Image | |
| run: | | |
| docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:latest ./backend/product_service/ | |
| docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:latest | |
| - name: Build and Push Order Service Image | |
| run: | | |
| docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:latest ./backend/order_service/ | |
| docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:latest | |
| - name: Logout from Azure | |
| run: az logout | |
| if: always() |