-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJenkinsfile
393 lines (360 loc) · 19.9 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
pipeline {
agent {
docker {
image "${RUNNER_DOCKER_IMAGE}"
args "${RUNNER_DOCKER_ARGS}"
registryUrl "${RUNNER_DOCKER_REGISTRY_URL}"
registryCredentialsId 'ocir-pull-and-push-account'
label 'basic-small'
}
}
parameters {
string (name: 'BASE_TAG',
defaultValue: '1.0.0-1',
description: 'Base value used as part of generated image tag',
trim: true)
}
environment {
DOCKER_CREDS = credentials('github-packages-credentials-rw')
OCR_CREDS = credentials('ocr-pull-and-push-account')
NETRC_FILE = credentials('netrc')
OCI_CLI_TENANCY = credentials('oci-tenancy')
OCI_CLI_USER = credentials('oci-user-ocid')
OCI_CLI_FINGERPRINT = credentials('oci-api-key-fingerprint')
OCI_CLI_KEY_FILE = credentials('oci-api-key')
OCI_CLI_REGION = 'us-phoenix-1'
// image names and tags are created from these variables:
REPO = 'ghcr.io/verrazzano'
BOBBYS_HELIDON = 'example-bobbys-helidon-stock-application'
ROBERTS_HELIDON = 'example-roberts-helidon-stock-application'
BOBBYS_COHERENCE = 'example-bobbys-coherence'
ROBERTS_COHERENCE = 'example-roberts-coherence'
BOBBYS_WEBLOGIC = 'example-bobbys-front-end'
BOBS_WEBLOGIC = 'example-bobs-bookstore-order-manager'
TODO_WEBLOGIC = 'example-todo'
HELLO_HELIDON_V1 = 'example-helidon-greet-app-v1'
HELLO_HELIDON_V2 = 'example-helidon-greet-app-v2'
SPRING_SAMPLE = 'example-springboot'
VERSION = get_image_tag()
// secrets used during build
BOB_DB_PASSWORD = credentials('bobs-bookstore-db-password')
BOB_ADMIN_PASSWORD = credentials('bobs-bookstore-admin-password')
// access to GitHub Packages Maven Repository
MAVEN_SETTINGS = credentials('oracle-maven-settings')
BUCKET_NAME = "build-shared-files"
JDK14_BUNDLE = "openjdk-14.0.2_linux-x64_bin.tar.gz"
JDK11_BUNDLE = "openjdk-11+28_linux-x64_bin.tar.gz"
IMAGETOOL_BUNDLE = "imagetool.zip"
}
stages {
stage('Initialize') {
steps {
sh """
find $WORKSPACE -mindepth 1 -maxdepth 1 | xargs rm -rf
"""
sh """
cp -f "${NETRC_FILE}" $HOME/.netrc
chmod 600 $HOME/.netrc
"""
}
}
stage('Default checkout') {
steps {
script {
def scmURL = scm.getUserRemoteConfigs()[0].getUrl()
defaultCheckoutTargetDir = scmURL.replaceAll(/^.*\//,'').replaceAll(/\.git$/, '')
}
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'RelativeTargetDirectory', relativeTargetDir: defaultCheckoutTargetDir]],
userRemoteConfigs: scm.userRemoteConfigs
])
}
}
stage('Prepare Environment') {
steps {
getMavenSeedData '/build-shared-files'
sh """
mkdir -p $HOME/.m2/repository/com
tar xz -C $HOME/.m2/repository/com -f /build-shared-files/oracle-maven.tar.gz
sudo yum -y install wget
"""
}
}
stage('Copyright Compliance Check') {
when { not { buildingTag() } }
steps {
copyrightScan "${WORKSPACE}/examples"
}
}
stage('Parallel builds') {
parallel {
stage ('Bobbys Books') {
stages {
stage('Build Bobbys Coherence Application') {
steps {
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin
cd examples/bobs-books/bobbys-books/bobbys-coherence
mvn -B -s $MAVEN_SETTINGS -Dmaven.compiler.fork=true -Dmaven.compiler.executable=\${JAVA_11_HOME}/bin/javac clean install
docker build --force-rm=true -f Dockerfile -t ${env.REPO}/${env.BOBBYS_COHERENCE}:${env.VERSION} .
docker push ${env.REPO}/${env.BOBBYS_COHERENCE}:${env.VERSION}
"""
}
}
stage('Scan Bobbys Coherence Application') {
steps {
scanContainerImage("${env.REPO}/${env.BOBBYS_COHERENCE}:${env.VERSION}", "bobby_coherence.scanning-report.json")
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report*.json', allowEmptyArchive: true
}
}
}
stage('Build Bobbys Helidon Stock Application') {
steps {
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin
cd examples/bobs-books/bobbys-books/bobbys-helidon-stock-application
mvn -B -s $MAVEN_SETTINGS -Dmaven.compiler.fork=true -Dmaven.compiler.executable=\${JAVA_11_HOME}/bin/javac clean install
docker build --force-rm=true -f Dockerfile -t ${env.REPO}/${env.BOBBYS_HELIDON}:${env.VERSION} .
docker push ${env.REPO}/${env.BOBBYS_HELIDON}:${env.VERSION}
"""
}
}
stage('Scan Bobbys Helidon Stock Application') {
steps {
scanContainerImage("${env.REPO}/${env.BOBBYS_HELIDON}:${env.VERSION}", "bobby_helidon.scanning-report.json")
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report*.json', allowEmptyArchive: true
}
}
}
stage('Build Bobbys Front-end WebLogic Application') {
steps {
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin
echo "${OCR_CREDS_PSW}" | docker login container-registry.oracle.com -u ${OCR_CREDS_USR} --password-stdin
cd examples/bobs-books/bobbys-books/bobbys-front-end
mvn -B -s $MAVEN_SETTINGS clean install
cd deploy
./build.sh ${env.REPO}/${env.BOBBYS_WEBLOGIC}:${env.VERSION}
docker push ${env.REPO}/${env.BOBBYS_WEBLOGIC}:${env.VERSION}
"""
}
}
stage('Scan Bobbys Front-end WebLogic Application') {
steps {
scanContainerImage("${env.REPO}/${env.BOBBYS_WEBLOGIC}:${env.VERSION}", "bobby_weblogic.scanning-report.json")
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report*.json', allowEmptyArchive: true
}
}
}
}
}
stage('Bobs Backend') {
stages {
stage('Build Bobs Backend WebLogic Application') {
steps {
sh """
# sleep 2 minutes to workaround WIT doing a docker prune at the same time
# once WIT has a fix this can be removed
sleep 2m
echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin
echo "${OCR_CREDS_PSW}" | docker login container-registry.oracle.com -u ${OCR_CREDS_USR} --password-stdin
cd examples/bobs-books/bobs-bookstore-order-manager
mvn -B -s $MAVEN_SETTINGS clean install
cd deploy
./build.sh ${env.REPO}/${env.BOBS_WEBLOGIC}:${env.VERSION}
docker push ${env.REPO}/${env.BOBS_WEBLOGIC}:${env.VERSION}
"""
}
}
stage('Scan Bobs Backend WebLogic Application') {
steps {
scanContainerImage("${env.REPO}/${env.BOBS_WEBLOGIC}:${env.VERSION}", "bobs_weblogic.scanning-report.json")
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report*.json', allowEmptyArchive: true
}
}
}
}
}
stage('Roberts Books') {
stages {
stage('Build Roberts Coherence Application') {
steps {
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin
cd examples/bobs-books/roberts-books/roberts-coherence
mvn -B -s $MAVEN_SETTINGS -Dmaven.compiler.fork=true -Dmaven.compiler.executable=\${JAVA_11_HOME}/bin/javac clean install
oci os object get -bn ${BUCKET_NAME} --file ${JDK14_BUNDLE} --name ${JDK14_BUNDLE}
docker build --build-arg JDK_BINARY=${JDK14_BUNDLE} --force-rm=true -f Dockerfile -t ${env.REPO}/${env.ROBERTS_COHERENCE}:${env.VERSION} .
docker push ${env.REPO}/${env.ROBERTS_COHERENCE}:${env.VERSION}
"""
}
}
stage('Scan Roberts Coherence Application') {
steps {
scanContainerImage("${env.REPO}/${env.ROBERTS_COHERENCE}:${env.VERSION}", "roberts_coherence.scanning-report.json")
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report*.json', allowEmptyArchive: true
}
}
}
stage('Build Roberts Helidon Stock Application') {
steps {
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin
cd examples/bobs-books/roberts-books/roberts-helidon-stock-application/src/main/web
npm install
cd ../../..
mvn -B -s $MAVEN_SETTINGS -Dmaven.compiler.fork=true -Dmaven.compiler.executable=\${JAVA_11_HOME}/bin/javac clean install
oci os object get -bn ${BUCKET_NAME} --file ${JDK14_BUNDLE} --name ${JDK14_BUNDLE}
docker build --build-arg JDK_BINARY=${JDK14_BUNDLE} --force-rm=true -f Dockerfile -t ${env.REPO}/${env.ROBERTS_HELIDON}:${env.VERSION} .
docker push ${env.REPO}/${env.ROBERTS_HELIDON}:${env.VERSION}
"""
}
}
stage('Scan Roberts Helidon Stock Application') {
steps {
scanContainerImage("${env.REPO}/${env.ROBERTS_HELIDON}:${env.VERSION}", "roberts_helidon.scanning-report.json")
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report*.json', allowEmptyArchive: true
}
}
}
}
}
stage('Hello Helidon') {
stages {
stage('Build Hello Helidon V1 Application') {
steps {
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin
cd examples/hello-helidon/helidon-app-greet-v1
mvn -B -s $MAVEN_SETTINGS -Dmaven.compiler.fork=true -Dmaven.compiler.executable=\${JAVA_11_HOME}/bin/javac clean install
oci os object get -bn ${BUCKET_NAME} --file ${JDK14_BUNDLE} --name ${JDK14_BUNDLE}
docker image build --build-arg JDK_BINARY=${JDK14_BUNDLE} -t ${env.REPO}/${env.HELLO_HELIDON_V1}:${env.VERSION} .
docker push ${env.REPO}/${env.HELLO_HELIDON_V1}:${env.VERSION}
"""
}
}
stage('Scan Hello Helidon V1 Application') {
steps {
scanContainerImage("${env.REPO}/${env.HELLO_HELIDON_V1}:${env.VERSION}", "hello_helidon_v1.scanning-report.json")
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report*.json', allowEmptyArchive: true
}
}
}
stage('Build Hello Helidon V2 Application') {
steps {
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin
cd examples/hello-helidon/helidon-app-greet-v2
mvn -B -s $MAVEN_SETTINGS -Dmaven.compiler.fork=true -Dmaven.compiler.executable=\${JAVA_11_HOME}/bin/javac clean install
oci os object get -bn ${BUCKET_NAME} --file ${JDK14_BUNDLE} --name ${JDK14_BUNDLE}
docker image build --build-arg JDK_BINARY=${JDK14_BUNDLE} -t ${env.REPO}/${env.HELLO_HELIDON_V2}:${env.VERSION} .
docker push ${env.REPO}/${env.HELLO_HELIDON_V2}:${env.VERSION}
"""
}
}
stage('Scan Hello Helidon V2 Application') {
steps {
scanContainerImage("${env.REPO}/${env.HELLO_HELIDON_V2}:${env.VERSION}", "hello_helidon_v2.scanning-report.json")
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report*.json', allowEmptyArchive: true
}
}
}
}
}
stage ('TODO List') {
stages {
stage('Build TODO List WebLogic Application') {
steps {
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin
echo "${OCR_CREDS_PSW}" | docker login container-registry.oracle.com -u ${OCR_CREDS_USR} --password-stdin
cd examples/todo-list
mvn -B -s $MAVEN_SETTINGS clean install
cd setup
./build.sh ${env.REPO}/${env.TODO_WEBLOGIC}:${env.VERSION}
docker push ${env.REPO}/${env.TODO_WEBLOGIC}:${env.VERSION}
"""
}
}
stage('Scan TODO List WebLogic Application') {
steps {
scanContainerImage("${env.REPO}/${env.TODO_WEBLOGIC}:${env.VERSION}", "todo_weblogic.scanning-report.json")
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report*.json', allowEmptyArchive: true
}
}
}
}
}
stage('Spring sample') {
stages {
stage('Build Spring sample application') {
steps {
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin
echo "${OCR_CREDS_PSW}" | docker login container-registry.oracle.com -u ${OCR_CREDS_USR} --password-stdin
cd examples/springboot-app
mvn -B -s $MAVEN_SETTINGS clean install
oci os object get -bn ${BUCKET_NAME} --file ${JDK11_BUNDLE} --name ${JDK11_BUNDLE}
docker build -t ${env.REPO}/${env.SPRING_SAMPLE}:${env.VERSION} .
docker push ${env.REPO}/${env.SPRING_SAMPLE}:${env.VERSION}
"""
}
}
stage('Scan Spring sample Application') {
steps {
scanContainerImage("${env.REPO}/${env.SPRING_SAMPLE}:${env.VERSION}", "spring_sample.scanning-report.json")
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report*.json', allowEmptyArchive: true
}
}
}
}
}
}
}
}
}
def get_image_tag() {
time_stamp = sh(returnStdout: true, script: "date +%Y%m%d%H%M%S").trim()
short_commit_sha = sh(returnStdout: true, script: "git rev-parse --short HEAD").trim()
if ( env.BRANCH_NAME == 'master' ) {
docker_image_tag = params.BASE_TAG + "-" + time_stamp + "-" + short_commit_sha
} else {
docker_image_tag = time_stamp + "-" + short_commit_sha
}
println("image tag: " + docker_image_tag)
return docker_image_tag
}