Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add qualifier support for docker build task #1844

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/jenkins/InputManifest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ class InputManifest {
class Build implements Serializable {
String name
String version
String qualifier
String platform
String architecture

Build(Map data) {
this.name = data.name
this.version = data.version
this.qualifier = data.qualifier
this.platform = data.platform
this.architecture = data.architecture
}
Expand Down
11 changes: 11 additions & 0 deletions tests/jenkins/TestBuildDockerImage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,15 @@ class TestBuildDockerImage extends BuildPipelineTest {
"tests/jenkins/jobs/BuildDockerImage_Jenkinsfile_skips_arm64"
)
}

@Test
public void testBuildsQualifierBoth() {
binding.env.ARTIFACT_URL_linux_x64 = 'opensearch.linux.x64'
binding.env.ARTIFACT_URL_linux_arm64 = 'opensearch.linux.arm64'

super.testPipeline(
"tests/jenkins/jobs/BuildDockerImage_Qualifier_Jenkinsfile",
"tests/jenkins/jobs/BuildDockerImage_Qualifier_Jenkinsfile_builds_both"
)
}
}
17 changes: 17 additions & 0 deletions tests/jenkins/data/opensearch-2.0.0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
schema-version: '1.0'
build:
name: OpenSearch
version: 2.0.0
qualifier: alpha1
ci:
image:
name: opensearchstaging/ci-runner:ci-runner-centos7-v1
args: -e JAVA_HOME=/opt/java/openjdk-17
components:
- name: OpenSearch
ref: '2.0'
repository: https://github.com/opensearch-project/OpenSearch.git
checks:
- gradle:publish
- gradle:properties:version
16 changes: 16 additions & 0 deletions tests/jenkins/jobs/BuildDockerImage_Qualifier_Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pipeline {
agent none
stages {
stage('build docker image') {
steps {
script {
buildDockerImage(
inputManifest: 'tests/jenkins/data/opensearch-2.0.0.yml',
artifactUrlX64: env.ARTIFACT_URL_linux_x64,
artifactUrlArm64: env.ARTIFACT_URL_linux_arm64
)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BuildDockerImage_Qualifier_Jenkinsfile.run()
BuildDockerImage_Qualifier_Jenkinsfile.pipeline(groovy.lang.Closure)
BuildDockerImage_Qualifier_Jenkinsfile.echo(Executing on agent [label:none])
BuildDockerImage_Qualifier_Jenkinsfile.stage(build docker image, groovy.lang.Closure)
BuildDockerImage_Qualifier_Jenkinsfile.script(groovy.lang.Closure)
BuildDockerImage_Qualifier_Jenkinsfile.buildDockerImage({inputManifest=tests/jenkins/data/opensearch-2.0.0.yml, artifactUrlX64=opensearch.linux.x64, artifactUrlArm64=opensearch.linux.arm64})
buildDockerImage.git({url=https://github.com/opensearch-project/opensearch-build.git, branch=main})
buildDockerImage.legacySCM(groovy.lang.Closure)
buildDockerImage.library({identifier=jenkins@20211123, retriever=null})
buildDockerImage.readYaml({file=tests/jenkins/data/opensearch-2.0.0.yml})
InputManifest.asBoolean()
buildDockerImage.string({name=DOCKER_BUILD_GIT_REPOSITORY, value=https://github.com/opensearch-project/opensearch-build})
buildDockerImage.string({name=DOCKER_BUILD_GIT_REPOSITORY_REFERENCE, value=main})
buildDockerImage.string({name=DOCKER_BUILD_SCRIPT_WITH_COMMANDS, value=id && pwd && cd docker/release && curl -sSL opensearch.linux.x64 -o opensearch-x64.tgz && curl -sSL opensearch.linux.arm64 -o opensearch-arm64.tgz && bash build-image-multi-arch.sh -v 2.0.0-alpha1 -f ./dockerfiles/opensearch.al2.dockerfile -p opensearch -a 'x64,arm64' -r opensearchstaging/opensearch -t 'opensearch-x64.tgz,opensearch-arm64.tgz' -n 33})
buildDockerImage.booleanParam({name=IS_STAGING, value=true})
buildDockerImage.build({job=docker-build, parameters=[null, null, null, null]})
11 changes: 9 additions & 2 deletions vars/buildDockerImage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ void call(Map args = [:]) {

def lib = library(identifier: 'jenkins@20211123', retriever: legacySCM(scm))
def inputManifest = lib.jenkins.InputManifest.new(readYaml(file: args.inputManifest))
def build_qualifier = inputManifest.build.qualifier

if (build_qualifier != null && build_qualifier != 'null') {
build_qualifier = "-" + build_qualifier
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move else up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should just default build_qualifier to null and check inputmanifest.build.qualifier.
Will change in a later improvement.

else {
build_qualifier = ''
}
String filename = inputManifest.build.getFilename()

if (args.artifactUrlX64 == null || args.artifactUrlArm64 == null) {
Expand All @@ -23,7 +30,7 @@ void call(Map args = [:]) {
[
'bash',
'build-image-multi-arch.sh',
"-v ${inputManifest.build.version}",
"-v ${inputManifest.build.version}${build_qualifier}",
peterzhuamazon marked this conversation as resolved.
Show resolved Hide resolved
"-f ./dockerfiles/${filename}.al2.dockerfile",
"-p ${filename}",
"-a 'x64,arm64'",
Expand All @@ -36,4 +43,4 @@ void call(Map args = [:]) {
]
}
}
}
}