update aks workflows to latest versions

This commit is contained in:
Oliver King
2022-10-20 15:06:21 -04:00
parent c820ab8a1d
commit a95c4f68c8
4 changed files with 197 additions and 369 deletions
+54 -97
View File
@@ -1,14 +1,16 @@
# This workflow will build and push an application to a Azure Kubernetes Service (AKS) cluster when you push your code # This workflow will build and push an application to a Azure Kubernetes Service (AKS) cluster when you push your code
# #
# This workflow assumes you have already created the target AKS cluster and have created an Azure Container Registry (ACR) # This workflow assumes you have already created the target AKS cluster and have created an Azure Container Registry (ACR)
# The ACR should be attached to the AKS cluster
# For instructions see: # For instructions see:
# - https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal # - https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal
# - https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal # - https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal
# - https://learn.microsoft.com/en-us/azure/aks/cluster-container-registry-integration?tabs=azure-cli#configure-acr-integration-for-existing-aks-clusters
# - https://github.com/Azure/aks-create-action # - https://github.com/Azure/aks-create-action
# #
# To configure this workflow: # To configure this workflow:
# #
# 1. Set the following secrets in your repository (instructions for getting these # 1. Set the following secrets in your repository (instructions for getting these
# https://docs.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux)): # https://docs.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux)):
# - AZURE_CLIENT_ID # - AZURE_CLIENT_ID
# - AZURE_TENANT_ID # - AZURE_TENANT_ID
@@ -34,7 +36,7 @@ name: Build and deploy an app to AKS with Helm
on: on:
push: push:
branches: [ $default-branch ] branches: [$default-branch]
workflow_dispatch: workflow_dispatch:
env: env:
@@ -42,7 +44,6 @@ env:
CONTAINER_NAME: "your-container-name" CONTAINER_NAME: "your-container-name"
RESOURCE_GROUP: "your-resource-group" RESOURCE_GROUP: "your-resource-group"
CLUSTER_NAME: "your-cluster-name" CLUSTER_NAME: "your-cluster-name"
IMAGE_PULL_SECRET_NAME: "your-image-pull-secret-name"
CHART_PATH: "your-chart-path" CHART_PATH: "your-chart-path"
CHART_OVERRIDE_PATH: "your-chart-override-path" CHART_OVERRIDE_PATH: "your-chart-override-path"
@@ -53,63 +54,21 @@ jobs:
id-token: write id-token: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# Checks out the repository this file is in # Checks out the repository this file is in
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Builds and pushes an image up to your Azure Container Registry
- name: Build and push image to ACR
run: |
az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
createSecret: # Logs in with your Azure credentials
permissions: - name: Azure login
contents: read uses: azure/[email protected]
id-token: write with:
runs-on: ubuntu-latest client-id: ${{ secrets.AZURE_CLIENT_ID }}
steps: tenant-id: ${{ secrets.AZURE_TENANT_ID }}
# Logs in with your Azure credentials subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file # Builds and pushes an image up to your Azure Container Registry
- name: Get K8s context - name: Build and push image to ACR
uses: azure/[email protected] run: |
with: az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
resource-group: ${{ env.RESOURCE_GROUP }}
cluster-name: ${{ env.CLUSTER_NAME }}
# Retrieves the credentials for pulling images from your Azure Container Registry
- name: Get ACR credentials
run: |
az acr update -n ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} --admin-enabled true
ACR_USERNAME=$(az acr credential show -g ${{ env.RESOURCE_GROUP }} -n ${{ env.AZURE_CONTAINER_REGISTRY }} --query username -o tsv)
ACR_PASSWORD=$(az acr credential show -g ${{ env.RESOURCE_GROUP }} -n ${{ env.AZURE_CONTAINER_REGISTRY }} --query passwords[0].value -o tsv)
echo "::add-mask::${ACR_USERNAME}"
echo "::set-output name=username::${ACR_USERNAME}"
echo "::add-mask::${ACR_PASSWORD}"
echo "::set-output name=password::${ACR_PASSWORD}"
id: get-acr-creds
# Creates a kubernetes secret on your Azure Kubernetes Service cluster that matches up to the credentials from the last step
- name: Create K8s secret for pulling image from ACR
uses: Azure/[email protected]
with:
container-registry-url: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io
container-registry-username: ${{ steps.get-acr-creds.outputs.username }}
container-registry-password: ${{ steps.get-acr-creds.outputs.password }}
secret-name: ${{ env.IMAGE_PULL_SECRET_NAME }}
deploy: deploy:
permissions: permissions:
@@ -117,45 +76,43 @@ jobs:
contents: read contents: read
id-token: write id-token: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [buildImage, createSecret] needs: [buildImage]
steps: steps:
# Checks out the repository this file is in # Checks out the repository this file is in
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file
- name: Get K8s context
uses: azure/[email protected]
with:
resource-group: ${{ env.RESOURCE_GROUP }}
cluster-name: ${{ env.CLUSTER_NAME }}
# Runs Helm to create manifest files # Logs in with your Azure credentials
- name: Bake deployment - name: Azure login
uses: azure/[email protected] uses: azure/[email protected]
with: with:
renderEngine: 'helm' client-id: ${{ secrets.AZURE_CLIENT_ID }}
helmChart: ${{ env.CHART_PATH }} tenant-id: ${{ secrets.AZURE_TENANT_ID }}
overrideFiles: ${{ env.CHART_OVERRIDE_PATH }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
overrides: |
replicas:2
helm-version: 'latest'
id: bake
# Deploys application based on manifest files from previous step # Retrieves your Azure Kubernetes Service cluster's kubeconfig file
- name: Deploy application - name: Get K8s context
uses: Azure/k8s-deploy@v3.1 uses: azure/aks-set-context@v3
with: with:
action: deploy resource-group: ${{ env.RESOURCE_GROUP }}
manifests: ${{ steps.bake.outputs.manifestsBundle }} cluster-name: ${{ env.CLUSTER_NAME }}
images: |
${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} # Runs Helm to create manifest files
imagepullsecrets: | - name: Bake deployment
${{ env.IMAGE_PULL_SECRET_NAME }} uses: azure/k8s-bake@v2
with:
renderEngine: "helm"
helmChart: ${{ env.CHART_PATH }}
overrideFiles: ${{ env.CHART_OVERRIDE_PATH }}
overrides: |
replicas:2
helm-version: "latest"
id: bake
# Deploys application based on manifest files from previous step
- name: Deploy application
uses: Azure/k8s-deploy@v4
with:
action: deploy
manifests: ${{ steps.bake.outputs.manifestsBundle }}
images: |
${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }}
@@ -1,14 +1,16 @@
# This workflow will build and push an application to a Azure Kubernetes Service (AKS) cluster when you push your code # This workflow will build and push an application to a Azure Kubernetes Service (AKS) cluster when you push your code
# #
# This workflow assumes you have already created the target AKS cluster and have created an Azure Container Registry (ACR) # This workflow assumes you have already created the target AKS cluster and have created an Azure Container Registry (ACR)
# The ACR should be attached to the AKS cluster
# For instructions see: # For instructions see:
# - https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal # - https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal
# - https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal # - https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal
# - https://learn.microsoft.com/en-us/azure/aks/cluster-container-registry-integration?tabs=azure-cli#configure-acr-integration-for-existing-aks-clusters
# - https://github.com/Azure/aks-create-action # - https://github.com/Azure/aks-create-action
# #
# To configure this workflow: # To configure this workflow:
# #
# 1. Set the following secrets in your repository (instructions for getting these # 1. Set the following secrets in your repository (instructions for getting these
# https://docs.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux): # https://docs.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux):
# - AZURE_CLIENT_ID # - AZURE_CLIENT_ID
# - AZURE_TENANT_ID # - AZURE_TENANT_ID
@@ -33,7 +35,7 @@ name: Build and deploy an app to AKS with Kompose
on: on:
push: push:
branches: [ $default-branch ] branches: [$default-branch]
workflow_dispatch: workflow_dispatch:
env: env:
@@ -41,7 +43,6 @@ env:
CONTAINER_NAME: "your-container-name" CONTAINER_NAME: "your-container-name"
RESOURCE_GROUP: "your-resource-group" RESOURCE_GROUP: "your-resource-group"
CLUSTER_NAME: "your-cluster-name" CLUSTER_NAME: "your-cluster-name"
IMAGE_PULL_SECRET_NAME: "your-image-pull-secret-name"
DOCKER_COMPOSE_FILE_PATH: "your-docker-compose-file-path" DOCKER_COMPOSE_FILE_PATH: "your-docker-compose-file-path"
jobs: jobs:
@@ -51,106 +52,62 @@ jobs:
id-token: write id-token: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# Checks out the repository this file is in # Checks out the repository this file is in
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Builds and pushes an image up to your Azure Container Registry
- name: Build and push image to ACR
run: |
az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
createSecret:
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file
- name: Get K8s context
uses: azure/[email protected]
with:
resource-group: ${{ env.RESOURCE_GROUP }}
cluster-name: ${{ env.CLUSTER_NAME }}
# Retrieves the credentials for pulling images from your Azure Container Registry # Logs in with your Azure credentials
- name: Get ACR credentials - name: Azure login
run: | uses: azure/[email protected]
az acr update -n ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} --admin-enabled true with:
ACR_USERNAME=$(az acr credential show -g ${{ env.RESOURCE_GROUP }} -n ${{ env.AZURE_CONTAINER_REGISTRY }} --query username -o tsv) client-id: ${{ secrets.AZURE_CLIENT_ID }}
ACR_PASSWORD=$(az acr credential show -g ${{ env.RESOURCE_GROUP }} -n ${{ env.AZURE_CONTAINER_REGISTRY }} --query passwords[0].value -o tsv) tenant-id: ${{ secrets.AZURE_TENANT_ID }}
echo "::add-mask::${ACR_USERNAME}" subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
echo "::set-output name=username::${ACR_USERNAME}"
echo "::add-mask::${ACR_PASSWORD}" # Builds and pushes an image up to your Azure Container Registry
echo "::set-output name=password::${ACR_PASSWORD}" - name: Build and push image to ACR
id: get-acr-creds run: |
az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
# Creates a kubernetes secret on your Azure Kubernetes Service cluster that matches up to the credentials from the last step
- name: Create K8s secret for pulling image from ACR
uses: Azure/[email protected]
with:
container-registry-url: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io
container-registry-username: ${{ steps.get-acr-creds.outputs.username }}
container-registry-password: ${{ steps.get-acr-creds.outputs.password }}
secret-name: ${{ env.IMAGE_PULL_SECRET_NAME }}
deploy: deploy:
permissions: permissions:
actions: read actions: read
contents: read contents: read
id-token: write id-token: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [buildImage, createSecret] needs: [buildImage]
steps: steps:
# Checks out the repository this file is in # Checks out the repository this file is in
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file # Logs in with your Azure credentials
- name: Get K8s context - name: Azure login
uses: azure/[email protected] uses: azure/[email protected]
with: with:
resource-group: ${{ env.RESOURCE_GROUP }} client-id: ${{ secrets.AZURE_CLIENT_ID }}
cluster-name: ${{ env.CLUSTER_NAME }} tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Runs Kompose to create manifest files # Retrieves your Azure Kubernetes Service cluster's kubeconfig file
- name: Bake deployment - name: Get K8s context
uses: azure/[email protected] uses: azure/aks-set-context@v3
with: with:
renderEngine: 'kompose' resource-group: ${{ env.RESOURCE_GROUP }}
dockerComposeFile: ${{ env.DOCKER_COMPOSE_FILE_PATH }} cluster-name: ${{ env.CLUSTER_NAME }}
kompose-version: 'latest'
id: bake
# Deploys application based on manifest files from previous step # Runs Kompose to create manifest files
- name: Deploy application - name: Bake deployment
uses: Azure/k8s-[email protected] uses: azure/k8s-bake@v2
with: with:
action: deploy renderEngine: "kompose"
manifests: ${{ steps.bake.outputs.manifestsBundle }} dockerComposeFile: ${{ env.DOCKER_COMPOSE_FILE_PATH }}
images: | kompose-version: "latest"
${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} id: bake
imagepullsecrets: |
${{ env.IMAGE_PULL_SECRET_NAME }} # Deploys application based on manifest files from previous step
- name: Deploy application
uses: Azure/k8s-deploy@v4
with:
action: deploy
manifests: ${{ steps.bake.outputs.manifestsBundle }}
images: |
${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }}
@@ -1,14 +1,16 @@
# This workflow will build and push an application to a Azure Kubernetes Service (AKS) cluster when you push your code # This workflow will build and push an application to a Azure Kubernetes Service (AKS) cluster when you push your code
# #
# This workflow assumes you have already created the target AKS cluster and have created an Azure Container Registry (ACR) # This workflow assumes you have already created the target AKS cluster and have created an Azure Container Registry (ACR)
# The ACR should be attached to the AKS cluster
# For instructions see: # For instructions see:
# - https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal # - https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal
# - https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal # - https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal
# - https://learn.microsoft.com/en-us/azure/aks/cluster-container-registry-integration?tabs=azure-cli#configure-acr-integration-for-existing-aks-clusters
# - https://github.com/Azure/aks-create-action # - https://github.com/Azure/aks-create-action
# #
# To configure this workflow: # To configure this workflow:
# #
# 1. Set the following secrets in your repository (instructions for getting these # 1. Set the following secrets in your repository (instructions for getting these
# https://docs.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux): # https://docs.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux):
# - AZURE_CLIENT_ID # - AZURE_CLIENT_ID
# - AZURE_TENANT_ID # - AZURE_TENANT_ID
@@ -33,7 +35,7 @@ name: Build and deploy an app to AKS with Kustomize
on: on:
push: push:
branches: [ $default-branch ] branches: [$default-branch]
workflow_dispatch: workflow_dispatch:
env: env:
@@ -41,7 +43,6 @@ env:
CONTAINER_NAME: "your-container-name" CONTAINER_NAME: "your-container-name"
RESOURCE_GROUP: "your-resource-group" RESOURCE_GROUP: "your-resource-group"
CLUSTER_NAME: "your-cluster-name" CLUSTER_NAME: "your-cluster-name"
IMAGE_PULL_SECRET_NAME: "your-image-pull-secret-name"
KUSTOMIZE_PATH: "your-kustomize-path" KUSTOMIZE_PATH: "your-kustomize-path"
jobs: jobs:
@@ -51,106 +52,62 @@ jobs:
id-token: write id-token: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# Checks out the repository this file is in # Checks out the repository this file is in
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# Logs in with your Azure credentials # Logs in with your Azure credentials
- name: Azure login - name: Azure login
uses: azure/[email protected].3 uses: azure/[email protected].6
with: with:
client-id: ${{ secrets.AZURE_CLIENT_ID }} client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Builds and pushes an image up to your Azure Container Registry
- name: Build and push image to ACR
run: |
az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
createSecret:
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file # Builds and pushes an image up to your Azure Container Registry
- name: Get K8s context - name: Build and push image to ACR
uses: azure/[email protected] run: |
with: az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
resource-group: ${{ env.RESOURCE_GROUP }}
cluster-name: ${{ env.CLUSTER_NAME }}
# Retrieves the credentials for pulling images from your Azure Container Registry
- name: Get ACR credentials
run: |
az acr update -n ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} --admin-enabled true
ACR_USERNAME=$(az acr credential show -g ${{ env.RESOURCE_GROUP }} -n ${{ env.AZURE_CONTAINER_REGISTRY }} --query username -o tsv)
ACR_PASSWORD=$(az acr credential show -g ${{ env.RESOURCE_GROUP }} -n ${{ env.AZURE_CONTAINER_REGISTRY }} --query passwords[0].value -o tsv)
echo "::add-mask::${ACR_USERNAME}"
echo "::set-output name=username::${ACR_USERNAME}"
echo "::add-mask::${ACR_PASSWORD}"
echo "::set-output name=password::${ACR_PASSWORD}"
id: get-acr-creds
# Creates a kubernetes secret on your Azure Kubernetes Service cluster that matches up to the credentials from the last step
- name: Create K8s secret for pulling image from ACR
uses: Azure/[email protected]
with:
container-registry-url: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io
container-registry-username: ${{ steps.get-acr-creds.outputs.username }}
container-registry-password: ${{ steps.get-acr-creds.outputs.password }}
secret-name: ${{ env.IMAGE_PULL_SECRET_NAME }}
deploy: deploy:
permissions: permissions:
actions: read actions: read
contents: read contents: read
id-token: write id-token: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [buildImage, createSecret] needs: [buildImage]
steps: steps:
# Checks out the repository this file is in # Checks out the repository this file is in
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# Logs in with your Azure credentials # Logs in with your Azure credentials
- name: Azure login - name: Azure login
uses: azure/[email protected].3 uses: azure/[email protected].6
with: with:
client-id: ${{ secrets.AZURE_CLIENT_ID }} client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file # Retrieves your Azure Kubernetes Service cluster's kubeconfig file
- name: Get K8s context - name: Get K8s context
uses: azure/aks-set-context@v2.0 uses: azure/aks-set-context@v3
with: with:
resource-group: ${{ env.RESOURCE_GROUP }} resource-group: ${{ env.RESOURCE_GROUP }}
cluster-name: ${{ env.CLUSTER_NAME }} cluster-name: ${{ env.CLUSTER_NAME }}
# Runs Kustomize to create manifest files # Runs Kustomize to create manifest files
- name: Bake deployment - name: Bake deployment
uses: azure/k8s-bake@v2.1 uses: azure/k8s-bake@v2
with: with:
renderEngine: 'kustomize' renderEngine: "kustomize"
kustomizationPath: ${{ env.KUSTOMIZE_PATH }} kustomizationPath: ${{ env.KUSTOMIZE_PATH }}
kubectl-version: latest kubectl-version: latest
id: bake id: bake
# Deploys application based on manifest files from previous step # Deploys application based on manifest files from previous step
- name: Deploy application - name: Deploy application
uses: Azure/k8s-deploy@v3.1 uses: Azure/k8s-deploy@v4
with: with:
action: deploy action: deploy
manifests: ${{ steps.bake.outputs.manifestsBundle }} manifests: ${{ steps.bake.outputs.manifestsBundle }}
images: | images: |
${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }}
imagepullsecrets: |
${{ env.IMAGE_PULL_SECRET_NAME }}
+43 -86
View File
@@ -1,9 +1,11 @@
# This workflow will build and push an application to a Azure Kubernetes Service (AKS) cluster when you push your code # This workflow will build and push an application to a Azure Kubernetes Service (AKS) cluster when you push your code
# #
# This workflow assumes you have already created the target AKS cluster and have created an Azure Container Registry (ACR) # This workflow assumes you have already created the target AKS cluster and have created an Azure Container Registry (ACR)
# The ACR should be attached to the AKS cluster
# For instructions see: # For instructions see:
# - https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal # - https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal
# - https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal # - https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal
# - https://learn.microsoft.com/en-us/azure/aks/cluster-container-registry-integration?tabs=azure-cli#configure-acr-integration-for-existing-aks-clusters
# - https://github.com/Azure/aks-create-action # - https://github.com/Azure/aks-create-action
# #
# To configure this workflow: # To configure this workflow:
@@ -29,7 +31,7 @@ name: Build and deploy an app to AKS
on: on:
push: push:
branches: [ $default-branch ] branches: [$default-branch]
workflow_dispatch: workflow_dispatch:
env: env:
@@ -37,8 +39,7 @@ env:
CONTAINER_NAME: "your-container-name" CONTAINER_NAME: "your-container-name"
RESOURCE_GROUP: "your-resource-group" RESOURCE_GROUP: "your-resource-group"
CLUSTER_NAME: "your-cluster-name" CLUSTER_NAME: "your-cluster-name"
IMAGE_PULL_SECRET_NAME: "your-image-pull-secret-name" DEPLOYMENT_MANIFEST_PATH: "your-deployment-manifest-path"
DEPLOYMENT_MANIFEST_PATH: 'your-deployment-manifest-path'
jobs: jobs:
buildImage: buildImage:
@@ -47,63 +48,21 @@ jobs:
id-token: write id-token: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# Checks out the repository this file is in # Checks out the repository this file is in
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Builds and pushes an image up to your Azure Container Registry
- name: Build and push image to ACR
run: |
az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
createSecret: # Logs in with your Azure credentials
permissions: - name: Azure login
contents: read uses: azure/[email protected]
id-token: write with:
runs-on: ubuntu-latest client-id: ${{ secrets.AZURE_CLIENT_ID }}
steps: tenant-id: ${{ secrets.AZURE_TENANT_ID }}
# Logs in with your Azure credentials subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file
- name: Get K8s context
uses: azure/[email protected]
with:
resource-group: ${{ env.RESOURCE_GROUP }}
cluster-name: ${{ env.CLUSTER_NAME }}
# Retrieves the credentials for pulling images from your Azure Container Registry # Builds and pushes an image up to your Azure Container Registry
- name: Get ACR credentials - name: Build and push image to ACR
run: | run: |
az acr update -n ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} --admin-enabled true az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
ACR_USERNAME=$(az acr credential show -g ${{ env.RESOURCE_GROUP }} -n ${{ env.AZURE_CONTAINER_REGISTRY }} --query username -o tsv)
ACR_PASSWORD=$(az acr credential show -g ${{ env.RESOURCE_GROUP }} -n ${{ env.AZURE_CONTAINER_REGISTRY }} --query passwords[0].value -o tsv)
echo "::add-mask::${ACR_USERNAME}"
echo "::set-output name=username::${ACR_USERNAME}"
echo "::add-mask::${ACR_PASSWORD}"
echo "::set-output name=password::${ACR_PASSWORD}"
id: get-acr-creds
# Creates a kubernetes secret on your Azure Kubernetes Service cluster that matches up to the credentials from the last step
- name: Create K8s secret for pulling image from ACR
uses: Azure/[email protected]
with:
container-registry-url: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io
container-registry-username: ${{ steps.get-acr-creds.outputs.username }}
container-registry-password: ${{ steps.get-acr-creds.outputs.password }}
secret-name: ${{ env.IMAGE_PULL_SECRET_NAME }}
deploy: deploy:
permissions: permissions:
@@ -111,33 +70,31 @@ jobs:
contents: read contents: read
id-token: write id-token: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [buildImage, createSecret] needs: [buildImage]
steps: steps:
# Checks out the repository this file is in # Checks out the repository this file is in
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file
- name: Get K8s context
uses: azure/[email protected]
with:
resource-group: ${{ env.RESOURCE_GROUP }}
cluster-name: ${{ env.CLUSTER_NAME }}
# Deploys application based on given manifest file # Logs in with your Azure credentials
- name: Deploys application - name: Azure login
uses: Azure/[email protected] uses: azure/[email protected]
with: with:
action: deploy client-id: ${{ secrets.AZURE_CLIENT_ID }}
manifests: ${{ env.DEPLOYMENT_MANIFEST_PATH }} tenant-id: ${{ secrets.AZURE_TENANT_ID }}
images: | subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }}
imagepullsecrets: | # Retrieves your Azure Kubernetes Service cluster's kubeconfig file
${{ env.IMAGE_PULL_SECRET_NAME }} - name: Get K8s context
uses: azure/aks-set-context@v3
with:
resource-group: ${{ env.RESOURCE_GROUP }}
cluster-name: ${{ env.CLUSTER_NAME }}
# Deploys application based on given manifest file
- name: Deploys application
uses: Azure/k8s-deploy@v4
with:
action: deploy
manifests: ${{ env.DEPLOYMENT_MANIFEST_PATH }}
images: |
${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }}