Skip to content

Commit 372f649

Browse files
idzikovskyiAnatoliy Shevchuk
andcommitted
MapR [DFDEVOPS-3022] Add an option to easily modify build images per component (apache#1153)
Co-authored-by: Anatoliy Shevchuk <[email protected]>
1 parent 903a3d9 commit 372f649

File tree

9 files changed

+78
-326
lines changed

9 files changed

+78
-326
lines changed

devops/Jenkinsfile

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ env.ARTIFACTORY_PATH=''
1818
env.ID=''
1919
env.PROJECT=''
2020

21-
env.DOCKER_REGISTRY="${DOCKER_REGISTRY}"
21+
IMAGE_NAMES_MAP=[:]
2222

2323
pipeline {
2424
agent none
@@ -45,31 +45,30 @@ pipeline {
4545
}
4646
}
4747
}
48-
4948
stage("Build & Sign & Upload to Artifactory") {
5049
agent none
5150
steps {
5251
script {
5352
buildInParallel=[:]
5453
YAML_CONFIG.build.each {
5554
buildInParallel["Build ${it.name}"] = { ->
56-
5755
node (it.hostmachine_jenkins_label) {
5856
checkout scm
59-
build(it)
57+
validateBuildImage(it)
58+
echo "Using image: ${IMAGE_NAMES_MAP[it.name]}"
59+
buildStage(it)
6060
if(it.rpmSign == true)
6161
signing.rpmSign("dist")
62-
getVersionAndUploadToArtifactory()
62+
getVersionAndUploadToArtifactory(it)
6363
}
64-
6564
}
66-
}
65+
}
6766
parallel buildInParallel
6867
}
6968
}
7069
}
7170

72-
stage ("Whitesource Scan") {
71+
stage ("OWASP Scan") {
7372
agent {label "redhat8"}
7473
when {
7574
equals (actual: YAML_CONFIG.whitesourceScan, expected: true)
@@ -78,18 +77,6 @@ pipeline {
7877
script {
7978
checkout scm
8079
ws.dockerScan()
81-
/*Get token of product. We have to communicate with WS API only using 64-digits project's token.
82-
We are sending request to API and get ALL "project+token" pairs. Then parse this information and find token for current project*/
83-
productToken = ws.getWSProductToken()
84-
85-
//Get reports (Excel and json) from WS site and save these reports to files. Once for each format
86-
ws.getWSReports(productToken)
87-
88-
//Move latest reports to the "old" folder in Artifactory
89-
ws.moveOldWsReports(ARTIFACTORY_SERVER)
90-
91-
//Upload reports (Excel and json) to the Artifactory (to the latest folder)
92-
ws.uploadToArtifactory(ARTIFACTORY_SERVER)
9380
}
9481
}
9582
}
@@ -124,42 +111,14 @@ pipeline {
124111
}
125112
}
126113

127-
def build(yamlCurrentBuildItem) {
128-
def image = yamlCurrentBuildItem.image
129-
def imageContext = yamlCurrentBuildItem.imageContext
130-
131-
if (image) {
132-
image = image.replace("_DOCKER_REGISTRY_", DOCKER_REGISTRY)
133-
}
134-
135-
if (imageContext) {
136-
if (image) {
137-
error "You can not specify 'image' and 'imageContext' options in build-config.yaml"
138-
}
139-
def imageTagScript = yamlCurrentBuildItem.imageTagScript
140-
image = sh script: imageTagScript, returnStdout: true
141-
image = image.trim()
142-
def imageCheckStatus = sh script: "docker inspect -f . '${image}'", returnStatus: true
143-
if (imageCheckStatus != 0) {
144-
imageCheckStatus = sh script: "docker pull '${image}'", returnStatus: true
145-
}
146-
if (imageCheckStatus != 0) {
147-
sh """
148-
docker build \
149-
--build-arg DOCKER_REGISTRY='${DOCKER_REGISTRY}' \
150-
-t '${image}' \
151-
'${imageContext}'
152-
docker push '${image}'
153-
"""
154-
}
155-
}
156-
114+
def buildStage(yamlCurrentBuildItem) {
157115
def buildCommand = yamlCurrentBuildItem.basicBuildCommands.replace("_BUILD_ENV_VARS_","TIMESTAMP=${ID} DO_DEPLOY=${params.DO_DEPLOY} ${params.BUILD_ENV_VARS}")
158116

159117
configFileProvider([configFile(fileId: 'maven_settings_spark_deploy_mvn381_above', variable: 'mvn_settings')]) {
160118
sh "cat ${env.mvn_settings} > settings.xml"
161119
}
162-
docker.image(image).inside (
120+
121+
docker.image(IMAGE_NAMES_MAP[yamlCurrentBuildItem.name]).inside (
163122
"-e MAPR_MIRROR=${MAPR_MIRROR} \
164123
-e MAPR_CENTRAL=${MAPR_CENTRAL} \
165124
-e MAVEN_CENTRAL=${MAVEN_CENTRAL} \
@@ -185,7 +144,25 @@ def build(yamlCurrentBuildItem) {
185144
}
186145
}
187146

188-
def getVersionAndUploadToArtifactory() {
189-
def osVersionContainerRaw = sh script: 'cat os_release_version.txt', returnStdout:true
190-
artifactory.uploadToArtifactoryWithOSVersions(ARTIFACTORY_SERVER, osVersionContainerRaw)
147+
def validateBuildImage(yamlCurrentBuildItem) {
148+
def imageStatic = yamlCurrentBuildItem.image
149+
def imageCustom = yamlCurrentBuildItem.imageCustom
150+
def imageName = ""
151+
if (imageStatic) {
152+
imageName = imageStatic.replace("_DOCKER_REGISTRY_", DOCKER_REGISTRY)
153+
}
154+
if (imageCustom) {
155+
if (imageStatic) {
156+
error "You can not specify 'image' and 'imageCustom' options in build-config.yaml"
157+
}
158+
imageName = sh(script: imageCustom, returnStdout: true).trim()
159+
}
160+
IMAGE_NAMES_MAP[yamlCurrentBuildItem.name] = imageName
161+
}
162+
163+
def getVersionAndUploadToArtifactory(yamlCurrentBuildItem) {
164+
stage("Get Version And Upload to Artifactory stage:${yamlCurrentBuildItem.name}") {
165+
def osVersionContainerRaw = sh script: 'cat os_release_version.txt', returnStdout:true
166+
artifactory.uploadToArtifactoryWithOSVersions(ARTIFACTORY_SERVER, osVersionContainerRaw)
167+
}
191168
}

devops/build-config.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ initialReleaseTag: '3.3.3.0-eep-921' # Use only for release build
44
whitesourceScan: true
55
build:
66
- name: ubuntu
7-
imageContext: devops/buildimages/ubuntu/
8-
imageTagScript: devops/buildimages/ubuntu/tag.sh
7+
imageCustom: devops/buildimages/ubuntu/image.sh
98
basicBuildCommands: "_BUILD_ENV_VARS_ devops/scripts/build.sh"
109
hostmachine_jenkins_label: "ubuntu16"
1110
- name: centos
12-
imageContext: devops/buildimages/centos/
13-
imageTagScript: devops/buildimages/centos/tag.sh
11+
imageCustom: devops/buildimages/centos/image.sh
1412
basicBuildCommands: "_BUILD_ENV_VARS_ devops/scripts/build.sh"
1513
hostmachine_jenkins_label: "redhat8"
1614
rpmSign: true

devops/buildimages/centos/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG DOCKER_REGISTRY
2-
FROM ${DOCKER_REGISTRY}/centos8-java11-gcc8
1+
ARG BASE_IMAGE
2+
FROM ${BASE_IMAGE}
33

44
RUN sed -i 's/^mirrorlist/#mirrorlist/' /etc/yum.repos.d/CentOS-* && \
55
sed -i 's/^#baseurl/baseurl/' /etc/yum.repos.d/CentOS-* && \

devops/buildimages/centos/image.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
BASE_IMAGE=${DOCKER_REGISTRY}/centos8-java11-gcc8
3+
BASE_TAG=latest
4+
5+
BASEDIR=$(dirname $0)
6+
DOCKERFILE_CHECKSUM=$(md5sum "${BASEDIR}/Dockerfile" | head -c 7)
7+
8+
IMAGE_NAME_FOR_BUILD=${BASE_IMAGE}-custom-${REPOSITORY_NAME}:${BASE_TAG}-${DOCKERFILE_CHECKSUM}
9+
10+
ensure_image() {
11+
docker image pull -q ${IMAGE_NAME_FOR_BUILD}
12+
retVal=$?
13+
if [ "$retVal" -ne 0 ]; then
14+
docker build -q ${BASEDIR} -f ${BASEDIR}/Dockerfile -t ${IMAGE_NAME_FOR_BUILD} --build-arg BASE_IMAGE=${BASE_IMAGE}:${BASE_TAG}
15+
docker push -q ${IMAGE_NAME_FOR_BUILD}
16+
fi
17+
}
18+
19+
ensure_image >&2
20+
21+
echo ${IMAGE_NAME_FOR_BUILD}

devops/buildimages/centos/tag.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

devops/buildimages/ubuntu/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG DOCKER_REGISTRY
2-
FROM ${DOCKER_REGISTRY}/ubuntu16-java11-gcc7
1+
ARG BASE_IMAGE
2+
FROM ${BASE_IMAGE}
33

44
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 51716619E084DAB9 && \
55
add-apt-repository 'deb [trusted=yes] https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/' && \

devops/buildimages/ubuntu/image.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
BASE_IMAGE=${DOCKER_REGISTRY}/ubuntu16-java11-gcc7
2+
BASE_TAG=latest
3+
4+
BASEDIR=$(dirname $0)
5+
DOCKERFILE_CHECKSUM=$(md5sum "${BASEDIR}/Dockerfile" | head -c 7)
6+
7+
IMAGE_NAME_FOR_BUILD=${BASE_IMAGE}-custom-${REPOSITORY_NAME}:${BASE_TAG}-${DOCKERFILE_CHECKSUM}
8+
9+
ensure_image() {
10+
docker image pull -q ${IMAGE_NAME_FOR_BUILD}
11+
retVal=$?
12+
if [ "$retVal" -ne 0 ]; then
13+
docker build -q ${BASEDIR} -f ${BASEDIR}/Dockerfile -t ${IMAGE_NAME_FOR_BUILD} --build-arg BASE_IMAGE=${BASE_IMAGE}:${BASE_TAG}
14+
docker push -q ${IMAGE_NAME_FOR_BUILD}
15+
fi
16+
}
17+
18+
ensure_image >&2
19+
20+
echo ${IMAGE_NAME_FOR_BUILD}

devops/buildimages/ubuntu/tag.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)