Skip to content
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
86 changes: 86 additions & 0 deletions jenkins/promotion/promote-docker-ecr.jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
lib = library(identifier: 'jenkins@20211123', retriever: legacySCM(scm))

pipeline {
options {
timeout(time: 1, unit: 'HOURS')
}
agent {
docker {
label 'Jenkins-Agent-al2-x64-c54xlarge-Docker-Host'
image 'opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.6.3-qemu5.0-awscli1.22-jdk11-v2'
args '-u root -v /var/run/docker.sock:/var/run/docker.sock'
}
}
parameters {
string(
name: 'SOURCE_IMAGES',
description: 'Comma separated list of product with its image tag that we want to promote from staging to production. E.g.: opensearch:2.0.1.3910, opensearch-dashboards:2.0.1, data-prepper:1.5.0-19.',
trim: true
)
string(
name: 'RELEASE_VERSION',
description: 'Official release version on production repository. This is uniform for all source images. E.g.: 2.0.1, 1.5.0.',
trim: true
)
booleanParam(
name: 'DOCKER_HUB_PROMOTE',
defaultValue: true,
description: 'Promote SOURCE_IMAGES to `opensearchproject` production Docker Hub.'
)
booleanParam(
name: 'ECR_PROMOTE',
defaultValue: true,
description: 'Promote SOURCE_IMAGES to `gallery.ecr.aws/opensearchproject` production ECR repository.'
)
booleanParam(
name: 'TAG_LATEST',
defaultValue: true,
description: 'Tag the copied image as latest'
)
booleanParam(
name: 'TAG_MAJOR_VERSION',
defaultValue: true,
description: 'Tag the copied image with its major version. E.g.: 1.3.2 image will be tagged with 1 in the hub.'
)
}

stages {
stage('Parameters Check') {
steps {
script {
currentBuild.description = "Promoting ${SOURCE_IMAGES} to production hub."
if(SOURCE_IMAGES.isEmpty() || RELEASE_VERSION.isEmpty()) {
currentBuild.result = 'ABORTED'
error('Make sure at lease one product is added to be promoted with proper release version.')
}
}
}
}
stage('image-promote-to-prod') {
steps {
script {
for (product in SOURCE_IMAGES.split(',')) {
def productRepo = product.trim()
println("Promoting \"$productRepo\" from staging to production.")
promoteContainer(
imageRepository: productRepo,
version: RELEASE_VERSION,
dockerPromote: DOCKER_HUB_PROMOTE,
ecrPromote: ECR_PROMOTE,
latestTag: TAG_LATEST,
majorVersionTag: TAG_MAJOR_VERSION
)
}
}
}
}
}
post() {
always {
script {
postCleanup()
sh "docker logout"
}
}
}
}
2 changes: 1 addition & 1 deletion tests/jenkins/TestCopyContainer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestCopyContainer extends BuildPipelineTest {
binding.setVariable('ARTIFACT_PROMOTION_ROLE_NAME', 'sample-agent-AssumeRole')
binding.setVariable('AWS_ACCOUNT_ARTIFACT', '1234567890')
binding.setVariable('DATA_PREPPER_STAGING_CONTAINER_REPOSITORY', 'sample_dataprepper_ecr_url')
helper.registerAllowedMethod('withAWS', [Map, Closure], null)
helper.registerAllowedMethod('withAWS', [Map, Closure], null)
super.setUp()

}
Expand Down
116 changes: 116 additions & 0 deletions tests/jenkins/TestPromoteContainer.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test

class TestPromoteContainer extends BuildPipelineTest {

String PROMOTE_PRODUCT = 'opensearch:2.0.1.2901, opensearch-dashboards:2.0.1-2345, data-prepper:2.0.1.123'
String RELEASE_VERSION = '2.0.1'

@Before
void setUp() {
binding.setVariable('SOURCE_IMAGES', PROMOTE_PRODUCT)
binding.setVariable('RELEASE_VERSION', RELEASE_VERSION)
binding.setVariable('DOCKER_USERNAME', 'dummy_docker_username')
binding.setVariable('DOCKER_PASSWORD', 'dummy_docker_password')
binding.setVariable('ARTIFACT_PROMOTION_ROLE_NAME', 'dummy-agent-AssumeRole')
binding.setVariable('AWS_ACCOUNT_ARTIFACT', '1234567890')
binding.setVariable('DATA_PREPPER_STAGING_CONTAINER_REPOSITORY', 'dummy_dataprepper_ecr_url')


helper.registerAllowedMethod('withAWS', [Map, Closure], null)
super.setUp()

}

@Test
public void testPromoteContainerToDocker() {
String dockerPromote = true
String ecrPromote = false
String latestBoolean = false
String majorVersionBoolean = false
binding.setVariable('DOCKER_HUB_PROMOTE', dockerPromote)
binding.setVariable('ECR_PROMOTE', ecrPromote)
binding.setVariable('TAG_LATEST', latestBoolean)
binding.setVariable('TAG_MAJOR_VERSION', majorVersionBoolean)

super.testPipeline("jenkins/promotion/promote-docker-ecr.jenkinsfile",
"tests/jenkins/jenkinsjob-regression-files/promotion/promote-container/promote-container-testPromoteContainerToDocker.jenkinsfile")
}

@Test
public void testPromoteContainerToDockerLatest() {
String dockerPromote = true
String ecrPromote = false
String latestBoolean = true
String majorVersionBoolean = false
binding.setVariable('DOCKER_HUB_PROMOTE', dockerPromote)
binding.setVariable('ECR_PROMOTE', ecrPromote)
binding.setVariable('TAG_LATEST', latestBoolean)
binding.setVariable('TAG_MAJOR_VERSION', majorVersionBoolean)

super.testPipeline("jenkins/promotion/promote-docker-ecr.jenkinsfile",
"tests/jenkins/jenkinsjob-regression-files/promotion/promote-container/promote-container-testPromoteContainerToDockerLatest.jenkinsfile")
}

@Test
public void testPromoteContainerToDockerMajor() {
String dockerPromote = true
String ecrPromote = false
String latestBoolean = false
String majorVersionBoolean = true
binding.setVariable('DOCKER_HUB_PROMOTE', dockerPromote)
binding.setVariable('ECR_PROMOTE', ecrPromote)
binding.setVariable('TAG_LATEST', latestBoolean)
binding.setVariable('TAG_MAJOR_VERSION', majorVersionBoolean)

super.testPipeline("jenkins/promotion/promote-docker-ecr.jenkinsfile",
"tests/jenkins/jenkinsjob-regression-files/promotion/promote-container/promote-container-testPromoteContainerToDockerMajor.jenkinsfile")
}

@Test
public void testPromoteContainerToDockerLatestMajor() {
String dockerPromote = true
String ecrPromote = false
String latestBoolean = true
String majorVersionBoolean = true
binding.setVariable('DOCKER_HUB_PROMOTE', dockerPromote)
binding.setVariable('ECR_PROMOTE', ecrPromote)
binding.setVariable('TAG_LATEST', latestBoolean)
binding.setVariable('TAG_MAJOR_VERSION', majorVersionBoolean)

super.testPipeline("jenkins/promotion/promote-docker-ecr.jenkinsfile",
"tests/jenkins/jenkinsjob-regression-files/promotion/promote-container/promote-container-testPromoteContainerToDockerLatestMajor.jenkinsfile")
}

@Test
public void testPromoteContainerToECRLatestMajor() {
String dockerPromote = false
String ecrPromote = true
String latestBoolean = true
String majorVersionBoolean = true
binding.setVariable('DOCKER_HUB_PROMOTE', dockerPromote)
binding.setVariable('ECR_PROMOTE', ecrPromote)
binding.setVariable('TAG_LATEST', latestBoolean)
binding.setVariable('TAG_MAJOR_VERSION', majorVersionBoolean)

super.testPipeline("jenkins/promotion/promote-docker-ecr.jenkinsfile",
"tests/jenkins/jenkinsjob-regression-files/promotion/promote-container/promote-container-testPromoteContainerToECRLatestMajor.jenkinsfile")
}

@Test
public void testPromoteContainerToDockerECRLatestMajor() {
String dockerPromote = true
String ecrPromote = true
String latestBoolean = true
String majorVersionBoolean = true
binding.setVariable('DOCKER_HUB_PROMOTE', dockerPromote)
binding.setVariable('ECR_PROMOTE', ecrPromote)
binding.setVariable('TAG_LATEST', latestBoolean)
binding.setVariable('TAG_MAJOR_VERSION', majorVersionBoolean)

super.testPipeline("jenkins/promotion/promote-docker-ecr.jenkinsfile",
"tests/jenkins/jenkinsjob-regression-files/promotion/promote-container/promote-container-testPromoteContainerToDockerECRLatestMajor.jenkinsfile")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
promote-docker-ecr.run()
promote-docker-ecr.legacySCM(groovy.lang.Closure)
promote-docker-ecr.library({identifier=jenkins@20211123, retriever=null})
promote-docker-ecr.pipeline(groovy.lang.Closure)
promote-docker-ecr.timeout({time=1, unit=HOURS})
promote-docker-ecr.echo(Executing on agent [docker:[image:opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.6.3-qemu5.0-awscli1.22-jdk11-v2, reuseNode:false, stages:[:], args:-u root -v /var/run/docker.sock:/var/run/docker.sock, alwaysPull:false, containerPerStageRoot:false, label:Jenkins-Agent-al2-x64-c54xlarge-Docker-Host]])
promote-docker-ecr.stage(Parameters Check, groovy.lang.Closure)
promote-docker-ecr.script(groovy.lang.Closure)
promote-docker-ecr.stage(image-promote-to-prod, groovy.lang.Closure)
promote-docker-ecr.script(groovy.lang.Closure)
promote-docker-ecr.promoteContainer({imageRepository=opensearch:2.0.1.2901, version=2.0.1, dockerPromote=true, ecrPromote=false, latestTag=false, majorVersionTag=false})
promoteContainer.string({name=SOURCE_IMAGE_REGISTRY, value=opensearchstaging})
promoteContainer.string({name=SOURCE_IMAGE, value=opensearch:2.0.1.2901})
promoteContainer.string({name=DESTINATION_IMAGE_REGISTRY, value=opensearchproject})
promoteContainer.string({name=DESTINATION_IMAGE, value=opensearch:2.0.1})
promoteContainer.build({job=docker-copy, parameters=[null, null, null, null]})
promote-docker-ecr.promoteContainer({imageRepository=opensearch-dashboards:2.0.1-2345, version=2.0.1, dockerPromote=true, ecrPromote=false, latestTag=false, majorVersionTag=false})
promoteContainer.string({name=SOURCE_IMAGE_REGISTRY, value=opensearchstaging})
promoteContainer.string({name=SOURCE_IMAGE, value=opensearch-dashboards:2.0.1-2345})
promoteContainer.string({name=DESTINATION_IMAGE_REGISTRY, value=opensearchproject})
promoteContainer.string({name=DESTINATION_IMAGE, value=opensearch-dashboards:2.0.1})
promoteContainer.build({job=docker-copy, parameters=[null, null, null, null]})
promote-docker-ecr.promoteContainer({imageRepository=data-prepper:2.0.1.123, version=2.0.1, dockerPromote=true, ecrPromote=false, latestTag=false, majorVersionTag=false})
promoteContainer.string({name=SOURCE_IMAGE_REGISTRY, value=dummy_dataprepper_ecr_url})
promoteContainer.string({name=SOURCE_IMAGE, value=data-prepper:2.0.1.123})
promoteContainer.string({name=DESTINATION_IMAGE_REGISTRY, value=opensearchproject})
promoteContainer.string({name=DESTINATION_IMAGE, value=data-prepper:2.0.1})
promoteContainer.build({job=docker-copy, parameters=[null, null, null, null]})
promote-docker-ecr.script(groovy.lang.Closure)
promote-docker-ecr.postCleanup()
postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true})
promote-docker-ecr.sh(docker logout)
Loading