forked from rakol-ms/nodejs-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webappcontainer1.yml
149 lines (125 loc) · 5.08 KB
/
webappcontainer1.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Docker image, Azure Container Registry, and Azure Kubernetes Service
# Build a Docker image, push it to an Azure Container Registry, and deploy it to Azure Kubernetes Service.
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
# ========================================================================
# Mandatory variables
# ========================================================================
# Update Azure.ResourceGroupName value with Azure resource group name.
Azure.ResourceGroupName: 'gopinathchnodejssample'
# Update Azure.ServiceConnectionId value with AzureRm service endpoint.
Azure.ServiceConnectionId: 'bc1b1581-3bdd-4459-8de8-a9b7aaad285a'
# Update Azure.Location value with Azure Location.
Azure.Location: 'eastus'
# Update ACR.Name value with ACR name. Please note ACR names should be all lower-case and alphanumeric only.
ACR.Name: 'gopinathchnodejssample4152'
# Update AKS.ClusterName value Azure kubernetes cluster name.
AKS.ClusterName: 'gopinathchnodejssample'
# Docker Container port
Container.Port: 5000
# ========================================================================
# Optional variables
# ========================================================================
ACR.RepositoryName: '$(ACR.Name)'
ACR.ImageName: '$(ACR.Name):$(Build.BuildId)'
ACR.FullName: '$(ACR.Name).azurecr.io'
ACR.Sku: 'Standard'
AKS.KubeDeploymentYaml: '$(System.DefaultWorkingDirectory)/KubeDeployment.yml' # Update AKS.KubeDeploymentYaml if you want to use deployment file from repo instead of generated file.
AKS.DeploymentPort: '$(Container.Port)'
Azure.CreateResources: 'true' # Update Azure.CreateResources to false if you have already created resources like resource group, azure container registry and azure kubernetes cluster.
System.Debug: 'false'
jobs:
- job: CreateResources
displayName: Create resources
condition: and(succeeded(), eq(variables['Azure.CreateResources'], 'true'))
pool:
vmImage: 'Ubuntu-16.04'
steps:
- task: AzureResourceGroupDeployment@2
displayName: 'Azure Deployment:Create ACR and AKS'
inputs:
azureSubscription: '$(Azure.ServiceConnectionId)'
resourceGroupName: '$(Azure.ResourceGroupName)'
location: '$(Azure.Location)'
templateLocation: 'URL of the file'
addSpnToEnvironment: true
csmFileLink: 'https://raw.githubusercontent.com/Microsoft/azure-pipelines-yaml/master/templates/resources/arm/aks.json'
overrideParameters: '-registryName "$(ACR.Name)" -registryLocation "$(Azure.Location)" -servicePrincipalId $servicePrincipalId -servicePrincipalKey $servicePrincipalKey -clusterName "$(AKS.ClusterName)" -clusterLocation "$(Azure.Location)"'
- job: BuildImage
displayName: Build
dependsOn: CreateResources
condition: or(succeeded(), ne(variables['Azure.CreateResources'], 'true'))
pool:
vmImage: 'Ubuntu-16.04'
steps:
- task: Docker@1
displayName: 'Build an image'
inputs:
azureSubscriptionEndpoint: '$(Azure.ServiceConnectionId)'
azureContainerRegistry: '$(ACR.FullName)'
imageName: '$(ACR.ImageName)'
command: build
dockerFile: '**/Dockerfile'
- task: Docker@1
displayName: 'Push an image'
inputs:
azureSubscriptionEndpoint: '$(Azure.ServiceConnectionId)'
azureContainerRegistry: '$(ACR.FullName)'
imageName: '$(ACR.ImageName)'
command: push
- job: DeployApp
displayName: Deploy
dependsOn: BuildImage
condition: succeeded()
pool:
vmImage: 'Ubuntu-16.04'
steps:
- bash: |
if [ -f $(AKS.KubeDeploymentYaml) ]; then
echo "##vso[task.setvariable variable=AKS.KubeDeploymentYamlExists;]true"
else
echo "##vso[task.setvariable variable=AKS.KubeDeploymentYamlExists;]false"
fi
displayName: 'Check kubernetes deployment yaml exists'
- bash: |
echo "apiVersion : apps/v1beta1
kind: Deployment
metadata:
name: $(ACR.RepositoryName)
spec:
replicas: 1
template:
metadata:
labels:
app: $(ACR.RepositoryName)
spec:
containers:
- name: $(ACR.RepositoryName)
image: $(ACR.FullName)/$(ACR.ImageName)
ports:
- containerPort: $(AKS.DeploymentPort)
---
apiVersion: v1
kind: Service
metadata:
name: $(ACR.RepositoryName)
spec:
type: LoadBalancer
ports:
- port: $(AKS.DeploymentPort)
selector:
app: $(ACR.RepositoryName)" > $(AKS.KubeDeploymentYaml)
displayName: 'Generate kubernetes deployment yaml'
condition: and(succeeded(), eq(variables['AKS.KubeDeploymentYamlExists'], 'False'))
- task: Kubernetes@1
displayName: 'kubectl apply'
inputs:
azureSubscriptionEndpoint: '$(Azure.ServiceConnectionId)'
azureResourceGroup: '$(Azure.ResourceGroupName)'
kubernetesCluster: '$(AKS.ClusterName)'
arguments: '-f $(AKS.KubeDeploymentYaml)'
command: 'apply'