forked from NVIDIA/spark-rapids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile-blossom.premerge-databricks
230 lines (210 loc) · 9.34 KB
/
Jenkinsfile-blossom.premerge-databricks
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
229
230
#!/usr/local/env groovy
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* Jenkinsfile for building rapids-plugin on Databricks cluster
*
*/
@Library('blossom-lib')
@Library('blossom-github-lib@master')
import ipp.blossom.*
def githubHelper // blossom github helper
def IMAGE_DB = pod.getCPUYAML("${common.ARTIFACTORY_NAME}/sw-spark-docker/spark:rapids-databricks")
pipeline {
agent {
kubernetes {
label "premerge-init-${BUILD_TAG}"
cloud "${common.CLOUD_NAME}"
yaml "${IMAGE_DB}"
}
}
options {
ansiColor('xterm')
buildDiscarder(logRotator(numToKeepStr: '50'))
skipDefaultCheckout true
timeout(time: 12, unit: 'HOURS')
}
parameters {
// Put a default value for REF to avoid error when running the pipeline manually
string(name: 'REF', defaultValue: 'main',
description: 'Merged commit of specific PR')
string(name: 'GITHUB_DATA', defaultValue: '',
description: 'Json-formatted github data from upstream blossom-ci')
choice(name: 'TEST_MODE', choices: ['CI_PART1', 'CI_PART2'],
description: 'Separate integration tests into 2 parts, and run each part in parallell')
}
environment {
GITHUB_TOKEN = credentials("github-token")
PVC = credentials("pvc")
CUSTOM_WORKSPACE = "/home/jenkins/agent/workspace/${BUILD_TAG}"
// DB related ENVs
IDLE_TIMEOUT = '390' // 6.5 hours
NUM_WORKERS = '0'
DB_TYPE = getDbType()
DATABRICKS_HOST = DbUtils.getHost("$DB_TYPE")
DATABRICKS_TOKEN = credentials("${DbUtils.getToken("$DB_TYPE")}")
DATABRICKS_PUBKEY = credentials("SPARK_DATABRICKS_PUBKEY")
DATABRICKS_DRIVER = DbUtils.getDriver("$DB_TYPE")
DATABRICKS_WORKER = DbUtils.getWorker("$DB_TYPE")
INIT_SCRIPTS_DIR = "/databricks/init_scripts/${BUILD_TAG}"
}
stages {
stage("Init githubHelper") {
steps {
script {
githubHelper = GithubHelper.getInstance("${GITHUB_TOKEN}", params.GITHUB_DATA)
// desc contains the PR ID and can be accessed from different builds
currentBuild.description = githubHelper.getBuildDescription()
checkoutCode(githubHelper.getCloneUrl(), githubHelper.getMergedSHA())
}
}
} // end of Init githubHelper
stage('Databricks') {
failFast true // Abort running if one branch failed
matrix {
axes {
axis {
// 'name' and 'value' only supprt literal string in the declarative Jenkins
// Refer to Jenkins issue https://issues.jenkins.io/browse/JENKINS-62127
name 'DB_RUNTIME'
values '11.3', '12.2', '13.3'
}
}
stages {
stage('Build') {
agent {
kubernetes {
label "premerge-ci-${DB_RUNTIME}-${BUILD_NUMBER}"
cloud "${common.CLOUD_NAME}"
yaml "${IMAGE_DB}"
workspaceVolume persistentVolumeClaimWorkspaceVolume(claimName: "${PVC}", readOnly: false)
customWorkspace "${CUSTOM_WORKSPACE}-${DB_RUNTIME}-${BUILD_NUMBER}"
}
}
environment {
DATABRICKS_RUNTIME = DbUtils.getRuntime("$DB_RUNTIME")
BASE_SPARK_VERSION = DbUtils.getSparkVer("$DB_RUNTIME")
BASE_SPARK_VERSION_TO_INSTALL_DATABRICKS_JARS = DbUtils.getInstallVer("$DB_RUNTIME")
INIT_SCRIPTS = DbUtils.getInitScripts("$DB_RUNTIME")
}
steps {
script {
unstash('source_tree')
databricksBuild()
deleteDir() // cleanup content if no error
}
}
}
}
} // end of matrix
} // end of stage Databricks
} // end of stages
} // end of pipeline
// params.DATABRICKS_TYPE: 'aws' or 'azure', param can be defined through the jenkins webUI
String getDbType() {
return params.DATABRICKS_TYPE ? params.DATABRICKS_TYPE : 'aws'
}
void databricksBuild() {
def CLUSTER_ID = ''
def SPARK_MAJOR = BASE_SPARK_VERSION_TO_INSTALL_DATABRICKS_JARS.replace('.', '')
def ws_path = "$INIT_SCRIPTS_DIR-$DB_TYPE"
try {
stage("Create $SPARK_MAJOR DB") {
script {
container('cpu') {
sh "rm -rf spark-rapids-ci.tgz"
sh "tar -zcf spark-rapids-ci.tgz *"
def CREATE_PARAMS = " -r $DATABRICKS_RUNTIME -w $DATABRICKS_HOST -t $DATABRICKS_TOKEN" +
" -s $DB_TYPE -n CI-${BUILD_TAG}-${BASE_SPARK_VERSION} -k \"$DATABRICKS_PUBKEY\" -i $IDLE_TIMEOUT" +
" -d $DATABRICKS_DRIVER -o $DATABRICKS_WORKER -e $NUM_WORKERS"
// handle init scripts if exist
if (env.INIT_SCRIPTS) {
// foo.sh,bar.sh --> /path/foo.sh,/path/bar.sh
CREATE_PARAMS += " -f " + DbUtils.uploadFiles(this, env.INIT_SCRIPTS, ws_path)
}
CLUSTER_ID = sh(script: "python3 ./jenkins/databricks/create.py $CREATE_PARAMS",
returnStdout: true).trim()
echo CLUSTER_ID
}
}
}
stage("Build against $SPARK_MAJOR DB") {
script {
container('cpu') {
withCredentials([file(credentialsId: 'SPARK_DATABRICKS_PRIVKEY', variable: 'DATABRICKS_PRIVKEY')]) {
def BUILD_PARAMS = " -w $DATABRICKS_HOST -t $DATABRICKS_TOKEN -c $CLUSTER_ID -z ./spark-rapids-ci.tgz" +
" -p $DATABRICKS_PRIVKEY -l ./jenkins/databricks/build.sh -d /home/ubuntu/build.sh" +
" -v $BASE_SPARK_VERSION -i $BASE_SPARK_VERSION_TO_INSTALL_DATABRICKS_JARS"
// add retry for build step to try
// mitigate the issue of downloading dependencies while maven/sonatype is quite unstable
retry(3) {
sh "python3 ./jenkins/databricks/run-build.py $BUILD_PARAMS"
}
}
}
}
}
stage("Test agaist $SPARK_MAJOR DB") {
script {
container('cpu') {
try {
withCredentials([file(credentialsId: 'SPARK_DATABRICKS_PRIVKEY', variable: 'DATABRICKS_PRIVKEY')]) {
def TEST_PARAMS = " -w $DATABRICKS_HOST -t $DATABRICKS_TOKEN -c $CLUSTER_ID -e TEST_MODE=$TEST_MODE" +
" -p $DATABRICKS_PRIVKEY -l ./jenkins/databricks/test.sh -v $BASE_SPARK_VERSION -d /home/ubuntu/test.sh"
if (params.SPARK_CONF) {
TEST_PARAMS += " -f ${params.SPARK_CONF}"
}
sh "python3 ./jenkins/databricks/run-tests.py $TEST_PARAMS"
}
} finally {
common.publishPytestResult(this, "${STAGE_NAME}")
}
}
}
}
} finally {
if (CLUSTER_ID) {
container('cpu') {
retry(3) {
if (env.INIT_SCRIPTS) {
DbUtils.cleanUp(this, ws_path)
}
sh "python3 ./jenkins/databricks/shutdown.py -s $DATABRICKS_HOST -t $DATABRICKS_TOKEN -c $CLUSTER_ID -d"
}
}
}
}
}
void checkoutCode(String url, String sha) {
checkout(
changelog: false,
poll: true,
scm: [
$class : 'GitSCM', branches: [[name: sha]],
userRemoteConfigs: [[
credentialsId: 'github-token',
url : url,
refspec : '+refs/pull/*/merge:refs/remotes/origin/pr/*']],
extensions : [[$class: 'CloneOption', shallow: true]]
]
)
sh "git submodule update --init"
if (!common.isSubmoduleInit(this)) {
error "Failed to clone submodule : thirdparty/parquet-testing"
}
stash(name: 'source_tree', includes: '**,.git/**', useDefaultExcludes: false)
}