Deploy to AKS #5
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: Deploy to AKS | |
| on: | |
| workflow_run: | |
| workflows: ["Build and Push Docker Images"] | |
| types: | |
| - completed | |
| branches: [main] | |
| workflow_dispatch: | |
| env: | |
| RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }} | |
| AKS_CLUSTER_NAME: ${{ secrets.AKS_CLUSTER_NAME }} | |
| ACR_LOGIN_SERVER: ${{ secrets.ACR_LOGIN_SERVER }} | |
| jobs: | |
| deploy: | |
| name: Deploy to AKS | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Log in to Azure | |
| uses: azure/login@v1 | |
| with: | |
| creds: ${{ secrets.AZURE_CREDENTIALS }} | |
| - name: Get AKS credentials | |
| run: | | |
| az aks get-credentials \ | |
| --resource-group ${{ env.RESOURCE_GROUP }} \ | |
| --name ${{ env.AKS_CLUSTER_NAME }} \ | |
| --overwrite-existing | |
| - name: Install Helm | |
| uses: azure/setup-helm@v3 | |
| with: | |
| version: '3.13.0' | |
| - name: Get image tag | |
| id: image-tag | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| echo "tag=latest" >> $GITHUB_OUTPUT | |
| else | |
| SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7) | |
| echo "tag=main-$SHORT_SHA" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Deploy Product Service | |
| run: | | |
| helm upgrade --install product-service ./helm/product-service \ | |
| --set image.repository=${{ env.ACR_LOGIN_SERVER }}/product-service \ | |
| --set image.tag=${{ steps.image-tag.outputs.tag }} \ | |
| --set image.pullPolicy=Always \ | |
| --wait \ | |
| --timeout 5m | |
| - name: Deploy Order Service | |
| run: | | |
| helm upgrade --install order-service ./helm/order-service \ | |
| --set image.repository=${{ env.ACR_LOGIN_SERVER }}/order-service \ | |
| --set image.tag=${{ steps.image-tag.outputs.tag }} \ | |
| --set image.pullPolicy=Always \ | |
| --set env[0].name=PRODUCT_SERVICE_URL \ | |
| --set env[0].value=http://product-service:8000 \ | |
| --wait \ | |
| --timeout 5m | |
| - name: Verify deployment | |
| run: | | |
| echo "Checking deployment status..." | |
| kubectl get pods | |
| kubectl get svc | |
| echo "Waiting for pods to be ready..." | |
| kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=product-service --timeout=300s | |
| kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=order-service --timeout=300s | |
| echo "Deployment successful!" | |
| - name: Get service endpoints | |
| run: | | |
| echo "=== Services ===" | |
| kubectl get svc | |
| echo "" | |
| echo "=== Pods ===" | |
| kubectl get pods -o wide | |
| - name: Deployment summary | |
| run: | | |
| echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Deployment completed successfully" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Image Tags" >> $GITHUB_STEP_SUMMARY | |
| echo "- Product Service: \`${{ steps.image-tag.outputs.tag }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- Order Service: \`${{ steps.image-tag.outputs.tag }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Resources" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| kubectl get all >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |