1616 - ' backend/**'
1717 - ' .github/workflows/backend_ci.yml' # Trigger if this workflow file changes
1818
19+ # Define global environment variables that can be used across jobs
20+ env :
21+ # ACR Login Server (e.g., myregistry.azurecr.io)
22+ # This needs to be set as a GitHub Repository Secret
23+ ACR_LOGIN_SERVER : ${{ secrets.ACR_LOGIN_SERVER }}
1924
2025jobs :
21- # Define a matrix job to run checks for each backend service concurrently
26+ # Job 1: Run tests and linting for all backend services
2227 test_and_lint_backends :
2328 runs-on : ubuntu-latest # Use a GitHub-hosted runner
2429
@@ -133,3 +138,45 @@ jobs:
133138 POSTGRES_PASSWORD : postgres
134139 run : |
135140 pytest tests --maxfail=1 --disable-warnings -q
141+
142+ # Job 2: Build and Push Docker Images (runs only if tests pass)
143+ build_and_push_images :
144+ runs-on : ubuntu-latest
145+ needs : test_and_lint_backends
146+
147+ steps :
148+ - name : Checkout repository
149+ uses : actions/checkout@v4
150+
151+ # Azure login using a Service Principal secret
152+ - name : Azure Login
153+ uses : azure/login@v1
154+ with :
155+ creds : ${{ secrets.AZURE_CREDENTIALS }} # Needs to be set as a GitHub Secret (Service Principal JSON)
156+
157+ # Login to Azure Container Registry (ACR)
158+ - name : Login to Azure Container Registry
159+ run : az acr login --name ${{ env.ACR_LOGIN_SERVER }}
160+
161+ # Build and Push Docker image for Product Service
162+ - name : Build and Push Product Service Image
163+ run : |
164+ docker build -t ${{ env.ACR_LOGIN_SERVER }}/product-service:latest ./backend/product_service/
165+ docker push ${{ env.ACR_LOGIN_SERVER }}/product-service:latest
166+
167+ # Build and Push Docker image for Order Service
168+ - name : Build and Push Order Service Image
169+ run : |
170+ docker build -t ${{ env.ACR_LOGIN_SERVER }}/order-service:latest ./backend/order_service/
171+ docker push ${{ env.ACR_LOGIN_SERVER }}/order-service:latest
172+
173+ # Build and Push Docker image for Customer Service
174+ - name : Build and Push Customer Service Image
175+ run : |
176+ docker build -t ${{ env.ACR_LOGIN_SERVER }}/customer-service:latest ./backend/customer_service/
177+ docker push ${{ env.ACR_LOGIN_SERVER }}/customer-service:latest
178+
179+ # Logout from Azure for security (runs even if image push fails)
180+ - name : Logout from Azure
181+ run : az logout
182+ if : always()
0 commit comments