-
Notifications
You must be signed in to change notification settings - Fork 14
/
azure-pipelines.yml
181 lines (154 loc) · 6.84 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# YAML definition for Ev2 usage-service app deployment configuration
parameters:
- name: PublishArtifacts
displayName: Publish built artifacts for release
type: boolean
default: false
- name: ev2ServiceConnection
type: string
default: 'GHAE Ev2 Test'
- name: 'rolloutSpecNames'
type: object
default:
- RolloutSpec-ImagePublish.json
- RolloutSpec-Deploy.json
- name: 'images'
type: object
default:
- 1
- 2
- 3
#
# This workflow is always triggered from GitHub Actions
trigger:
branches:
include:
- main
pr:
branches:
include:
- '*'
stages:
- stage: DockerArtifacts
pool:
type: docker
os: linux
variables:
RepositoryName: $(Build.Repository.Name)
WorkflowName: 'Build Containers'
${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
VersionPrefix: ''
BuildBranch: $(Build.SourceBranchName)
CommitSHA: $(Build.SourceVersion)
${{ if ne(variables['Build.SourceBranchName'], 'main') }}:
VersionPrefix: 'dev-'
BuildBranch: $[coalesce(variables['branch.name'], variables['System.PullRequest.SourceBranch'], variables['Build.SourceBranchName'])]
CommitSHA: $[coalesce(variables['github.sha'], variables['System.PullRequest.SourceCommitId'], variables['Build.SourceVersion'])]
ContainerImagesPath: '$(Build.SourcesDirectory)/config/ev2/app/ServiceGroupRoot/bin/docker_images'
ghaeUsageRootPath: '$(Build.SourcesDirectory)'
doPublishing: $[or(eq(variables['ActionsPublishArtifacts'], true), eq(${{ parameters.PublishArtifacts }}, true))]
isMergeToMain: $[or(in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI'), and(eq(variables['github.event_name'], 'push'), eq(variables['github.ref'], 'refs/heads/main')))]
jobs:
- job: configure
steps:
- checkout: self
# check if we need to rebase with main so that migrations are sequential
- bash: |
set -x -v
default_sha=$(git rev-parse refs/remotes/origin/${DEFAULT_BRANCH})
branch_sha=$(git merge-base ${default_sha} ${COMMIT_SHA})
echo "COMMIT_SHA == > ${COMMIT_SHA}"
[ "${default_sha}" = "${branch_sha}" ] && echo "OK" || (echo "Rebase is required" && exit 1)
condition: or(eq(variables.doPublishing, true), eq(variables.isMergeToMain, true))
workingDirectory: $(ghaeUsageRootPath)
displayName: "Check rebase from main"
env:
COMMIT_SHA: $(CommitSHA)
DEFAULT_BRANCH: main
- bash: echo "##vso[task.setvariable variable=BuildVersion]$(cat ./Dockerfile|grep 'USER_ID'| awk -F'=' '{print $2}')"
displayName: Set Base Version
workingDirectory: $(ghaeUsageRootPath)
- bash: echo "##vso[task.setvariable variable=Image_1]$(echo "1")"
displayName: Set Base Version
workingDirectory: $(ghaeUsageRootPath)
- ${{ each image in parameters.images }}:
- job: "image_${{ image }}"
dependsOn: ['configure']
variables:
target: "${{ image }}"
group: usage.services
steps:
- checkout: self
- ${{ each variable in variables }}:
# - ${{ if startsWith(variable.Key, 'Image_') }}:
- bash: |
if [[ "${{ variable.Key }}" =~ 'Image_' ]] ; then
echo "${{ variable.Key }}"
echo "${{ variable.Value }}"
fi
displayName: "get ${{ variable.Key }}"
- bash: |
set -x -v
echo 'Pretend to pull publish.sh -g -u -s -n'
mkdir -p "${DOCKER_IMAGES}"
touch "${DOCKER_IMAGES}/${TARGET}"
condition: or(eq(variables.doPublishing, true), eq(variables.isMergeToMain, true))
workingDirectory: $(ghaeUsageRootPath)
displayName: "Pull Docker Images from GPR"
env:
VERSION: $(Version)
DOCKER_IMAGES: ${{ variables.ContainerImagesPath }}
DEBUG: '-x -v'
TARGET: $(target)
- task: PublishPipelineArtifact@1
displayName: "Publish Container artifacts"
condition: or(eq(variables.doPublishing, true), eq(variables.isMergeToMain, true))
inputs:
targetPath: '${{ variables.ContainerImagesPath }}'
artifact: 'usage-service-containers'
publishLocation: 'pipeline'
- stage: ArtifactBuilds
variables:
serviceGroupRoot : '$(Build.SourcesDirectory)/ghae-usage-service/config/ev2/app/ServiceGroupRoot'
resourcesFilePath: '$(Build.SourcesDirectory)/ghae-usage-service/config/ev2/Resources.json'
scaleUnitsOverridesFilePath: '$(Build.SourcesDirectory)/ghae-usage-service/config/ev2/ScaleUnits.json'
environmentsOverridesFilePath: '$(Build.SourcesDirectory)/ghae-usage-service/config/ev2/Environments.json'
ghaeUsageRootPath: '$(Build.SourcesDirectory)/ghae-usage-service'
ghaeDeploymentRootPath: '$(Build.SourcesDirectory)/ghae-deployment'
artifactName: ServiceGroupRoot
Version: $[stageDependencies.DockerArtifacts.pullFromGPR.outputs['CalculateVersion.Version']]
dependsOn: [ 'DockerArtifacts' ] # nothing, should just run
jobs:
- job: ArtifactsBuild
pool:
name: Azure Pipelines
vmImage: 'windows-latest'
variables:
doPublishing: $[or(eq(variables['ActionsPublishArtifacts'], true), eq(${{ parameters.PublishArtifacts }}, true))]
isMergeToMain: $[or(in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI'), eq(variables['branch.name'], 'main'))]
steps:
- checkout: self
- task: DownloadPipelineArtifact@2
displayName: "Download docker images artifacts"
condition: or(eq(variables.doPublishing, true), eq(variables.isMergeToMain, true))
inputs:
artifact: 'usage-service-containers'
path: '${{ variables.serviceGroupRoot }}/dist/bin/docker_images/'
# Note this runs in a non-publish mode, so we're testing that first
- bash: |
set -x -v
echo 'Pretend do something artifacty'
mkdir -p "${SERVICE_GROUP_ROOT}"
touch "${SERVICE_GROUP_ROOT}/artifacts"
displayName: 'Prep the workspace with fake artifacts'
condition: and(eq(variables.doPublishing, false), eq(variables.isMergeToMain, false))
env:
VERSION: $(Version)
SERVICE_GROUP_ROOT: '${{ variables.serviceGroupRoot }}'
- task: PublishPipelineArtifact@1
displayName: "Publish ServiceGroupRoot artifact"
condition: or(eq(variables.doPublishing, true), eq(variables.isMergeToMain, true))
inputs:
targetPath: '${{ variables.serviceGroupRoot }}'
artifact: '${{ variables.artifactName }}'
publishLocation: 'pipeline'