|
| 1 | +# This workflow will build a docker container, publish it to Azure Container Registry, and deploy it to Azure Kubernetes Service using a helm chart. |
| 2 | +# |
| 3 | +# https://github.com/Azure/actions-workflow-samples/tree/master/Kubernetes |
| 4 | +# |
| 5 | +# To configure this workflow: |
| 6 | +# |
| 7 | +# 1. Set up the following secrets in your workspace: |
| 8 | +# a. REGISTRY_USERNAME with ACR username |
| 9 | +# b. REGISTRY_PASSWORD with ACR Password |
| 10 | +# c. AZURE_CREDENTIALS with the output of `az ad sp create-for-rbac --sdk-auth` |
| 11 | +# |
| 12 | +# 2. Change the values for the REGISTRY_NAME, CLUSTER_NAME, CLUSTER_RESOURCE_GROUP and NAMESPACE environment variables (below). |
| 13 | +name: publish |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: |
| 17 | + - master |
| 18 | + |
| 19 | +# Environment variables available to all jobs and steps in this workflow |
| 20 | +env: |
| 21 | + REGISTRY_NAME: k8scc01covidacr |
| 22 | + CLUSTER_NAME: k8s-cancentral-02-covid-aks |
| 23 | + CLUSTER_RESOURCE_GROUP: k8s-cancentral-01-covid-aks |
| 24 | + NAMESPACE: web |
| 25 | + |
| 26 | +jobs: |
| 27 | + build: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@master |
| 31 | + |
| 32 | + # Connect to Azure Container registry (ACR) |
| 33 | + - uses: azure/docker-login@v1 |
| 34 | + with: |
| 35 | + login-server: ${{ env.REGISTRY_NAME }}.azurecr.io |
| 36 | + username: ${{ secrets.REGISTRY_USERNAME }} |
| 37 | + password: ${{ secrets.REGISTRY_PASSWORD }} |
| 38 | + |
| 39 | + # Container build and push to a Azure Container registry (ACR) |
| 40 | + - run: | |
| 41 | + docker build -f Dockerfile -t ${{ env.REGISTRY_NAME }}.azurecr.io/jupyter-apis:${{ github.sha }} . |
| 42 | + docker push ${{ env.REGISTRY_NAME }}.azurecr.io/jupyter-apis:${{ github.sha }} |
| 43 | +
|
| 44 | + # Scan image for vulnerabilities |
| 45 | + - uses: Azure/container-scan@v0 |
| 46 | + with: |
| 47 | + image-name: ${{ env.REGISTRY_NAME }}.azurecr.io/jupyter-apis:${{ github.sha }} |
| 48 | + severity-threshold: CRITICAL |
| 49 | + run-quality-checks: false |
| 50 | + |
| 51 | + # Prepare to deploy the image |
| 52 | + - run: | |
| 53 | + sed -i -E 's/[0-9a-f]{40}/${{ github.sha }}/g' deploy/deploy.yaml |
| 54 | +
|
| 55 | + # Deploy to Kubernetes |
| 56 | + - name: kubectl |
| 57 | + uses: statcan/actions/kubectl@master |
| 58 | + with: |
| 59 | + kubeconfig: ${{ secrets.KUBECONFIG }} |
| 60 | + args: apply -f deploy/deploy.yaml |
0 commit comments