forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bazel.yml
225 lines (209 loc) · 7.9 KB
/
bazel.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
parameters:
- name: ciTarget
displayName: "CI target"
type: string
default: bazel.release
- name: artifactSuffix
displayName: "Suffix of artifact"
type: string
default: ""
- name: cacheKey
type: string
default: $(cacheKeyBazelFiles)
- name: cacheVersion
type: string
default: $(cacheKeyBazel)
- name: rbe
displayName: "Enable RBE"
type: boolean
default: true
- name: managedAgent
type: boolean
default: true
- name: bazelBuildExtraOptions
type: string
default: ""
- name: envoyBuildFilterExample
type: string
default: ""
- name: cacheTestResults
displayName: "Cache test results"
type: boolean
default: true
# Unfortunately, AZP is an unmittigated and undocumented disaster.
# The definition of primitive types is close to pointless, as depending
# on where things are set, azp just turns them into strings anyway.
- name: repoFetchDepth
type: string
default: 1
- name: repoFetchTags
type: string
default: false
# Auth
- name: authGithub
type: string
default: ""
# Publishing
- name: publishEnvoy
type: string
default: true
- name: publishTestResults
type: string
default: true
- name: stepsPre
type: stepList
default: []
- name: stepsPost
type: stepList
default: []
steps:
- checkout: self
fetchDepth: ${{ parameters.repoFetchDepth }}
fetchTags: ${{ parameters.repoFetchTags }}
- ${{ each step in parameters.stepsPre }}:
- ${{ each pair in step }}:
${{ pair.key }}: ${{ pair.value }}
# Set up tmpfs directories for self-hosted agents which have a surplus of mem.
#
# NB: Do not add any directory that grow larger than spare memory capacity!
- bash: |
TMPDIRS=(
# This is used as the final delivery directory for the binaries
"$(Build.StagingDirectory)/envoy"
# Bazel repository_cache which is cached by AZP (this speeds up cache load/save)
"$(Build.StagingDirectory)/repository_cache"
"$(Build.StagingDirectory)/bazel"
"$(Build.StagingDirectory)/.cache"
"$(Build.StagingDirectory)/bazel_root/install"
"$(Build.StagingDirectory)/tmp"
"$(Build.StagingDirectory)/bazel_root/base/external")
if [[ "${{ parameters.artifactSuffix }}" == ".arm64" ]]; then
TMPDIRS+=(
"$(Build.StagingDirectory)/bazel_root/base/execroot/envoy/bazel-out/aarch64-fastbuild/testlogs"
"$(Build.StagingDirectory)/bazel_root/base/execroot/envoy/bazel-out/aarch64-opt/testlogs")
else
TMPDIRS+=(
"$(Build.StagingDirectory)/bazel_root/base/execroot/envoy/bazel-out/k8-fastbuild/testlogs"
"$(Build.StagingDirectory)/bazel_root/base/execroot/envoy/bazel-out/k8-opt/testlogs")
fi
for tmpdir in "${TMPDIRS[@]}"; do
echo "Mount(tmpfs): ${tmpdir}"
sudo mkdir -p "$tmpdir"
sudo mount -t tmpfs none "$tmpdir"
sudo chown azure-pipelines "$tmpdir"
done
sudo chown -R azure-pipelines:azure-pipelines $(Build.StagingDirectory)/bazel_root/
displayName: "Mount/tmpfs bazel directories"
condition: and(succeeded(), eq('${{ parameters.managedAgent }}', false))
- bash: |
set -e
CACHE_DIRS=(
"$(Build.StagingDirectory)/.cache/"
"$(Build.StagingDirectory)/bazel_root/install/"
"$(Build.StagingDirectory)/repository_cache/"
"$(Build.StagingDirectory)/bazel_root/base/external")
sudo mkdir -p "${CACHE_DIRS[@]}"
sudo chown -R vsts:vsts "${CACHE_DIRS[@]}" $(Build.StagingDirectory)/bazel_root/
echo "Created bazel cache directories: "${CACHE_DIRS[*]}""
displayName: "Create bazel directories"
condition: and(succeeded(), eq('${{ parameters.managedAgent }}', true))
# Caching
- task: Cache@2
inputs:
key: '"${{ parameters.ciTarget }}" | "${{ parameters.cacheVersion }}" | "${{ parameters.artifactSuffix }}" | ${{ parameters.cacheKey }}'
path: $(Build.StagingDirectory)/bazel
cacheHitVar: BAZEL_CACHE_RESTORED
continueOnError: true
- script: |
set -e
sudo tar xf $(Build.StagingDirectory)/bazel/cache.tar.zst -C $(Build.StagingDirectory) --warning=no-timestamp
sudo rm -rf $(Build.StagingDirectory)/bazel/*
displayName: "Cache/restore (${{ parameters.ciTarget }})"
condition: and(not(canceled()), eq(variables.BAZEL_CACHE_RESTORED, 'true'))
- template: cached.yml
parameters:
version: "$(cacheKeyBuildImage)"
arch: "${{ parameters.artifactSuffix }}"
- bash: |
echo "disk space at beginning of build:"
df -h
displayName: "Check disk space at beginning"
- bash: |
sudo mkdir -p /etc/docker
echo '{
"ipv6": true,
"fixed-cidr-v6": "2001:db8:1::/64"
}' | sudo tee /etc/docker/daemon.json
sudo service docker restart
displayName: "Enable IPv6"
condition: ${{ parameters.managedAgent }}
- script: ci/run_envoy_docker.sh 'ci/do_ci.sh ${{ parameters.ciTarget }}'
workingDirectory: $(Build.SourcesDirectory)
env:
ENVOY_DOCKER_BUILD_DIR: $(Build.StagingDirectory)
SLACK_TOKEN: $(SLACK_TOKEN)
REPO_URI: $(Build.Repository.Uri)
BUILD_URI: $(Build.BuildUri)
ENVOY_BUILD_FILTER_EXAMPLE: ${{ parameters.envoyBuildFilterExample }}
GITHUB_TOKEN: "${{ parameters.authGithub }}"
${{ if ne(parameters['cacheTestResults'], true) }}:
BAZEL_NO_CACHE_TEST_RESULTS: 1
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
AZP_TARGET_BRANCH: "origin/$(System.PullRequest.TargetBranch)"
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
AZP_TARGET_BRANCH: "origin/$(Build.SourceBranchName)"
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
# sha1sum of `ENVOY_PULL_REQUEST`
BAZEL_FAKE_SCM_REVISION: e3b4a6e9570da15ac1caffdded17a8bebdc7dfc9
${{ if parameters.rbe }}:
GCP_SERVICE_ACCOUNT_KEY: $(GcpServiceAccountKey)
ENVOY_RBE: "1"
BAZEL_BUILD_EXTRA_OPTIONS: "--config=remote-ci --jobs=$(RbeJobs) ${{ parameters.bazelBuildExtraOptions }}"
BAZEL_REMOTE_CACHE: grpcs://remotebuildexecution.googleapis.com
BAZEL_REMOTE_INSTANCE: projects/envoy-ci/instances/default_instance
${{ if eq(parameters.rbe, false) }}:
BAZEL_BUILD_EXTRA_OPTIONS: "${{ parameters.bazelBuildExtraOptions }}"
BAZEL_REMOTE_CACHE: $(LocalBuildCache)
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
BAZEL_REMOTE_INSTANCE_BRANCH: "$(System.PullRequest.TargetBranch)"
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
BAZEL_REMOTE_INSTANCE_BRANCH: "$(Build.SourceBranchName)"
displayName: "Run CI script ${{ parameters.ciTarget }}"
- bash: |
echo "disk space at end of build:"
df -h
echo
du -ch "$(Build.StagingDirectory)" | grep -E "[0-9]{2,}M|[0-9]G"
# Cleanup offending files with unicode names
rm -rf $(Build.StagingDirectory)/bazel_root/base/external/go_sdk/test/fixedbugs
displayName: "Check disk space at end"
condition: always()
- ${{ each step in parameters.stepsPost }}:
- ${{ each pair in step }}:
${{ pair.key }}: ${{ pair.value }}
- script: |
set -e
CACHE_DIRS=(
".cache"
"bazel_root/install"
"repository_cache/"
"bazel_root/base/external")
mkdir -p $(Build.StagingDirectory)/bazel/
sudo tar cf - -C $(Build.StagingDirectory) "${CACHE_DIRS[@]}" \
| zstd - -T0 -o $(Build.StagingDirectory)/bazel/cache.tar.zst
echo "Created tarball ($(Build.StagingDirectory)/bazel/cache.tar.zst): ${CACHE_DIRS[@]}"
displayName: "Cache/save (${{ parameters.ciTarget }})"
condition: and(not(canceled()), ne(variables.BAZEL_CACHE_RESTORED, 'true'))
- task: PublishTestResults@2
inputs:
testResultsFiles: "**/bazel-out/**/testlogs/**/test.xml"
testRunTitle: "${{ parameters.ciTarget }}"
searchFolder: $(Build.StagingDirectory)/bazel_root
timeoutInMinutes: 10
condition: eq('${{ parameters.publishTestResults }}', 'true')
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: "$(Build.StagingDirectory)/envoy"
artifactName: ${{ parameters.ciTarget }}${{ parameters.artifactSuffix }}
timeoutInMinutes: 10
condition: eq('${{ parameters.publishEnvoy }}', 'true')