-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathazure-pipelines.yml
166 lines (134 loc) · 3.79 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
154
155
156
157
158
159
160
161
162
163
164
165
166
trigger:
tags:
include:
- v*
branches:
include:
- "*"
paths:
exclude:
- README.md
- CHANGELOG.md
- LICENSE
pr:
autoCancel: true
branches:
include:
- "*"
paths:
exclude:
- README.md
- CHANGELOG.md
- LICENSE
variables:
jobuuid: $(Build.BuildId)$(Agent.Id)
GOROOT: '/usr/local/go1.19'
GOPATH: '/tmp/go'
GOBIN: '$(GOPATH)/bin'
repository: 'focal-freedom-236620/operator'
USE_GKE_GCLOUD_AUTH_PLUGIN: 'True'
build: $(Build.BuildId)
ref: $(Build.SourceBranch)
branch: $(Build.SourceBranchName)
version:
jobs:
- job: Operator
pool:
vmImage: 'Ubuntu-20.04'
steps:
- script: |
echo 'test1'
set -e
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
displayName: 'Set up the Go workspace'
- task: KubectlInstaller@0
displayName: Kubectl installer
inputs:
kubectlVersion: 1.25.2
- script: |
set -e
sudo make kustomize
displayName: 'Install kustomize'
- task: DownloadSecureFile@1
displayName: 'Download secure file'
inputs:
secureFile: 'azure-gcp.json'
- bash: |
set -e
keyFilePath="$(Agent.TempDirectory)/azure-gcp.json"
# Install gcloud-auth-plugin
echo "deb https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl -f https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install -y google-cloud-sdk-gke-gcloud-auth-plugin
gcloud components list
gcloud --quiet auth activate-service-account --key-file="${keyFilePath}"
gcloud --quiet config set project $(gcp.project.name)
gcloud --quiet container clusters get-credentials $(gcp.cluster.name) --region $(gcp.cluster.region)
displayName: 'Connect to cluster'
- task: GoTool@0
inputs:
version: '1.19'
goPath: $(GOPATH)
goBin: $(GOBIN)
displayName: 'Install Golang'
- bash: |
VERS=$(echo $(commit) | cut -c1-20)
if [[ $(ref) == refs/tags* ]]; then
VERS=$(echo $(ref) | sed "s|refs/tags/v||g")
fi
echo "##vso[task.setvariable variable=version]$VERS"
displayName: 'Set version variable'
- script: |
set -e
make lint
displayName: 'Lint source'
- task: Docker@2
displayName: 'build and push docker image'
inputs:
containerRegistry: 'Edgeworx GCP'
repository: $(repository)
command: 'buildAndPush'
Dockerfile: './Dockerfile'
buildContext: './'
tags: |
$(version)
$(branch)
$(branch)-$(build)
latest
- script: |
set -e
sudo make bats
displayName: 'Install bats'
- script: |
set -e
IMAGE="gcr.io/focal-freedom-236620/operator:$(version)"
cd config/operator
kustomize edit set image "$IMAGE"
kustomize build . > /tmp/deployment.yaml
cp /tmp/deployment.yaml ./deployment.yaml
cat ./deployment.yaml | grep "image: $IMAGE"
displayName: 'Kustomize'
- script: |
set -e
cp test/conf/env.sh.tpl test/conf/env.sh
sed -i "s/<<NAMESPACE>>/$(jobuuid)/g" test/conf/env.sh
sed -i "s/<<OP_VERSION>>/$(version)/g" test/conf/env.sh
make feature
displayName: 'Feature tests'
- script: |
set -e
kubectl delete ns $(jobuuid)
displayName: 'Cleanup tests'
condition: failed()
- script: |
set -e
echo $(version) > $(Build.ArtifactStagingDirectory)/version.txt
displayName: 'Create version artefact'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'operator'
displayName: 'Publish artefacts'