-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
153 lines (142 loc) · 6.16 KB
/
azure-pipelines.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
150
151
152
153
# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger: none
resources:
- repo: self
parameters:
- name: printFrontendVersion
displayName: Print Frontend version to deploy
type: string
default: latest
variables:
# Container registry service connection established during pipeline creation
- name: imageRepository
value: 'fdpg-pdf'
- name: containerRegistry
value: 'tmffdpgregistry.azurecr.io'
- name: registryServiceConnectionName
value: 'tmffdpgregistry_service_connection'
- name: dockerfilePath
value: '$(Build.SourcesDirectory)/Dockerfile'
- name: azureSubscription
value: 'fdpg_deployment_service_connection'
- name: azureResourceGroup
value: tmf-fdpg-shared
- name: tag
value: '$(Build.BuildId)'
- name: isMain
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')]
- name: isDev
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/dev')]
- name: pipeDate
value: $[format('{0:yyyyMMdd}', pipeline.startTime)]
- name: pipeTime
value: $[format('{0:HHmmss}', pipeline.startTime)]
- name: buildNumberOfDate
value: $[counter(format('{0}_{1:yyyyMMdd}', variables['Build.SourceBranch'], pipeline.startTime), 1)]
# Agent VM image name
- name: vmImageName
value: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- script: |
npmVersionString=$(node -p "require('./package.json').version")
echo "##vso[task.setvariable variable=softwareVersion;isOutput=true]$npmVersionString"
if [ $(isDev) = True ]; then
echo "##vso[task.setvariable variable=tag;isOutput=true]latest"
echo "##vso[build.updatebuildnumber]latest_${npmVersionString}_$(pipeDate)_$(buildNumberOfDate)"
elif [ $(isMain) = True ]; then
echo "##vso[task.setvariable variable=tag;isOutput=true]${npmVersionString}_$(pipeDate)_$(buildNumberOfDate)"
echo "##vso[build.updatebuildnumber]${npmVersionString}_$(pipeDate)_$(buildNumberOfDate)"
else
echo "##vso[task.setvariable variable=tag;isOutput=true]test-latest"
echo "##vso[build.updatebuildnumber]test-latest_${npmVersionString}_$(pipeDate)_$(buildNumberOfDate)"
fi
name: dockerTag
- task: Docker@2
displayName: Build container
inputs:
command: 'build'
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(registryServiceConnectionName)
tags: |
$(dockerTag.tag)
arguments: >-
--build-arg SOFTWARE_VERSION=$(dockerTag.softwareVersion)
--build-arg BUILD_DATE=$(pipeDate)
--build-arg BUILD_TIME=$(pipeTime)
--build-arg BUILD_NO_OF_DATE=$(buildNumberOfDate)
--build-arg SOURCE_BRANCH=$(Build.SourceBranch)
- task: Docker@2
displayName: Push container to registry
condition: or(eq(variables.isDev, true), eq(variables.isMain, true))
inputs:
command: 'push'
repository: $(imageRepository)
containerRegistry: $(registryServiceConnectionName)
addPipelineData: true
tags: |
$(dockerTag.tag)
- stage: Helm_Deployment_Dev
displayName: 'Push Helm chart to registry and deploy to Dev'
condition: or(eq(variables.isDev, true), eq(variables.isMain, true))
jobs:
- job: helm_deploy
displayName: 'Push the helm chart to registry and deploy to dev via helm upgrade'
steps:
- task: AzureKeyVault@2
inputs:
azureSubscription: $(azureSubscription)
KeyVaultName: 'tmffdpg-keyvault'
SecretsFilter: '*'
RunAsPreJob: false
- task: HelmInstaller@1
displayName: Helm installer
inputs:
helmVersionToInstall: 3.7.1
- task: AzureCLI@2
displayName: 'Push the Helm chart to ACR'
inputs:
scriptType: bash
scriptLocation: inlineScript
azureSubscription: $(azureSubscription)
inlineScript: |
export HELM_EXPERIMENTAL_OCI=1
export HELM_VERSION=$(grep -A3 'version:' deploy/helm/Chart.yaml | awk '{ print $2}')
export ACR_USERNAME="00000000-0000-0000-0000-000000000000"
export ACR_PASSWORD=$(az acr login --name tmffdpgregistry --expose-token --output tsv --query accessToken)
helm registry login tmffdpgregistry.azurecr.io --username $ACR_USERNAME --password $ACR_PASSWORD
helm package ./deploy/helm
helm push fdpg-pdf-$HELM_VERSION.tgz oci://tmffdpgregistry.azurecr.io/helm
- task: HelmDeploy@0
condition: and(succeeded(), eq(variables.isDev, true))
displayName: 'helm upgrade'
inputs:
azureSubscription: $(azureSubscription)
azureResourceGroup: $(azureResourceGroup)
kubernetesCluster: $(kubernetesCluster)
useClusterAdmin: true
namespace: $(devClusterNamespaceName)
command: upgrade
argument: --install
chartType: FilePath
chartPath: 'deploy/helm'
releaseName: 'fdpg-pdf'
waitForExecution: false
overrideValues: |
initContainer.tag=${{parameters.printFrontendVersion}}
appConfig.environment.env=dev
appConfig.environment.applicationInsightsConnectionString=$(devFdpgApplicationInsightsConnectionString)
appConfig.environment.releaseDate=$(pipeDate)
appConfig.environment.releaseTime=$(pipeTime)
appConfig.environment.releaseNoOfDate=$(buildNumberOfDate)
appConfig.environment.softwareVersion=$(Build.BuildNumber)