diff --git a/jenkins/docker-ecr/docker-ecr-promote.jenkinsfile b/jenkins/docker-ecr/docker-ecr-promote.jenkinsfile index e82932efd0..cd475dc723 100644 --- a/jenkins/docker-ecr/docker-ecr-promote.jenkinsfile +++ b/jenkins/docker-ecr/docker-ecr-promote.jenkinsfile @@ -27,6 +27,11 @@ pipeline { name: 'PLATFORM', description: 'Where do you want to push the images?' ) + booleanParam( + defaultValue: true, + name: 'TAG_LATEST', + description: 'Tag the copied image as latest' + ) } stages { @@ -42,6 +47,14 @@ pipeline { destinationType: "docker", destinationCredentialIdentifier: "jenkins-staging-docker-prod-token" ) + if(TAG_LATEST == "true"){ + copyContainer( + sourceImagePath: "opensearchstaging/${IMAGE_REPOSITORY}:${IMAGE_TAG}", + destinationImagePath: "opensearchproject/${IMAGE_REPOSITORY}:latest", + destinationType: "docker", + destinationCredentialIdentifier: "jenkins-staging-docker-prod-token" + ) + } } } } @@ -58,6 +71,15 @@ pipeline { destinationCredentialIdentifier: "public.ecr.aws/p5f6l6i3", accountName: "${AWS_ACCOUNT_ARTIFACT}" ) + if(TAG_LATEST == "true"){ + copyContainer( + sourceImagePath: "opensearchstaging/${IMAGE_REPOSITORY}:${IMAGE_TAG}", + destinationImagePath: "public.ecr.aws/p5f6l6i3/${IMAGE_REPOSITORY}:latest", + destinationType: "ecr", + destinationCredentialIdentifier: "public.ecr.aws/p5f6l6i3", + accountName: "${AWS_ACCOUNT_ARTIFACT}" + ) + } } } } diff --git a/tests/jenkins/TestDockerPromoteWithDockerhubOnlyJob.groovy b/tests/jenkins/TestDockerPromoteWithDockerhubOnlyJob.groovy index 17008a7836..6c7e7e091b 100644 --- a/tests/jenkins/TestDockerPromoteWithDockerhubOnlyJob.groovy +++ b/tests/jenkins/TestDockerPromoteWithDockerhubOnlyJob.groovy @@ -22,6 +22,7 @@ class TestDockerPromoteWithDockerhubOnlyJob extends BuildPipelineTest { binding.setVariable('IMAGE_TAG', imageTag) binding.setVariable('AWS_ACCOUNT_ARTIFACT', accountName) binding.setVariable('PLATFORM', 'docker-hub') + binding.setVariable('TAG_LATEST', 'false') } diff --git a/tests/jenkins/TestDockerPromoteWithEcrAndDockerhubJob.groovy b/tests/jenkins/TestDockerPromoteWithEcrAndDockerhubJob.groovy index 6f6aee0fe0..8f34e2fa97 100644 --- a/tests/jenkins/TestDockerPromoteWithEcrAndDockerhubJob.groovy +++ b/tests/jenkins/TestDockerPromoteWithEcrAndDockerhubJob.groovy @@ -28,6 +28,7 @@ class TestDockerPromoteWithEcrAndDockerhubJob extends BuildPipelineTest { binding.setVariable('IMAGE_TAG', imageTag) binding.setVariable('AWS_ACCOUNT_ARTIFACT', accountName) binding.setVariable('PLATFORM', 'docker-hub + ECR') + binding.setVariable('TAG_LATEST', 'false') } diff --git a/tests/jenkins/TestDockerPromoteWithEcrOnlyJob.groovy b/tests/jenkins/TestDockerPromoteWithEcrOnlyJob.groovy index 3a9d59e4a0..49275308b7 100644 --- a/tests/jenkins/TestDockerPromoteWithEcrOnlyJob.groovy +++ b/tests/jenkins/TestDockerPromoteWithEcrOnlyJob.groovy @@ -23,6 +23,7 @@ class TestDockerPromoteWithEcrOnlyJob extends BuildPipelineTest { binding.setVariable('IMAGE_TAG', imageTag) binding.setVariable('AWS_ACCOUNT_ARTIFACT', accountName) binding.setVariable('PLATFORM', 'ECR') + binding.setVariable('TAG_LATEST', 'false') } diff --git a/tests/jenkins/TestDockerPromoteWithLatestTagDockerHubJob.groovy b/tests/jenkins/TestDockerPromoteWithLatestTagDockerHubJob.groovy new file mode 100644 index 0000000000..7900fc75d4 --- /dev/null +++ b/tests/jenkins/TestDockerPromoteWithLatestTagDockerHubJob.groovy @@ -0,0 +1,40 @@ +import jenkins.tests.BuildPipelineTest +import org.junit.Before +import org.junit.Test + +class TestDockerPromoteWithLatestTagDockerHubJob extends BuildPipelineTest { + + @Before + void setUp() { + String imageRepository = 'ci-runner-staging' + String imageTag = '1.3.0' + String accountName = 'aws_account_artifact' + String sourceImagePath = "opensearchstaging/${imageRepository}:${imageTag}" + + this.registerLibTester(new CopyContainerLibTester(sourceImagePath, + "opensearchproject/${imageRepository}:${imageTag}", + 'docker', + 'jenkins-staging-docker-prod-token')) + + this.registerLibTester(new CopyContainerLibTester(sourceImagePath, + "opensearchproject/${imageRepository}:latest", + 'docker', + 'jenkins-staging-docker-prod-token')) + + super.setUp() + + binding.setVariable('IMAGE_REPOSITORY', imageRepository) + binding.setVariable('IMAGE_TAG', imageTag) + binding.setVariable('AWS_ACCOUNT_ARTIFACT', accountName) + binding.setVariable('PLATFORM', 'docker-hub') + binding.setVariable('TAG_LATEST', 'true') + + } + + @Test + public void testDockerForEcrJobProductionWithDockerhubOnly(){ + super.testPipeline("jenkins/docker-ecr/docker-ecr-promote.jenkinsfile", + "tests/jenkins/jenkinsjob-regression-files/docker-ecr/docker-ecr-promote-with-latestTag-dockerhub-only.jenkinsfile") + } + +} diff --git a/tests/jenkins/TestDockerPromoteWithLatestTagEcrOnlyJob.groovy b/tests/jenkins/TestDockerPromoteWithLatestTagEcrOnlyJob.groovy new file mode 100644 index 0000000000..e049ba9b6c --- /dev/null +++ b/tests/jenkins/TestDockerPromoteWithLatestTagEcrOnlyJob.groovy @@ -0,0 +1,42 @@ +import jenkins.tests.BuildPipelineTest +import org.junit.Before +import org.junit.Test + +class TestDockerPromoteWithLatestTagEcrOnlyJob extends BuildPipelineTest { + + @Before + void setUp() { + String imageRepository = 'ci-runner-staging' + String imageTag = '1.3.0' + String accountName = 'aws_account_artifact' + String sourceImagePath = "opensearchstaging/${imageRepository}:${imageTag}" + + this.registerLibTester(new CopyContainerLibTester(sourceImagePath, + "public.ecr.aws/p5f6l6i3/${imageRepository}:${imageTag}", + 'ecr', + 'public.ecr.aws/p5f6l6i3', + accountName)) + + this.registerLibTester(new CopyContainerLibTester(sourceImagePath, + "public.ecr.aws/p5f6l6i3/${imageRepository}:latest", + 'ecr', + 'public.ecr.aws/p5f6l6i3', + accountName)) + + super.setUp() + + binding.setVariable('IMAGE_REPOSITORY', imageRepository) + binding.setVariable('IMAGE_TAG', imageTag) + binding.setVariable('AWS_ACCOUNT_ARTIFACT', accountName) + binding.setVariable('PLATFORM', 'ECR') + binding.setVariable('TAG_LATEST', 'true') + + } + + @Test + public void testDockerForEcrAndDockerhubJobProductionWithECR(){ + super.testPipeline("jenkins/docker-ecr/docker-ecr-promote.jenkinsfile", + "tests/jenkins/jenkinsjob-regression-files/docker-ecr/docker-ecr-promote-with-latestTag-ECR-only.jenkinsfile") + } + +} diff --git a/tests/jenkins/jenkinsjob-regression-files/docker-ecr/docker-ecr-promote-with-latestTag-ECR-only.jenkinsfile.txt b/tests/jenkins/jenkinsjob-regression-files/docker-ecr/docker-ecr-promote-with-latestTag-ECR-only.jenkinsfile.txt new file mode 100644 index 0000000000..c9e5553f13 --- /dev/null +++ b/tests/jenkins/jenkinsjob-regression-files/docker-ecr/docker-ecr-promote-with-latestTag-ECR-only.jenkinsfile.txt @@ -0,0 +1,29 @@ + docker-ecr-promote.run() + docker-ecr-promote.legacySCM(groovy.lang.Closure) + docker-ecr-promote.library({identifier=jenkins@20211123, retriever=null}) + docker-ecr-promote.pipeline(groovy.lang.Closure) + docker-ecr-promote.timeout({time=1, unit=HOURS}) + docker-ecr-promote.echo(Executing on agent [docker:[image:opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.6.3-qemu5.0-awscli1.22-jdk14, reuseNode:false, stages:[:], args:-u root, alwaysPull:false, containerPerStageRoot:false, label:Jenkins-Agent-al2-x64-c54xlarge-Docker-Host]]) + docker-ecr-promote.echo(Skipping stage dockerhub-promote-to-prod) + docker-ecr-promote.stage(ecr-promote-to-prod, groovy.lang.Closure) + docker-ecr-promote.script(groovy.lang.Closure) + docker-ecr-promote.copyContainer({sourceImagePath=opensearchstaging/ci-runner-staging:1.3.0, destinationImagePath=public.ecr.aws/p5f6l6i3/ci-runner-staging:1.3.0, destinationType=ecr, destinationCredentialIdentifier=public.ecr.aws/p5f6l6i3, accountName=aws_account_artifact}) + copyContainer.sh({script=test -f /usr/local/bin/gcrane && echo '1' || echo '0' , returnStdout=true}) + copyContainer.sh(docker logout) + copyContainer.withAWS({role=Upload_ECR_Image, roleAccount=aws_account_artifact, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure) + copyContainer.sh( + aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/p5f6l6i3 + gcrane cp opensearchstaging/ci-runner-staging:1.3.0 public.ecr.aws/p5f6l6i3/ci-runner-staging:1.3.0 + ) + docker-ecr-promote.copyContainer({sourceImagePath=opensearchstaging/ci-runner-staging:1.3.0, destinationImagePath=public.ecr.aws/p5f6l6i3/ci-runner-staging:latest, destinationType=ecr, destinationCredentialIdentifier=public.ecr.aws/p5f6l6i3, accountName=aws_account_artifact}) + copyContainer.sh({script=test -f /usr/local/bin/gcrane && echo '1' || echo '0' , returnStdout=true}) + copyContainer.sh(docker logout) + copyContainer.withAWS({role=Upload_ECR_Image, roleAccount=aws_account_artifact, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure) + copyContainer.sh( + aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/p5f6l6i3 + gcrane cp opensearchstaging/ci-runner-staging:1.3.0 public.ecr.aws/p5f6l6i3/ci-runner-staging:latest + ) + docker-ecr-promote.script(groovy.lang.Closure) + docker-ecr-promote.postCleanup() + postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) + docker-ecr-promote.sh(docker logout) diff --git a/tests/jenkins/jenkinsjob-regression-files/docker-ecr/docker-ecr-promote-with-latestTag-dockerhub-only.jenkinsfile.txt b/tests/jenkins/jenkinsjob-regression-files/docker-ecr/docker-ecr-promote-with-latestTag-dockerhub-only.jenkinsfile.txt new file mode 100644 index 0000000000..75f4e43cea --- /dev/null +++ b/tests/jenkins/jenkinsjob-regression-files/docker-ecr/docker-ecr-promote-with-latestTag-dockerhub-only.jenkinsfile.txt @@ -0,0 +1,31 @@ + docker-ecr-promote.run() + docker-ecr-promote.legacySCM(groovy.lang.Closure) + docker-ecr-promote.library({identifier=jenkins@20211123, retriever=null}) + docker-ecr-promote.pipeline(groovy.lang.Closure) + docker-ecr-promote.timeout({time=1, unit=HOURS}) + docker-ecr-promote.echo(Executing on agent [docker:[image:opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.6.3-qemu5.0-awscli1.22-jdk14, reuseNode:false, stages:[:], args:-u root, alwaysPull:false, containerPerStageRoot:false, label:Jenkins-Agent-al2-x64-c54xlarge-Docker-Host]]) + docker-ecr-promote.stage(dockerhub-promote-to-prod, groovy.lang.Closure) + docker-ecr-promote.script(groovy.lang.Closure) + docker-ecr-promote.copyContainer({sourceImagePath=opensearchstaging/ci-runner-staging:1.3.0, destinationImagePath=opensearchproject/ci-runner-staging:1.3.0, destinationType=docker, destinationCredentialIdentifier=jenkins-staging-docker-prod-token}) + copyContainer.sh({script=test -f /usr/local/bin/gcrane && echo '1' || echo '0' , returnStdout=true}) + copyContainer.sh(docker logout) + copyContainer.usernamePassword({credentialsId=jenkins-staging-docker-prod-token, usernameVariable=DOCKER_USERNAME, passwordVariable=DOCKER_PASSWORD}) + copyContainer.withCredentials([[DOCKER_USERNAME, DOCKER_PASSWORD]], groovy.lang.Closure) + copyContainer.sh( + docker login -u DOCKER_USERNAME -p DOCKER_PASSWORD + gcrane cp opensearchstaging/ci-runner-staging:1.3.0 opensearchproject/ci-runner-staging:1.3.0 + ) + docker-ecr-promote.copyContainer({sourceImagePath=opensearchstaging/ci-runner-staging:1.3.0, destinationImagePath=opensearchproject/ci-runner-staging:latest, destinationType=docker, destinationCredentialIdentifier=jenkins-staging-docker-prod-token}) + copyContainer.sh({script=test -f /usr/local/bin/gcrane && echo '1' || echo '0' , returnStdout=true}) + copyContainer.sh(docker logout) + copyContainer.usernamePassword({credentialsId=jenkins-staging-docker-prod-token, usernameVariable=DOCKER_USERNAME, passwordVariable=DOCKER_PASSWORD}) + copyContainer.withCredentials([[DOCKER_USERNAME, DOCKER_PASSWORD]], groovy.lang.Closure) + copyContainer.sh( + docker login -u DOCKER_USERNAME -p DOCKER_PASSWORD + gcrane cp opensearchstaging/ci-runner-staging:1.3.0 opensearchproject/ci-runner-staging:latest + ) + docker-ecr-promote.echo(Skipping stage ecr-promote-to-prod) + docker-ecr-promote.script(groovy.lang.Closure) + docker-ecr-promote.postCleanup() + postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) + docker-ecr-promote.sh(docker logout)