Skip to content

Commit

Permalink
Change the name of the newly built docker image in dockerPatch library (
Browse files Browse the repository at this point in the history
#346)

Signed-off-by: Divya Madala <[email protected]>
  • Loading branch information
Divyaasm authored Oct 31, 2023
1 parent cfaa0f3 commit 050b31a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 34 deletions.
4 changes: 1 addition & 3 deletions tests/jenkins/TestPatchDockerImage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class TestPatchDockerImage extends BuildPipelineTest {
void setUp() {
this.registerLibTester(new PatchDockerImageLibTester(
'opensearch',
'1',
'true'
)
'1' )
)
super.setUp()
}
Expand Down
3 changes: 1 addition & 2 deletions tests/jenkins/jobs/PatchDockerImage_Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ pipeline {
script {
patchDockerImage(
product: "opensearch",
tag: "1",
re_release: "true"
tag: "1"
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/jenkins/jobs/PatchDockerImage_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PatchDockerImage_Jenkinsfile.echo(Executing on agent [label:none])
PatchDockerImage_Jenkinsfile.stage(Patch docker image, groovy.lang.Closure)
PatchDockerImage_Jenkinsfile.script(groovy.lang.Closure)
PatchDockerImage_Jenkinsfile.patchDockerImage({product=opensearch, tag=1, re_release=true})
PatchDockerImage_Jenkinsfile.patchDockerImage({product=opensearch, tag=1})
patchDockerImage.legacySCM(groovy.lang.Closure)
patchDockerImage.library({identifier=jenkins@main, retriever=null})
patchDockerImage.sh(#!/bin/bash
Expand All @@ -13,7 +13,7 @@
docker pull opensearchproject/opensearch:latest
)
patchDockerImage.sh({script=docker inspect --format '{{ index .Config.Labels "org.label-schema.version"}}' opensearchproject/opensearch:1, returnStdout=true})
patchDockerImage.sh({script=docker inspect --format '{{ index .Config.Labels "org.label-schema.build-date"}}' opensearchproject/opensearch:1, returnStdout=true})
patchDockerImage.sh({script=date +%Y%m%d, returnStdout=true})
patchDockerImage.sh({script=docker inspect --format '{{ index .Config.Labels "org.label-schema.description"}}' opensearchproject/opensearch:1, returnStdout=true})
patchDockerImage.sh({script=docker inspect --format '{{ index .Config.Labels "org.label-schema.version"}}' opensearchproject/opensearch:latest, returnStdout=true})
patchDockerImage.readYaml({file=manifests/1.3.0/opensearch-1.3.0.yml})
Expand Down
8 changes: 3 additions & 5 deletions tests/jenkins/lib-testers/PatchDockerImageLibtester.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ class PatchDockerImageLibTester extends LibFunctionTester {

private String product
private String tag
private String re_release

public PatchDockerImageLibTester(product, tag, re_release){
public PatchDockerImageLibTester(product, tag){
this.product = product
this.tag = tag
this.re_release = re_release
}

void configure(helper, binding) {
Expand All @@ -34,8 +32,8 @@ class PatchDockerImageLibTester extends LibFunctionTester {
helper.addShMock("""docker inspect --format '{{ index .Config.Labels "org.label-schema.description"}}' opensearchproject/opensearch:1""") { script ->
return [stdout: "7756", exitValue: 0]
}
helper.addShMock("""docker inspect --format '{{ index .Config.Labels "org.label-schema.build-date"}}' opensearchproject/opensearch:1""") { script ->
return [stdout: "2023-06-19T19:12:59Z", exitValue: 0]
helper.addShMock("""date +%Y%m%d""") { script ->
return [stdout: "20230619", exitValue: 0]
}
helper.addShMock("""docker inspect --format '{{ index .Config.Labels "org.label-schema.version"}}' opensearchproject/opensearch:latest""") { script ->
return [stdout: "2.5.0", exitValue: 0]
Expand Down
34 changes: 12 additions & 22 deletions vars/patchDockerImage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
Library to support Docker Image Re-Release Automation
@param Map[product] <Required> - Product type refers to opensearch or opensearch-dashboards.
@param Map[tag] <Required> - Tag of the product that needs to be re-released.
@param Map[re_release] <Optional> - This Build-Option can be checked to release the image after Docker-Build.
*/
void call(Map args = [:]) {
def lib = library(identifier: 'jenkins@main', retriever: legacySCM(scm))
String docker_image = "opensearchproject/${args.product}:${args.tag}"
String latest_docker_image = "opensearchproject/${args.product}:latest"
boolean tag_latest = false
String build_option = "build_docker_image"
String build_option = "re_release_docker_image"

sh """#!/bin/bash
set -e
Expand All @@ -31,8 +30,8 @@ void call(Map args = [:]) {
script: """docker inspect --format '{{ index .Config.Labels "org.label-schema.version"}}' ${docker_image}""",
returnStdout: true
).trim()
def build_time = sh (
script: """docker inspect --format '{{ index .Config.Labels "org.label-schema.build-date"}}' ${docker_image}""",
def build_date = sh (
script: """date +%Y%m%d""",
returnStdout: true
).trim()
def build_number = sh (
Expand All @@ -50,9 +49,6 @@ void call(Map args = [:]) {

artifactUrlARM64 = "https://ci.opensearch.org/ci/dbc/distribution-build-${args.product}/${version}/${build_number}/linux/arm64/tar/dist/${args.product}/${args.product}-${version}-linux-arm64.tar.gz"

//slice the build-date value (For Example: 2023-08-11T02:17:43Z -> 20230811)
build_date = build_time[0..3] + build_time[5..6] + build_time[8..9]

def build_qualifier = inputManifest.build.qualifier

if (build_qualifier != null && build_qualifier != 'null') {
Expand All @@ -66,10 +62,6 @@ void call(Map args = [:]) {
tag_latest = true
}

if (args.re_release){
build_option = "re_release_docker_image"
}

buildDockerImage(
inputManifest: "manifests/${version}/${args.product}-${version}.yml",
buildNumber: "${build_number}",
Expand All @@ -80,16 +72,14 @@ void call(Map args = [:]) {
)

echo 'Triggering docker-promotion'
if(args.re_release){
dockerPromote: {
build job: 'docker-promotion',
propagate: true,
wait: true,
parameters: [
string(name: 'SOURCE_IMAGES', value: "${args.product}:${inputManifest.build.version}${build_qualifier}.${build_number}.${build_date}"),
string(name: 'RELEASE_VERSION', value: "${version}"),
booleanParam(name: 'TAG_LATEST', value: "${tag_latest}")
]
}
dockerPromote: {
build job: 'docker-promotion',
propagate: true,
wait: true,
parameters: [
string(name: 'SOURCE_IMAGES', value: "${args.product}:${inputManifest.build.version}${build_qualifier}.${build_number}.${build_date}"),
string(name: 'RELEASE_VERSION', value: "${version}"),
booleanParam(name: 'TAG_LATEST', value: "${tag_latest}")
]
}
}

0 comments on commit 050b31a

Please sign in to comment.