-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-test-web-app.yml
135 lines (122 loc) · 4.34 KB
/
ci-test-web-app.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
trigger:
batch: true
branches:
include:
- '*'
paths:
include:
- src
pr: none
pool: Terraform
variables:
- group: global-variables
- name: azureSubscription
value: AzureSubscription
- name: sourcePath
value: source
- name: helmChartPath
value: chart
- name: helmVersion
value: latest
- name: kubectlVersion
value: latest
- name: chartName
value: syntheticapi
- name: HELM_EXPERIMENTAL_OCI
value: 1
stages :
- stage: create_container_image
displayName: Create Image
jobs:
- job: create_container_image
displayName: 'Build Image'
steps:
- bash: |
# Set ACR name lowercase
acrName=$(echo $(registryServerName) | awk '{print tolower($0)}')
echo "##vso[task.setvariable variable=acrName;]$acrName"
failOnStderr: true
displayName: 'ACR Name ToLower'
- task: HelmInstaller@1
displayName: 'Install Helm'
enabled: false
inputs:
helmVersionToInstall: $(helmVersion)
- task: KubectlInstaller@0
displayName: 'Install Kubectl'
enabled: false
inputs:
kubectlVersion: $(kubectlVersion)
- task: AzureCLI@2
displayName: 'Container Image Build and Push'
condition: succeeded()
inputs:
scriptType: bash
scriptLocation: inlineScript
azureSubscription: $(azureSubscription)
addSpnToEnvironment: true
inlineScript: |
# Login to ACR
az acr login --name $(acrName)
# Retrieve ACR login server. Each container image needs to be tagged with the loginServer name of the registry.
echo "Logging to [$(acrName)] Azure Container Registry..."
loginServer=$(az acr show --name $(acrName) --query loginServer --output tsv)
cd $(sourcePath)
echo "Building [$loginServer/$(imageName):$(imageTag)] container image..."
docker build -t $loginServer/$(imageName):$(imageTag) .
# Push local container image to ACR
docker push $loginServer/$(imageName):$(imageTag)
- bash: |
# Run helm package
helm package \
--app-version $(imageTag) \
$(helmChartPath)
failOnStderr: true
displayName: 'Helm Package'
- bash: |
# Run helm lint
helm lint $(helmChartPath)
failOnStderr: false
displayName: 'Helm Lint'
- task: AzureCLI@2
displayName: 'Helm Chart Push'
condition: succeeded()
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
inputs:
scriptType: bash
scriptLocation: inlineScript
azureSubscription: $(azureSubscription)
addSpnToEnvironment: true
inlineScript: |
# Login to ACR
az acr login --name $(acrName)
# Retrieve ACR login server. Each container image needs to be tagged with the loginServer name of the registry.
echo "Logging to [$(acrName)] Azure Container Registry..."
loginServer=$(az acr show --name $(acrName) --query loginServer --output tsv)
# Login to ACR via Helm
token=$(az acr login --name $(acrName) --expose-token --output tsv --query accessToken)
echo $token | helm registry login $loginServer \
--username 00000000-0000-0000-0000-000000000000 \
--password-stdin
# Package helm chart
echo "Creating helm package..."
packageFile=`helm package $(helmChartPath) | awk -F ': ' '{print $2}'`
if [[ -n $packageFile ]]; then
echo "[$packageFile] helm package successfully created"
else
echo "Failed to create [$packageFile] helm package"
exit -1-
fi
# Get helm chart version
echo "Retrieving helm chart version..."
chartVersion=$(helm show chart $packageFile | grep version | awk -F ': ' '{print $2}')
if [[ -n $chartVersion ]]; then
echo "[$chartVersion] helm chart version successfully retrieved"
else
echo "Failed to retrieve [$chartVersion] helm chart version"
exit -1
fi
# Push helm chart to ACR
echo "Pushing [$packageFile] to oci://$loginServer/helm..."
helm push $packageFile oci://$loginServer/helm