build_deploy_aks_canary #1
This file contains 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: build_deploy_aks_canary | |
on: | |
push: | |
paths: | |
- unit4/exercise4/** | |
workflow_dispatch: | |
env: | |
IMAGE_TAG: 1 | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'Checkout source code' | |
uses: actions/checkout@v3 | |
- name: 'Login to Azure Container Registry' | |
uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }} | |
username: ${{ secrets.REGISTRY_USERNAME }} | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
- name: 'Build and push the blue image (v1)' | |
run: | | |
docker build unit4/exercise4/blue/. -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/nginx:1 | |
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/nginx:1 | |
- name: 'Build and push the green image (v2)' | |
run: | | |
docker build unit4/exercise4/green/. -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/nginx:2 | |
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/nginx:2 | |
- name: 'Azure login' | |
id: login | |
uses: azure/login@v1.4.3 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: 'Set the target AKS cluster' | |
id: set-context | |
uses: azure/aks-set-context@v3 | |
with: | |
resource-group: '${{ secrets.RESOURCE_GROUP_AKS }}' | |
cluster-name: '${{ secrets.CLUSTER_NAME }}' | |
- name: Setup kubectl | |
id: install-kubectl | |
uses: azure/setup-kubectl@v3 | |
- name: Replace image name in manifest | |
run: | | |
sed -i 's/__REGISTRY-LOGIN-SERVER__/${{ secrets.REGISTRY_LOGIN_SERVER }}/g' unit4/exercise4/deployment.yaml | |
- name: Deploy to AKS | |
id: deploy-aks | |
uses: Azure/k8s-deploy@v4 | |
with: | |
namespace: default | |
manifests: | | |
unit4/exercise4/service.yaml | |
unit4/exercise4/deployment.yaml | |
images: | | |
${{ secrets.REGISTRY_LOGIN_SERVER }}/nginx:${{ env.IMAGE_TAG }} | |
strategy: canary | |
action: deploy | |
traffic-split-method: pod | |
percentage: 40 | |
baseline-and-canary-replicas: 2 | |
- name: 'Get public IP of demoapp' | |
id: getip | |
run: | | |
kubectl get service -l tier=networking | |
approveapp: | |
runs-on: ubuntu-latest | |
needs: build-and-deploy | |
environment: approveapp | |
steps: | |
- run: echo asked for approval | |
promotereject: | |
runs-on: ubuntu-latest | |
needs: approveapp | |
steps: | |
- uses: actions/checkout@v3 | |
- name: 'Azure login' | |
id: login | |
uses: azure/login@v1.4.3 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: 'Set the target AKS cluster' | |
uses: azure/aks-set-context@v3 | |
with: | |
resource-group: '${{ secrets.RESOURCE_GROUP_AKS }}' | |
cluster-name: '${{ secrets.CLUSTER_NAME }}' | |
- name: Replace image name in manifest | |
run: | | |
sed -i 's/__REGISTRY-LOGIN-SERVER__/${{ secrets.REGISTRY_LOGIN_SERVER }}/g' unit4/exercise4/deployment.yaml | |
- name: Promote App | |
uses: azure/k8s-deploy@v4 | |
if: ${{ success() }} | |
with: | |
namespace: default | |
manifests: | | |
unit4/exercise4/service.yaml | |
unit4/exercise4/deployment.yaml | |
images: | | |
${{ secrets.REGISTRY_LOGIN_SERVER }}/nginx:${{ env.IMAGE_TAG }} | |
strategy: canary | |
traffic-split-method: pod | |
action: promote #deploy is the default; we will later use this to promote/reject | |
percentage: 40 | |
baseline-and-canary-replicas: 2 | |
- name: Reject App | |
uses: azure/k8s-deploy@v4 | |
if: ${{ failure() }} | |
with: | |
namespace: default | |
manifests: | | |
unit4/exercise4/service.yaml | |
unit4/exercise4/deployment.yaml | |
images: | | |
${{ secrets.REGISTRY_LOGIN_SERVER }}/nginx:${{ env.IMAGE_TAG }} | |
strategy: canary | |
traffic-split-method: pod | |
action: reject #deploy is the default; we will later use this to promote/reject | |
percentage: 40 | |
baseline-and-canary-replicas: 2 |