-
Notifications
You must be signed in to change notification settings - Fork 277
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
Create a docker promotion jenkins workflow #2288
Merged
peterzhuamazon
merged 7 commits into
opensearch-project:main
from
zelinh:docker-promotion
Jul 7, 2022
+662
−1
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
00dd33a
Add docker promotion jenkins jobs
zelinh 76e7f59
Merge remote-tracking branch 'upstream/main' into docker-promotion
zelinh 303a2be
Create a Jenkins workflow for docker promotion job
zelinh c179be8
Fix promoting product with its individual image tag
zelinh 716432a
Add data prepper into tests
zelinh 8829ac2
Convert to use docker copy job
zelinh f06a4fa
Update test cases
zelinh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 'PROMOTE_PRODUCT', | ||
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-prepper1.5.0-19.', | ||
trim: true | ||
) | ||
string( | ||
name: 'RELEASE_VERSION', | ||
description: 'Official release version on production repository. E.g.: 2.0.1, 1.5.0.', | ||
trim: true | ||
) | ||
booleanParam( | ||
name: 'DOCKER_HUB_PROMOTE', | ||
defaultValue: true, | ||
description: 'Promote the staging images to Docker Hub with the tag choices.' | ||
) | ||
booleanParam( | ||
name: 'ECR_PROMOTE', | ||
defaultValue: true, | ||
description: 'Promote the staging images to ECR with the tag choices.' | ||
) | ||
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 to be on the latest image for any build within 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 ${PROMOTE_PRODUCT} to production hub." | ||
if(PROMOTE_PRODUCT.isEmpty()) { | ||
currentBuild.result = 'ABORTED' | ||
error('Make sure at lease one product is added to be promoted.') | ||
} | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also make sure any string parameters requires non-empty inputs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add additional checks for |
||
stage('image-promote-to-prod') { | ||
steps { | ||
script { | ||
for (product in PROMOTE_PRODUCT.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('PROMOTE_PRODUCT', 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") | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...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,41 @@ | ||
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.copyContainer({sourceImage=opensearch:2.0.1.2901, sourceRegistry=opensearchstaging, destinationImage=opensearch:2.0.1, destinationRegistry=opensearchproject}) | ||
copyContainer.usernamePassword({credentialsId=jenkins-production-dockerhub-credential, usernameVariable=DOCKER_USERNAME, passwordVariable=DOCKER_PASSWORD}) | ||
copyContainer.withCredentials([[DOCKER_USERNAME, DOCKER_PASSWORD]], groovy.lang.Closure) | ||
copyContainer.sh({returnStdout=true, script=echo DOCKER_PASSWORD | docker login --username DOCKER_USERNAME --password-stdin}) | ||
copyContainer.sh( | ||
gcrane cp opensearchstaging/opensearch:2.0.1.2901 opensearchproject/opensearch:2.0.1 | ||
docker logout | ||
) | ||
promote-docker-ecr.promoteContainer({imageRepository=opensearch-dashboards:2.0.1-2345, version=2.0.1, dockerPromote=true, ecrPromote=false, latestTag=false, majorVersionTag=false}) | ||
promoteContainer.copyContainer({sourceImage=opensearch-dashboards:2.0.1-2345, sourceRegistry=opensearchstaging, destinationImage=opensearch-dashboards:2.0.1, destinationRegistry=opensearchproject}) | ||
copyContainer.usernamePassword({credentialsId=jenkins-production-dockerhub-credential, usernameVariable=DOCKER_USERNAME, passwordVariable=DOCKER_PASSWORD}) | ||
copyContainer.withCredentials([[DOCKER_USERNAME, DOCKER_PASSWORD]], groovy.lang.Closure) | ||
copyContainer.sh({returnStdout=true, script=echo DOCKER_PASSWORD | docker login --username DOCKER_USERNAME --password-stdin}) | ||
copyContainer.sh( | ||
gcrane cp opensearchstaging/opensearch-dashboards:2.0.1-2345 opensearchproject/opensearch-dashboards:2.0.1 | ||
docker logout | ||
) | ||
promote-docker-ecr.promoteContainer({imageRepository=data-prepper:2.0.1.123, version=2.0.1, dockerPromote=true, ecrPromote=false, latestTag=false, majorVersionTag=false}) | ||
promoteContainer.copyContainer({sourceImage=data-prepper:2.0.1.123, sourceRegistry=dummy_dataprepper_ecr_url, destinationImage=data-prepper:2.0.1, destinationRegistry=opensearchproject}) | ||
copyContainer.usernamePassword({credentialsId=jenkins-production-dockerhub-credential, usernameVariable=DOCKER_USERNAME, passwordVariable=DOCKER_PASSWORD}) | ||
copyContainer.withCredentials([[DOCKER_USERNAME, DOCKER_PASSWORD]], groovy.lang.Closure) | ||
copyContainer.sh({returnStdout=true, script=echo DOCKER_PASSWORD | docker login --username DOCKER_USERNAME --password-stdin}) | ||
copyContainer.sh( | ||
gcrane cp dummy_dataprepper_ecr_url/data-prepper:2.0.1.123 opensearchproject/data-prepper:2.0.1 | ||
docker logout | ||
) | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please give proper naming to these params, they are confusing at best for anyone that is not familiar with the release processes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the wording for these params.