-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a docker promotion jenkins workflow (#2288)
* Add docker promotion jenkins jobs Signed-off-by: Zelin Hao <zelinhao@amazon.com> * Create a Jenkins workflow for docker promotion job Signed-off-by: Zelin Hao <zelinhao@amazon.com> * Fix promoting product with its individual image tag Signed-off-by: Zelin Hao <zelinhao@amazon.com> * Add data prepper into tests Signed-off-by: Zelin Hao <zelinhao@amazon.com> * Convert to use docker copy job Signed-off-by: Zelin Hao <zelinhao@amazon.com> * Update test cases Signed-off-by: Zelin Hao <zelinhao@amazon.com>
- Loading branch information
Showing
10 changed files
with
662 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...romotion/promote-container/promote-container-testPromoteContainerToDocker.jenkinsfile.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.