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 Jenkins job for Docker Patch jenkins shared library #3937

Merged
merged 2 commits into from
Sep 5, 2023
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
54 changes: 54 additions & 0 deletions jenkins/docker/docker-re-release.jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
lib = library(identifier: '[email protected]', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
]))

pipeline {
options {
timeout(time: 2, unit: 'HOURS')
}
agent none
parameters {
choice(
name: 'PRODUCT',
peterzhuamazon marked this conversation as resolved.
Show resolved Hide resolved
choices: ['opensearch', 'opensearch-dashboards'],
description: "Choose the product type among OpenSearch / OpenSearch-Dashboards."
)
choice(
name: 'TAG',
choices: ['2', '1'],
description: "Choose the tag of the Product.",
)
}
stages {
stage("Docker re-release") {
agent {
docker {
label 'Jenkins-Agent-Ubuntu2004-X64-M52xlarge-Docker-Builder'
image 'opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.9.1-qemu5.0-awscli1.22-jdk11-v1'
args '-u root -v /var/run/docker.sock:/var/run/docker.sock'
registryUrl 'https://public.ecr.aws/'
alwaysPull true
}
}
stages {
stage('Patch Docker Image') {
steps {
script {
patchDockerImage(
product: "${PRODUCT}",
tag: "${TAG}",
re_release: true
)
}
}
post {
always {
postCleanup()
}
}
}
}
}
}
}
91 changes: 91 additions & 0 deletions tests/jenkins/TestDockerReRelease.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/


import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test
import org.yaml.snakeyaml.Yaml
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString


class TestDockerReRelease extends BuildPipelineTest {

@Override
@Before
void setUp() {

helper.registerSharedLibrary(
library().name('jenkins')
.defaultVersion('5.7.1')
.allowOverride(true)
.implicit(true)
.targetPath('vars')
.retriever(gitSource('https://github.com/opensearch-project/opensearch-build-libraries.git'))
.build()
)
super.setUp()

// Variables
addParam('PRODUCT', 'opensearch')
addParam('TAG', '1')

def inputManifest = "tests/jenkins/data/opensearch-1.3.0.yml"
helper.registerAllowedMethod('readYaml', [Map.class], { args ->
return new Yaml().load((inputManifest as File).text)
})
helper.addShMock("""docker inspect --format '{{ index .Config.Labels "org.label-schema.version"}}' opensearchproject/opensearch:1""") { script ->
return [stdout: "1.3.0", exitValue: 0]
}
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("""docker inspect --format '{{ index .Config.Labels "org.label-schema.version"}}' opensearchproject/opensearch:latest""") { script ->
return [stdout: "2.5.0", exitValue: 0]
}

}

@Test
void testReRelease() {
super.testPipeline('jenkins/docker/docker-re-release.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/docker/docker-re-release.jenkinsfile')
}

@Test
void checkForTriggeredJobs(){
runScript('jenkins/docker/docker-re-release.jenkinsfile')
assertThat(getCommandExecutions('build', ''), hasItem('{job=docker-build, propagate=true, wait=true, parameters=[null, null, null]}'))
assertThat(getCommandExecutions('build', ''), hasItem('{job=docker-scan, propagate=true, wait=true, parameters=[null]}'))
assertThat(getCommandExecutions('build', ''), hasItem('{job=docker-promotion, propagate=true, wait=true, parameters=[null, null, null]}'))

}

def getCommandExecutions(methodName, command) {
def shCommands = helper.callStack.findAll {
call ->
call.methodName == methodName
}.
collect {
call ->
callArgsToString(call)
}.findAll {
shCommand ->
shCommand.contains(command)
}

return shCommands
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
docker-re-release.run()
docker-re-release.modernSCM({$class=GitSCMSource, remote=https://github.com/opensearch-project/opensearch-build-libraries.git})
docker-re-release.library({[email protected], retriever=null})
docker-re-release.pipeline(groovy.lang.Closure)
docker-re-release.timeout({time=2, unit=HOURS})
docker-re-release.echo(Executing on agent [label:none])
docker-re-release.stage(Patch Docker Image, groovy.lang.Closure)
docker-re-release.script(groovy.lang.Closure)
docker-re-release.patchDockerImage({product=opensearch, tag=1, re_release=true})
patchDockerImage.legacySCM(groovy.lang.Closure)
patchDockerImage.library({[email protected], retriever=null})
patchDockerImage.sh(#!/bin/bash
set -e
set +x
docker pull opensearchproject/opensearch:1
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=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})
InputManifest.asBoolean()
patchDockerImage.buildDockerImage({inputManifest=manifests/1.3.0/opensearch-1.3.0.yml, buildNumber=7756, buildDate=20230619, buildOption=re_release_docker_image, artifactUrlX64=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/7756/linux/x64/tar/dist/opensearch/opensearch-1.3.0-linux-x64.tar.gz, artifactUrlArm64=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/7756/linux/arm64/tar/dist/opensearch/opensearch-1.3.0-linux-arm64.tar.gz})
buildDockerImage.legacySCM(groovy.lang.Closure)
buildDockerImage.library({[email protected], retriever=null})
buildDockerImage.readYaml({file=manifests/1.3.0/opensearch-1.3.0.yml})
InputManifest.asBoolean()
buildDockerImage.echo(Triggering docker-build)
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 https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/7756/linux/x64/tar/dist/opensearch/opensearch-1.3.0-linux-x64.tar.gz -o opensearch-x64.tgz && curl -sSL https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/7756/linux/arm64/tar/dist/opensearch/opensearch-1.3.0-linux-arm64.tar.gz -o opensearch-arm64.tgz && bash build-image-multi-arch.sh -v 1.3.0 -f ./dockerfiles/opensearch.al2.dockerfile -p opensearch -a 'x64,arm64' -r opensearchstaging/opensearch -t 'opensearch-x64.tgz,opensearch-arm64.tgz' -n 7756})
buildDockerImage.build({job=docker-build, propagate=true, wait=true, parameters=[null, null, null]})
buildDockerImage.echo(Triggering docker create tag with build number)
buildDockerImage.string({name=SOURCE_IMAGE_REGISTRY, value=opensearchstaging})
buildDockerImage.string({name=SOURCE_IMAGE, value=opensearch:1.3.0})
buildDockerImage.string({name=DESTINATION_IMAGE_REGISTRY, value=opensearchstaging})
buildDockerImage.string({name=DESTINATION_IMAGE, value=opensearch:1.3.0.7756.20230619})
buildDockerImage.build({job=docker-copy, propagate=true, wait=true, parameters=[null, null, null, null]})
buildDockerImage.echo(Triggering docker-scan for opensearch version 1.3.0)
buildDockerImage.string({name=IMAGE_FULL_NAME, value=opensearchstaging/opensearch:1.3.0})
buildDockerImage.build({job=docker-scan, propagate=true, wait=true, parameters=[null]})
patchDockerImage.echo(Triggering docker-promotion)
patchDockerImage.string({name=SOURCE_IMAGES, value=opensearch:1.3.0.7756.20230619})
patchDockerImage.string({name=RELEASE_VERSION, value=1.3.0})
patchDockerImage.booleanParam({name=TAG_LATEST, value=false})
patchDockerImage.build({job=docker-promotion, propagate=true, wait=true, parameters=[null, null, null]})
docker-re-release.postCleanup()
postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true})
Loading