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 docker login for both source and dest registries #249

Merged
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jacocoTestReport {
}
}

String version = '5.1.0'
String version = '5.2.0'

task updateVersion {
doLast {
Expand Down
4 changes: 2 additions & 2 deletions tests/jenkins/TestCopyContainer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TestCopyContainer extends BuildPipelineTest {
String craneStr = 'set -x && crane cp opensearchstaging/ci-runner:centos7-123 public.ecr.aws/opensearchstaging/ci-runner:centos7-123'
assertThat(getShellCommands('sh', 'crane'), hasItem(craneStr))

String dockerStr = 'set +x && docker logout && docker logout public.ecr.aws/opensearchstaging'
String dockerStr = 'set +x && docker logout && docker logout public.ecr.aws'
assertThat(getShellCommands('sh', 'docker logout'), hasItem(dockerStr))
}

Expand All @@ -54,7 +54,7 @@ class TestCopyContainer extends BuildPipelineTest {
String craneAllTagsStr = 'set -x && crane cp opensearchstaging/ci-runner opensearchstaging/ci-runner --all-tags'
assertThat(getShellCommands('sh', 'crane'), hasItem(craneAllTagsStr))

String dockerAllTagsStr = 'set +x && docker logout && docker logout opensearchstaging'
String dockerAllTagsStr = 'set +x && docker logout && docker logout public.ecr.aws'
assertThat(getShellCommands('sh', 'docker logout'), hasItem(dockerAllTagsStr))
}

Expand Down
6 changes: 3 additions & 3 deletions tests/jenkins/jobs/DockerCopyAllTags_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
copyContainer.usernamePassword({credentialsId=jenkins-staging-dockerhub-credential, usernameVariable=DOCKER_USERNAME, passwordVariable=DOCKER_PASSWORD})
copyContainer.withCredentials([[DOCKER_USERNAME, DOCKER_PASSWORD]], groovy.lang.Closure)
copyContainer.sh(set +x && echo DOCKER_PASSWORD | docker login --username DOCKER_USERNAME --password-stdin)
copyContainer.echo(Copying all the tags of image opensearchstaging/ci-runner to opensearchstaging/ci-runner)
copyContainer.sh(set -x && crane cp opensearchstaging/ci-runner opensearchstaging/ci-runner --all-tags)
copyContainer.sh(set +x && docker logout && docker logout opensearchstaging)
copyContainer.echo(Copying all the tags of image opensearchstaging/ci-runner to opensearchstaging/ci-runner)
copyContainer.sh(set -x && crane cp opensearchstaging/ci-runner opensearchstaging/ci-runner --all-tags)
copyContainer.sh(set +x && docker logout && docker logout public.ecr.aws)
5 changes: 4 additions & 1 deletion tests/jenkins/jobs/DockerCopy_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
DockerCopy_Jenkinsfile.stage(Copy Image to ECR/DockerHub, groovy.lang.Closure)
DockerCopy_Jenkinsfile.script(groovy.lang.Closure)
DockerCopy_Jenkinsfile.copyContainer({sourceImage=ci-runner:centos7-123, sourceRegistry=opensearchstaging, destinationImage=ci-runner:centos7-123, destinationRegistry=public.ecr.aws/opensearchstaging})
copyContainer.usernamePassword({credentialsId=jenkins-staging-dockerhub-credential, usernameVariable=DOCKER_USERNAME, passwordVariable=DOCKER_PASSWORD})
copyContainer.withCredentials([[DOCKER_USERNAME, DOCKER_PASSWORD]], groovy.lang.Closure)
copyContainer.sh(set +x && echo DOCKER_PASSWORD | docker login --username DOCKER_USERNAME --password-stdin)
copyContainer.sh(set +x && aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/opensearchstaging)
copyContainer.echo(Copying single image tag from opensearchstaging/ci-runner:centos7-123 to public.ecr.aws/opensearchstaging/ci-runner:centos7-123)
copyContainer.sh(set -x && crane cp opensearchstaging/ci-runner:centos7-123 public.ecr.aws/opensearchstaging/ci-runner:centos7-123)
copyContainer.sh(set +x && docker logout && docker logout public.ecr.aws/opensearchstaging)
copyContainer.sh(set +x && docker logout && docker logout public.ecr.aws)
28 changes: 16 additions & 12 deletions vars/copyContainer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,34 @@ void call(Map args = [:]) {
destination_image_no_tag = destination_image.split(':')[0]
destination_registry = args.destinationRegistry

if (args.destinationRegistry == 'opensearchstaging' || args.destinationRegistry == 'opensearchproject') {
def dockerJenkinsCredential = args.destinationRegistry == 'opensearchproject' ? "jenkins-production-dockerhub-credential" : "jenkins-staging-dockerhub-credential"
withCredentials([usernamePassword(credentialsId: dockerJenkinsCredential, usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
if (source_registry == 'opensearchstaging' || destination_registry == 'opensearchstaging') {
withCredentials([usernamePassword(credentialsId: 'jenkins-staging-dockerhub-credential', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
sh("set +x && echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin")
craneCopy()
}
}

if (args.destinationRegistry == 'public.ecr.aws/opensearchproject') {
if (source_registry == 'opensearchproject' || destination_registry == 'opensearchproject') {
withCredentials([usernamePassword(credentialsId: 'jenkins-production-dockerhub-credential', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
sh("set +x && echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin")
}
}

if (source_registry == 'public.ecr.aws/opensearchstaging' || destination_registry == 'public.ecr.aws/opensearchstaging') {
sh("set +x && aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${destination_registry}")
}

if (source_registry == 'public.ecr.aws/opensearchproject' || destination_registry == 'public.ecr.aws/opensearchproject') {
withCredentials([
string(credentialsId: 'jenkins-artifact-promotion-role', variable: 'ARTIFACT_PROMOTION_ROLE_NAME'),
string(credentialsId: 'jenkins-aws-production-account', variable: 'AWS_ACCOUNT_ARTIFACT')])
{
withAWS(role: "${ARTIFACT_PROMOTION_ROLE_NAME}", roleAccount: "${AWS_ACCOUNT_ARTIFACT}", duration: 900, roleSessionName: 'jenkins-session') {
sh("set +x && aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${args.destinationRegistry}")
craneCopy()
sh("set +x && aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${destination_registry}")
}
}
}

if(args.destinationRegistry == 'public.ecr.aws/opensearchstaging') {
sh("set +x && aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${args.destinationRegistry}")
craneCopy()
}
craneCopy()

}

Expand All @@ -69,7 +73,7 @@ def craneCopy() {
sh("set -x && crane cp ${source_registry}/${source_image} ${destination_registry}/${destination_image}")
}

sh("set +x && docker logout && docker logout ${destination_registry}")
sh("set +x && docker logout && docker logout public.ecr.aws")

return
}
Loading