You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.1 KiB

  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. # To configure this workflow:
  4. #
  5. # 1. Set up the following secrets in your workspace:
  6. # a. REGISTRY_USERNAME with ACR username
  7. # b. REGISTRY_PASSWORD with ACR Password
  8. # c. AZURE_CREDENTIALS with the output of `az ad sp create-for-rbac --sdk-auth`
  9. #
  10. # 2. Change the values for the REGISTRY_NAME, CLUSTER_NAME, CLUSTER_RESOURCE_GROUP and NAMESPACE environment variables (below).
  11. on:
  12. workflow_dispatch:
  13. # Inputs the workflow accepts.
  14. inputs:
  15. name:
  16. # Friendly description to be shown in the UI instead of 'name'
  17. description: 'exec name'
  18. # Default value if no value is explicitly provided
  19. default: 'default execution'
  20. # Input has to be provided for the workflow to run
  21. required: false
  22. # Environment variables available to all jobs and steps in this workflow
  23. env:
  24. REGISTRY_NAME: ${{ secrets.REGISTRY_NAME }}
  25. CLUSTER_NAME: ${{ secrets.CLUSTER_NAME}}
  26. CLUSTER_RESOURCE_GROUP: ${{ secrets.CLUSER_RG}}
  27. REGISTRY_ENDPOINT: ${{ secrets.REGISTRY_ENDPOINT }}
  28. NAMESPACE: default
  29. jobs:
  30. build:
  31. runs-on: ubuntu-latest
  32. steps:
  33. - uses: actions/checkout@master
  34. # Connect to Azure Container registry (ACR)
  35. - uses: azure/docker-login@v1
  36. with:
  37. login-server: ${{ env.REGISTRY_NAME }}.azurecr.io
  38. username: ${{ secrets.REGISTRY_USERNAME }}
  39. password: ${{ secrets.REGISTRY_PASSWORD }}
  40. # Container build and push to a Azure Container registry (ACR)
  41. - run: |
  42. docker-compose build . -t ${{ secrets.REGISTRY_ENDPOINT }}:linux-dev
  43. docker-compose push ${{ secrets.REGISTRY_ENDPOINT }}:linux-dev
  44. # Set the target Azure Kubernetes Service (AKS) cluster.
  45. - uses: azure/aks-set-context@v1
  46. with:
  47. creds: '${{ secrets.AZURE_CREDENTIALS }}'
  48. cluster-name: ${{ env.CLUSTER_NAME }}
  49. resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }}
  50. # Create namespace if doesn't exist
  51. - run: |
  52. kubectl create namespace ${{ env.NAMESPACE }} --dry-run -o json | kubectl apply -f -
  53. # Create imagepullsecret for Azure Container registry (ACR)
  54. - uses: azure/k8s-create-secret@v1
  55. with:
  56. container-registry-url: ${{ env.REGISTRY_NAME }}.azurecr.io
  57. container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
  58. container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
  59. secret-name: ${{ env.REGISTRY_NAME }}-registry-connection
  60. namespace: ${{ env.NAMESPACE }}
  61. # Baking the helm chart to generate the manifests to deploy
  62. - uses: azure/k8s-bake@v1
  63. with:
  64. renderEngine: 'helm2'
  65. helmChart: './deploy/k8s/helm/'
  66. helm-version: 'latest'
  67. id: bake
  68. # Deploy app to AKS
  69. - uses: azure/k8s-deploy@v1
  70. with:
  71. manifests: ${{ steps.bake.outputs.manifestsBundle }}
  72. images: |
  73. ${{ secrets.REGISTRY_ENDPOINT }}:linux-dev
  74. imagepullsecrets: |
  75. ${{ env.REGISTRY_NAME }}-registry-connection
  76. namespace: ${{ env.NAMESPACE }}