From fd024c91392f872e22a7c118209cf33be8dea324 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Wed, 20 Oct 2021 10:41:05 -0400 Subject: [PATCH] Switching to multi-JDK image, enriching build manifest with desired JDK version Signed-off-by: Andriy Redko --- jenkins/opensearch/Jenkinsfile | 42 +++++++++++++++++++++------- manifests/1.0.0/opensearch-1.0.0.yml | 1 + manifests/1.0.1/opensearch-1.0.1.yml | 1 + manifests/1.1.0/opensearch-1.1.0.yml | 1 + manifests/1.2.0/opensearch-1.2.0.yml | 1 + manifests/2.0.0/opensearch-2.0.0.yml | 1 + src/manifests/input_manifest.py | 4 ++- 7 files changed, 40 insertions(+), 11 deletions(-) diff --git a/jenkins/opensearch/Jenkinsfile b/jenkins/opensearch/Jenkinsfile index ee84758efc..799bc40a23 100644 --- a/jenkins/opensearch/Jenkinsfile +++ b/jenkins/opensearch/Jenkinsfile @@ -21,6 +21,22 @@ pipeline { } } } + stage('detect JDK version to build') { + steps { + script { + manifest = readYaml(file: "manifests/$INPUT_MANIFEST") + + jdk = "${manifest.build.jdk}" + // If the 'jdk' key is not present, it is populated with "null" string + if (jdk == null || jdk == "null") { + // If JDK is not set, use 14 + jdk = "14" + } + + echo "Using JDK version: " + jdk + } + } + } stage('build') { parallel { stage('build-snapshots') { @@ -30,19 +46,21 @@ pipeline { agent { docker { label 'Jenkins-Agent-al2-x64-c54xlarge-Docker-Host' - image 'opensearchstaging/ci-runner:centos7-x64-arm64-jdk14-node10.24.1-cypress6.9.1-20211005' + image 'opensearchstaging/ci-runner:centos7-x64-arm64-jdkmulti-node10.24.1-cypress6.9.1-20211019' // Unlike freestyle docker, pipeline docker does not login to the container and run commands // It use executes which does not source the docker container internal ENV VAR - args '-e JAVA_HOME=/usr/lib/jvm/adoptopenjdk-14-hotspot' + args '-e JAVA_HOME=$JAVA' + jdk + '_HOME' alwaysPull true } } steps { script { - git url: 'https://github.com/opensearch-project/opensearch-build.git', branch: 'main' - sh "./build.sh manifests/$INPUT_MANIFEST --snapshot" - withCredentials([usernamePassword(credentialsId: 'Sonatype', usernameVariable: 'SONATYPE_USERNAME', passwordVariable: 'SONATYPE_PASSWORD')]) { - sh('$WORKSPACE/publish/publish-snapshot.sh $WORKSPACE/artifacts/$ARTIFACT_PATH/maven') + withEnv(['JAVA_HOME=$JAVA' + jdk + '_HOME']) { + git url: 'https://github.com/opensearch-project/opensearch-build.git', branch: 'main' + sh "./build.sh manifests/$INPUT_MANIFEST --snapshot" + withCredentials([usernamePassword(credentialsId: 'Sonatype', usernameVariable: 'SONATYPE_USERNAME', passwordVariable: 'SONATYPE_PASSWORD')]) { + sh('$WORKSPACE/publish/publish-snapshot.sh $WORKSPACE/artifacts/$ARTIFACT_PATH/maven') + } } } } @@ -56,7 +74,7 @@ pipeline { agent { docker { label 'Jenkins-Agent-al2-x64-c54xlarge-Docker-Host' - image 'opensearchstaging/ci-runner:centos7-x64-arm64-jdk14-node10.24.1-cypress6.9.1-20211005' + image 'opensearchstaging/ci-runner:centos7-x64-arm64-jdkmulti-node10.24.1-cypress6.9.1-20211019' // Unlike freestyle docker, pipeline docker does not login to the container and run commands // It use executes which does not source the docker container internal ENV VAR args '-e JAVA_HOME=/usr/lib/jvm/adoptopenjdk-14-hotspot' @@ -65,7 +83,9 @@ pipeline { } steps { script { - build() + withEnv(['JAVA_HOME=$JAVA' + jdk + '_HOME']) { + build() + } } } post() { @@ -78,7 +98,7 @@ pipeline { agent { docker { label 'Jenkins-Agent-al2-arm64-c6g4xlarge-Docker-Host' - image 'opensearchstaging/ci-runner:centos7-x64-arm64-jdk14-node10.24.1-cypress6.9.1-20211005' + image 'opensearchstaging/ci-runner:centos7-x64-arm64-jdkmulti-node10.24.1-cypress6.9.1-20211019' // Unlike freestyle docker, pipeline docker does not login to the container and run commands // It use executes which does not source the docker container internal ENV VAR args '-e JAVA_HOME=/usr/lib/jvm/adoptopenjdk-14-hotspot' @@ -87,7 +107,9 @@ pipeline { } steps { script { - build() + withEnv(['JAVA_HOME=$JAVA' + jdk + '_HOME']) { + build() + } } } post() { diff --git a/manifests/1.0.0/opensearch-1.0.0.yml b/manifests/1.0.0/opensearch-1.0.0.yml index 845783f767..a272c27042 100644 --- a/manifests/1.0.0/opensearch-1.0.0.yml +++ b/manifests/1.0.0/opensearch-1.0.0.yml @@ -3,6 +3,7 @@ schema-version: "1.0" build: name: OpenSearch version: "1.0.0" + jdk: "14" components: - name: OpenSearch repository: https://github.com/opensearch-project/OpenSearch.git diff --git a/manifests/1.0.1/opensearch-1.0.1.yml b/manifests/1.0.1/opensearch-1.0.1.yml index 73233c09c4..bf0185f25f 100644 --- a/manifests/1.0.1/opensearch-1.0.1.yml +++ b/manifests/1.0.1/opensearch-1.0.1.yml @@ -3,6 +3,7 @@ schema-version: "1.0" build: name: OpenSearch version: 1.0.1 + jdk: "14" components: - name: OpenSearch repository: https://github.com/opensearch-project/OpenSearch.git diff --git a/manifests/1.1.0/opensearch-1.1.0.yml b/manifests/1.1.0/opensearch-1.1.0.yml index 03b808f3ac..d5ce9a87f6 100644 --- a/manifests/1.1.0/opensearch-1.1.0.yml +++ b/manifests/1.1.0/opensearch-1.1.0.yml @@ -3,6 +3,7 @@ schema-version: "1.0" build: name: OpenSearch version: 1.1.0 + jdk: "14" components: - name: OpenSearch repository: https://github.com/opensearch-project/OpenSearch.git diff --git a/manifests/1.2.0/opensearch-1.2.0.yml b/manifests/1.2.0/opensearch-1.2.0.yml index 87f358a8ae..683256dd25 100644 --- a/manifests/1.2.0/opensearch-1.2.0.yml +++ b/manifests/1.2.0/opensearch-1.2.0.yml @@ -3,6 +3,7 @@ schema-version: "1.0" build: name: OpenSearch version: 1.2.0 + jdk: "14" components: - name: OpenSearch repository: https://github.com/opensearch-project/OpenSearch.git diff --git a/manifests/2.0.0/opensearch-2.0.0.yml b/manifests/2.0.0/opensearch-2.0.0.yml index 9ec95c019a..cd651fde5c 100644 --- a/manifests/2.0.0/opensearch-2.0.0.yml +++ b/manifests/2.0.0/opensearch-2.0.0.yml @@ -1,6 +1,7 @@ build: name: OpenSearch version: 2.0.0 + jdk: "11" components: - name: OpenSearch ref: main diff --git a/src/manifests/input_manifest.py b/src/manifests/input_manifest.py index 45c08b7295..85884208b0 100644 --- a/src/manifests/input_manifest.py +++ b/src/manifests/input_manifest.py @@ -36,6 +36,7 @@ class InputManifest(Manifest): "schema": { "name": {"required": True, "type": "string"}, "version": {"required": True, "type": "string"}, + "jdk": {"required": False, "type": "string"}, }, }, "schema-version": {"required": True, "type": "string", "allowed": ["1.0"]}, @@ -74,9 +75,10 @@ class Build: def __init__(self, data): self.name = data["name"] self.version = data["version"] + self.jdk = data.get("jdk", None) def __to_dict__(self): - return {"name": self.name, "version": self.version} + return {"name": self.name, "version": self.version, "jdk": self.jdk} class Component: def __init__(self, data):