-
Notifications
You must be signed in to change notification settings - Fork 26
/
Jenkinsfile
228 lines (214 loc) · 9.62 KB
/
Jenkinsfile
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
226
227
228
def flagChiefDone = false
def flagWorkerLaunched = false
pipeline {
options {
disableConcurrentBuilds()
timeout(time: 2, unit: 'HOURS')
}
environment {
DOCKER_REGISTRY='registry.petuum.com/internal/scalable-ml/autodist/toolchain'
}
agent { label 'petuum-jenkins-slave' }
stages {
stage('begin') {
steps {
setBuildStatus("Build in progress", "pending", "${env.GIT_COMMIT}", "${env.BUILD_URL}");
}
}
stage('build-image') {
agent {
label 'GPU1'
}
steps {
sh "docker build --build-arg TF_IMAGE_TAG=1.15.0-gpu-py3 --no-cache -t ${DOCKER_REGISTRY}:tf1 -f docker/Dockerfile.gpu ."
sh "docker push ${DOCKER_REGISTRY}:tf1"
sh "docker build --build-arg TF_IMAGE_TAG=2.2.0-gpu --no-cache -t ${DOCKER_REGISTRY}:tf2 -f docker/Dockerfile.gpu ."
sh "docker push ${DOCKER_REGISTRY}:tf2"
}
}
stage('lint') {
agent {
docker {
label 'GPU1'
image "${DOCKER_REGISTRY}:tf2"
}
}
steps{
sh 'prospector autodist'
}
}
stage('test-local') {
parallel {
stage('tf1') {
agent {
docker {
alwaysPull true
label 'GPU1'
image "${DOCKER_REGISTRY}:tf1"
args '--gpus all'
}
}
steps{
// .. remove "--run-integration" to have a mini test ..
sh "cd tests && python3 -m pytest -s --run-integration --junitxml=test_local.xml --cov=autodist --cov-branch --cov-report term-missing --ignore=integration/test_dist.py . && mv .coverage .coverage.local.tf1"
}
post {
always {
junit allowEmptyResults: true, testResults: 'tests/test_local.xml'
stash includes: 'tests/.coverage.local.tf1', name: 'testcov_local_tf1'
}
}
}
stage('tf2') {
agent {
docker {
alwaysPull true
label 'GPU2'
image "${DOCKER_REGISTRY}:tf2"
args '--gpus all'
}
}
steps{
// .. remove "--run-integration" to have a mini test ..
sh "cd tests && python3 -m pytest -s --run-integration --junitxml=test_local.xml --cov=autodist --cov-branch --cov-report term-missing --ignore=integration/test_dist.py . && mv .coverage .coverage.local.tf2"
}
post {
always {
junit allowEmptyResults: true, testResults: 'tests/test_local.xml'
stash includes: 'tests/.coverage.local.tf2', name: 'testcov_local_tf2'
}
}
}
}
}
stage('test-distributed') {
parallel {
stage('chief') {
agent {
label 'GPU2'
}
steps {
sh 'docker pull ${DOCKER_REGISTRY}:tf2'
waitUntil {script {return flagWorkerLaunched}}
sh 'docker run --gpus all --network=host -v /shared/.ssh:/root/.ssh:ro -v $(pwd)/tests:/mnt -e COVERAGE_PROCESS_START=/mnt/integration/dist.coveragerc ${DOCKER_REGISTRY}:tf2 bash -c "python3 -m pytest -s --junitxml=test_dist.xml integration/test_dist.py"'
echo "${flagChiefDone}"
}
post {
always {
script {flagChiefDone = true}
echo "${flagChiefDone}"
junit allowEmptyResults: true, testResults: 'tests/test_dist.xml'
stash includes: 'tests/.coverage.*', name: 'testcov_distributed_chief'
}
}
}
stage('worker') {
agent {
label 'GPU1'
}
steps {
sh 'docker pull ${DOCKER_REGISTRY}:tf2'
sh 'docker rm -f worker || true'
sh 'docker run --gpus all --name worker -d --privileged --network=host -v /shared/.ssh:/root/.ssh -v $(pwd)/tests:/mnt -e COVERAGE_PROCESS_START=/mnt/integration/dist.coveragerc ${DOCKER_REGISTRY}:tf2 bash -c "env | grep COVERAGE >> /etc/environment && /usr/sbin/sshd -p 12345; sleep infinity"'
script {flagWorkerLaunched = true}
echo "${flagChiefDone}"
waitUntil {script {return flagChiefDone}}
}
post {
always {
sh 'docker rm -f worker || true'
stash includes: 'tests/.coverage.*', name: 'testcov_distributed_worker'
}
}
}
}
}
stage('report-coverage') {
agent {
docker {
label 'GPU2'
image "${DOCKER_REGISTRY}:tf2"
}
}
steps{
sh 'mkdir -p coverage-report'
dir ('coverage-report') {
unstash 'testcov_local_tf1'
unstash 'testcov_local_tf2'
unstash 'testcov_distributed_chief'
unstash 'testcov_distributed_worker'
sh """#!/bin/bash
coverage combine tests/
coverage report
coverage html -d htmlcov
tar -zcvf htmlcov.tar.gz htmlcov
# Create JSON to dynamically get total coverage percentage
total_coverage_line=\$(grep '<span class="pc_cov">.*%</span>' htmlcov/index.html | head -n 1)
capture_regex='<span class="pc_cov">(.*)?</span>'
if [[ \${total_coverage_line} =~ \${capture_regex} ]]; then
pct="\${BASH_REMATCH[@]:1}"
echo '{"total_coverage_pct":"'\${pct}'"}' > jenkinscovdata.json
fi
"""
}
}
post {
success {
archiveArtifacts allowEmptyArchive: true, artifacts: 'coverage-report/htmlcov.tar.gz', fingerprint: true
archiveArtifacts allowEmptyArchive: true, artifacts: 'coverage-report/jenkinscovdata.json', fingerprint: true
}
}
}
}
post {
success {
setBuildStatus("Build succeeded", "success", "${env.GIT_COMMIT}", "${env.BUILD_URL}");
}
failure {
setBuildStatus("Build failed", "failure", "${env.GIT_COMMIT}", "${env.BUILD_URL}");
}
}
}
/*
* We've disabled the github commit notification from plugin because it doesn't
* allow us to overwrite the target URL (it takes raw hostname of jenkins server,
* which we dont want, as we're pointing to public hostname instead).
*
* In future, we can use setBuildStatusViaPlugin() instead, but until those plugins
* become more stable, can use this.
*/
void setBuildStatus(String message, String state, String gitCommit, String buildUrl) {
withCredentials([string(credentialsId: 'petuumops-github-service-token', variable: 'TOKEN')]) {
String statusUrl = "https://api.github.com/repos/petuum/autodist/statuses/$gitCommit"
String targetUrl = buildUrl.replaceAll(/http.*\.(com|io)\//,"https://jenkins.petuum.io/")
// Can enable 'set -x' for debugging. TOKEN is not logged
sh """
# set -x
curl -H \"Authorization: token $TOKEN\" \
-X POST \
-d '{\"description\": \"$message\", \
\"state\": \"$state\", \
\"context\": "ci/jenkins", \
\"target_url\" : \"$targetUrl\" }' \
${statusUrl}
"""
}
}
/*
* Don't use this until plugins become more stable, for example:
* https://issues.jenkins-ci.org/browse/JENKINS-54249.
*
* Instead, opt for setBuildStatus() and disable from job (we need to send
* our own notification because auto won't allow us to set the public revere proxy URL)
*/
void setBuildStatusViaPlugin(String message, String state, String gitCommit, String repoSource, String buildUrl) {
String targetUrl = buildUrl.replaceAll(/http.*\.(com|io)\//,"https://jenkins.petuum.io/")
step([
$class: "GitHubCommitStatusSetter",
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/jenkins/branch"],
reposSource: [$class: "ManuallyEnteredRepositorySource", url: repoSource],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "error"]],
statusBackrefSource: [$class: "ManuallyEnteredBackrefSource", backref: targetUrl],
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
]);
}