Skip to content

Commit 0402605

Browse files
authored
Added templates for azure pipelines (#329)
1 parent 6e0b1ad commit 0402605

File tree

4 files changed

+188
-0
lines changed

4 files changed

+188
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Azure Kubernetes Service (AKS) pipeline with Kustomize
2+
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service cluster
3+
4+
variables:
5+
armServiceConnection: {{ARMSERVICECONNECTION}}
6+
azureContainerRegistry: {{AZURECONTAINERREGISTRY}}
7+
containerName: {{CONTAINERNAME}}
8+
acrRg: {{CLUSTERRESOURCEGROUP}}
9+
clusterRg: {{ACRRESOURCEGROUP}}
10+
clusterName: {{CLUSTERNAME}}
11+
kustomizePath: {{KUSTOMIZEPATH}}
12+
namespace: {{NAMESPACE}}
13+
tag: "$(Build.BuildId)"
14+
vmImageName: "ubuntu-latest"
15+
16+
trigger:
17+
- {{BRANCHNAME}}
18+
19+
name: {{PIPELINENAME}}
20+
21+
stages:
22+
- stage: BuildAndPush
23+
displayName: Build stage
24+
jobs:
25+
- job: BuildAndPush
26+
displayName: Build and push image
27+
pool:
28+
vmImage: $(vmImageName)
29+
steps:
30+
- task: AzureCLI@2
31+
displayName: Build and push image to Azure Container Registry
32+
inputs:
33+
azureSubscription: $(armServiceConnection)
34+
scriptType: "bash"
35+
scriptLocation: "inlineScript"
36+
inlineScript: |
37+
az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 .
38+
arguments: "$(azureContainerRegistry) $(containerName) $(tag) $(acrRg)"
39+
40+
- stage: Deploy
41+
displayName: Deploy stage
42+
dependsOn: BuildAndPush
43+
jobs:
44+
- job: Deploy
45+
displayName: Deploy to AKS using Kustomize
46+
pool:
47+
vmImage: $(vmImageName)
48+
steps:
49+
- task: KubernetesManifest@1
50+
displayName: Bake Kustomize manifests
51+
inputs:
52+
action: 'bake'
53+
kustomizationPath: $(kustomizePath)
54+
renderType: 'kustomize'
55+
name: 'bake'
56+
57+
- task: KubernetesManifest@1
58+
displayName: Deploy baked manifests to Kubernetes cluster
59+
inputs:
60+
action: 'deploy'
61+
connectionType: 'azureResourceManager'
62+
azureSubscriptionConnection: $(armServiceConnection)
63+
azureResourceGroup: $(clusterRg)
64+
kubernetesCluster: $(clusterName)
65+
namespace: $(namespace)
66+
manifests: $(bake.manifestsBundle)
67+
containers: |
68+
$(azureContainerRegistry).azurecr.io/$(containerName):$(tag)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
variables:
2+
- name: "PIPELINENAME"
3+
default:
4+
value: "Build and deploy an app to AKS"
5+
description: "the name of the azure pipeline"
6+
- name: "BRANCHNAME"
7+
default:
8+
value: "main"
9+
description: "the branch to trigger the pipeline"
10+
- name: "ARMSERVICECONNECTION"
11+
description: "the name of the Azure Resource Manager service connection"
12+
- name: "AZURECONTAINERREGISTRY"
13+
description: "the name of the Azure Container Registry"
14+
- name: "CONTAINERNAME"
15+
description: "the container image name"
16+
- name: "CLUSTERRESOURCEGROUP"
17+
description: "the AKS cluster resource group"
18+
- name: "ACRRESOURCEGROUP"
19+
description: "the ACR resource group"
20+
- name: "CLUSTERNAME"
21+
description: "the AKS cluster name"
22+
- name: "KUSTOMIZEPATH"
23+
default:
24+
disablePrompt: true
25+
value: "./overlays/production" # keeping this as default since draft generates the manifests in the overlays/production directory
26+
description: "the path to the Kustomize directory"
27+
- name: "NAMESPACE"
28+
default:
29+
value: "default"
30+
description: "the Kubernetes namespace"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Azure Kubernetes Service pipeline
2+
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service cluster
3+
4+
variables:
5+
armServiceConnection: {{ARMSERVICECONNECTION}}
6+
azureContainerRegistry: {{AZURECONTAINERREGISTRY}}
7+
containerName: {{CONTAINERNAME}}
8+
clusterRg: {{CLUSTERRESOURCEGROUP}}
9+
acrRg: {{ACRRESOURCEGROUP}}
10+
clusterName: {{CLUSTERNAME}}
11+
manifestPath: {{MANIFESTPATH}}
12+
namespace: {{NAMESPACE}}
13+
tag: "$(Build.BuildId)"
14+
vmImageName: "ubuntu-latest"
15+
16+
name: {{PIPELINENAME}}
17+
18+
trigger:
19+
- {{BRANCHNAME}}
20+
21+
stages:
22+
- stage: BuildAndPush
23+
displayName: Build stage
24+
jobs:
25+
- job: BuildAndPush
26+
displayName: Build and push image
27+
pool:
28+
vmImage: $(vmImageName)
29+
steps:
30+
- task: AzureCLI@2
31+
displayName: Build and push image to Azure Container Registry
32+
inputs:
33+
azureSubscription: $(armServiceConnection)
34+
scriptType: "bash"
35+
scriptLocation: "inlineScript"
36+
inlineScript: |
37+
az acr build --image $1.azurecr.io/$2:$3 --registry $1 -g $4 .
38+
arguments: "$(azureContainerRegistry) $(containerName) $(tag) $(acrRg)"
39+
40+
- stage: Deploy
41+
displayName: Deploy stage
42+
dependsOn: BuildAndPush
43+
jobs:
44+
- job: Deploy
45+
displayName: Deploy to AKS
46+
pool:
47+
vmImage: $(vmImageName)
48+
steps:
49+
- task: KubernetesManifest@1
50+
displayName: Deploy to Kubernetes cluster
51+
inputs:
52+
action: "deploy"
53+
connectionType: "azureResourceManager"
54+
azureSubscriptionConnection: $(armServiceConnection)
55+
azureResourceGroup: $(clusterRg)
56+
kubernetesCluster: $(clusterName)
57+
manifests: $(manifestPath)
58+
namespace: $(namespace)
59+
containers: |
60+
$(azureContainerRegistry).azurecr.io/$(containerName):$(tag)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
variables:
2+
- name: "PIPELINENAME"
3+
default:
4+
value: "Build and deploy an app to AKS"
5+
description: "the name of the azure pipeline"
6+
- name: "BRANCHNAME"
7+
default:
8+
value: "main"
9+
description: "the branch to trigger the pipeline"
10+
- name: "ARMSERVICECONNECTION"
11+
description: "the name of the Azure Resource Manager service connection"
12+
- name: "AZURECONTAINERREGISTRY"
13+
description: "the name of the Azure Container Registry"
14+
- name: "CONTAINERNAME"
15+
description: "the container image name"
16+
- name: "CLUSTERRESOURCEGROUP"
17+
description: "the AKS cluster resource group"
18+
- name: "ACRRESOURCEGROUP"
19+
description: "the ACR resource group"
20+
- name: "CLUSTERNAME"
21+
description: "the AKS cluster name"
22+
- name: "MANIFESTPATH"
23+
default:
24+
disablePrompt: true
25+
value: "./manifests"
26+
description: "the path to the Kubernetes deployment manifest"
27+
- name: "NAMESPACE"
28+
default:
29+
value: "default"
30+
description: "the Kubernetes namespace"

0 commit comments

Comments
 (0)