Skip to content

Commit

Permalink
Add support to validate both docker and ECR as image source (#4762)
Browse files Browse the repository at this point in the history
Signed-off-by: Divya Madala <[email protected]>
  • Loading branch information
Divyaasm authored Jun 12, 2024
1 parent c35c483 commit 58712d2
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 16 deletions.
1 change: 1 addition & 0 deletions jenkins/promotion/release-promotion.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ pipeline {
string(name: 'ARCHITECTURE', value: 'x64 arm64'),
string(name: 'PLATFORM', value: 'linux windows'),
string(name: 'PROJECTS', value: 'Both'),
string(name: 'DOCKER_SOURCE', value: 'Both'),
string(name: 'ARTIFACT_TYPE', value: 'production'),
string(name: 'OPTIONAL_ARGS', value: 'validate-digests-only')
]
Expand Down
8 changes: 6 additions & 2 deletions jenkins/validate-artifacts/validate-artifacts.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ pipeline {
)
choice(
name: 'DOCKER_SOURCE',
description: 'Enter the docker-source to pull the docker image, either DockerHub or ECR.',
choices: ["dockerhub", "ecr"]
description: 'Enter the docker-source to pull the docker image, either DockerHub or ECR or Both.',
choices: ["dockerhub", "ecr", "Both"]
)
choice(
name: 'PROJECTS',
Expand Down Expand Up @@ -131,6 +131,10 @@ pipeline {
PROJECTS = "opensearch opensearch-dashboards"
}

if (DOCKER_SOURCE == 'Both') {
DOCKER_SOURCE = "dockerhub ecr"
}

if (OPENSEARCH_DASHBOARDS_ARTIFACT_URL && OPENSEARCH_ARTIFACT_URL == "") {
currentBuild.result = 'ABORTED'
error("Provide OPENSEARCH_ARTIFACT_URL to validate")
Expand Down
12 changes: 10 additions & 2 deletions src/run_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ def main() -> int:
logging.getLogger("urllib3").setLevel(logging.WARNING)

with TemporaryDirectory() as work_dir:
test_result = ValidationTestRunner.dispatch(args, args.distribution, work_dir).run()
logging.info(f'final test_result = {test_result}')
if args.distribution == "docker":
docker_source = args.docker_source
for source in docker_source:
docker_args = args
docker_args.docker_source = source
test_result = ValidationTestRunner.dispatch(docker_args, args.distribution, work_dir).run()

else:
test_result = ValidationTestRunner.dispatch(args, args.distribution, work_dir).run()
logging.info(f'final test_result = {test_result}\n\n')
return 0 if test_result else 1 # type: ignore


Expand Down
9 changes: 4 additions & 5 deletions src/validation_workflow/validation_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class ValidationArgs:
SUPPORTED_PLATFORMS = ["linux", "windows"]
DOCKER_SOURCE = ["dockerhub", "ecr"]

def __init__(self) -> None:
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -74,11 +73,11 @@ def __init__(self) -> None:
)
parser.add_argument(
"--docker-source",
type=str,
nargs='+',
required=False,
choices=self.DOCKER_SOURCE,
help="(optional) Where to pull the docker image from, either DockerHub or ECR\n",
default="dockerhub",
help="(optional) Where to pull the docker image from, either DockerHub or ECR or Both \n",
choices=["dockerhub", "ecr"],
default=["dockerhub"],
)
parser.add_argument(
"-v",
Expand Down
3 changes: 2 additions & 1 deletion tests/jenkins/TestOpenSearchReleasePromotionTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ class TestOpenSearchReleasePromotionTest extends BuildPipelineTest {
assertCallStack().contains('release-promotion.string({name=ARCHITECTURE, value=x64 arm64})')
assertCallStack().contains('release-promotion.string({name=PLATFORM, value=linux windows})')
assertCallStack().contains('release-promotion.string({name=PROJECTS, value=Both})')
assertCallStack().contains('release-promotion.string({name=DOCKER_SOURCE, value=Both})')
assertCallStack().contains('release-promotion.string({name=ARTIFACT_TYPE, value=production})')
assertCallStack().contains('release-promotion.string({name=OPTIONAL_ARGS, value=validate-digests-only})')
assertCallStack().contains('release-promotion.build({job=distribution-validation, wait=true, parameters=[null, null, null, null, null, null, null]})')
assertCallStack().contains('release-promotion.build({job=distribution-validation, wait=true, parameters=[null, null, null, null, null, null, null, null]})')

// Maven Promotion Workflow
assertCallStack().contains('stage(Publish to Maven, groovy.lang.Closure)')
Expand Down
3 changes: 2 additions & 1 deletion tests/jenkins/TestValidateArtifacts.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TestValidateArtifacts extends BuildPipelineTest {
binding.setVariable('ARCHITECTURE', "x64 arm64")
binding.setVariable('PLATFORM', "linux windows")
binding.setVariable('PROJECTS', "Both")
binding.setVariable('DOCKER_SOURCE', "Both")
binding.setVariable('ARTIFACT_TYPE', "production")
binding.setVariable('OPTIONAL_ARGS', "using-staging-artifact-only")

Expand All @@ -56,7 +57,7 @@ class TestValidateArtifacts extends BuildPipelineTest {
public void testValidateArtifactsPipeline() {
super.testPipeline("jenkins/validate-artifacts/validate-artifacts.jenkinsfile",
"tests/jenkins/jenkinsjob-regression-files/validate-artifacts/validate-artifacts.jenkinsfile")
assertThat(getCommandExecutions('sh', 'validation.sh'), hasItem('./validation.sh --version 2.3.0 --distribution docker --arch x64 --projects opensearch opensearch-dashboards --docker-source dockerhub --os-build-number 6039 --osd-build-number 4104 --using-staging-artifact-only'))
assertThat(getCommandExecutions('sh', 'validation.sh'), hasItem('./validation.sh --version 2.3.0 --distribution docker --arch x64 --projects opensearch opensearch-dashboards --docker-source dockerhub ecr --os-build-number 6039 --osd-build-number 4104 --using-staging-artifact-only'))
assertThat(getCommandExecutions('sh', 'validation.sh'), hasItem('./validation.sh --version 2.3.0 --distribution tar --platform linux --arch x64 --projects opensearch opensearch-dashboards --os-build-number 6039 --osd-build-number 4104 --artifact-type production'))
assertThat(getCommandExecutions('sh', 'validation.sh'), hasItem('./validation.sh --version 2.3.0 --distribution yum --platform linux --arch x64 --projects opensearch opensearch-dashboards --os-build-number 6039 --osd-build-number 4104 --artifact-type production'))
assertThat(getCommandExecutions('sh', 'validation.sh'), hasItem('./validation.sh --version 2.3.0 --distribution rpm --platform linux --arch arm64 --projects opensearch opensearch-dashboards --os-build-number 6039 --osd-build-number 4104 --artifact-type production'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@
release-promotion.string({name=ARCHITECTURE, value=x64 arm64})
release-promotion.string({name=PLATFORM, value=linux windows})
release-promotion.string({name=PROJECTS, value=Both})
release-promotion.string({name=DOCKER_SOURCE, value=Both})
release-promotion.string({name=ARTIFACT_TYPE, value=production})
release-promotion.string({name=OPTIONAL_ARGS, value=validate-digests-only})
release-promotion.build({job=distribution-validation, wait=true, parameters=[null, null, null, null, null, null, null]})
release-promotion.build({job=distribution-validation, wait=true, parameters=[null, null, null, null, null, null, null, null]})
release-promotion.echo(Artifacts are successfully validated!)
release-promotion.stage(Publish to Maven, groovy.lang.Closure)
release-promotion.echo(Executing on agent [docker:[alwaysPull:true, args:, containerPerStageRoot:false, label:Jenkins-Agent-AL2023-X64-C54xlarge-Docker-Host, image:docker/library/alpine:3, reuseNode:false, registryUrl:https://public.ecr.aws/, stages:[:]]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
validate-artifacts.timeout({time=30}, groovy.lang.Closure)
validate-artifacts.node(Jenkins-Agent-AL2023-X64-C54xlarge-Single-Host, groovy.lang.Closure)
validate-artifacts.unstash(validate-artifacts-123)
validate-artifacts.validateArtifacts({version=2.3.0, distribution=docker, arch=x64, os_build_number=6039, osd_build_number=4104, projects=opensearch opensearch-dashboards, docker_args=using-staging-artifact-only, docker_source=dockerhub})
validate-artifacts.validateArtifacts({version=2.3.0, distribution=docker, arch=x64, os_build_number=6039, osd_build_number=4104, projects=opensearch opensearch-dashboards, docker_args=using-staging-artifact-only, docker_source=dockerhub ecr})
validateArtifacts.fileExists(/tmp/workspace/validation.sh)
validateArtifacts.sh(./validation.sh --version 2.3.0 --distribution docker --arch x64 --projects opensearch opensearch-dashboards --docker-source dockerhub --os-build-number 6039 --osd-build-number 4104 --using-staging-artifact-only)
validateArtifacts.sh(./validation.sh --version 2.3.0 --distribution docker --arch x64 --projects opensearch opensearch-dashboards --docker-source dockerhub ecr --os-build-number 6039 --osd-build-number 4104 --using-staging-artifact-only)
validate-artifacts.echo(Completed validation for docker-x64)
validate-artifacts.postCleanup()
postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true})
Expand Down Expand Up @@ -85,9 +85,9 @@
validate-artifacts.timeout({time=30}, groovy.lang.Closure)
validate-artifacts.node(Jenkins-Agent-AL2023-Arm64-C6g4xlarge-Single-Host, groovy.lang.Closure)
validate-artifacts.unstash(validate-artifacts-123)
validate-artifacts.validateArtifacts({version=2.3.0, distribution=docker, arch=arm64, os_build_number=6039, osd_build_number=4104, projects=opensearch opensearch-dashboards, docker_args=using-staging-artifact-only, docker_source=dockerhub})
validate-artifacts.validateArtifacts({version=2.3.0, distribution=docker, arch=arm64, os_build_number=6039, osd_build_number=4104, projects=opensearch opensearch-dashboards, docker_args=using-staging-artifact-only, docker_source=dockerhub ecr})
validateArtifacts.fileExists(/tmp/workspace/validation.sh)
validateArtifacts.sh(./validation.sh --version 2.3.0 --distribution docker --arch arm64 --projects opensearch opensearch-dashboards --docker-source dockerhub --os-build-number 6039 --osd-build-number 4104 --using-staging-artifact-only)
validateArtifacts.sh(./validation.sh --version 2.3.0 --distribution docker --arch arm64 --projects opensearch opensearch-dashboards --docker-source dockerhub ecr --os-build-number 6039 --osd-build-number 4104 --using-staging-artifact-only)
validate-artifacts.echo(Completed validation for docker-arm64)
validate-artifacts.postCleanup()
postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true})
Expand Down
19 changes: 19 additions & 0 deletions tests/test_run_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,22 @@ def test_main(self, mock_tar: Mock, *mocks: Any) -> None:

result = main()
self.assertEqual(result, 0)

@patch("argparse._sys.argv",
["run_validation.py", "--version", "2.1.0", "--distribution", "docker", "--docker_source",
"dockerhub,ecr"])
@patch('run_validation.ValidationTestRunner')
def test_main_docker(self, mock_docker: Mock, *mocks: Any) -> None:
mock_docker_instance = mock_docker.dispatch.return_value
mock_docker_instance.run.return_value = True

with patch('run_validation.ValidationArgs') as MockValidationArgs:
mock_args = Mock()
mock_args.docker_source = ["dockerhub", "ecr"]
mock_args.distribution = "docker"
MockValidationArgs.return_value = mock_args

result = main()
self.assertEqual(result, 0)
self.assertEqual(mock_docker.dispatch.call_count, 2)
self.assertTrue(mock_docker_instance.run.call_count, 2)
7 changes: 7 additions & 0 deletions tests/tests_validation_workflow/test_validation_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def test_docker_distribution(self) -> None:
self.assertEqual(ValidationArgs().distribution, "docker")
self.assertNotEqual(ValidationArgs().distribution, "yum")

@patch("argparse._sys.argv",
[VALIDATION_PY, "--version", "2.4.0", "--distribution", "docker", "--projects", "opensearch", "--docker-source", "dockerhub", "ecr",
"--using-staging-artifact-only"])
def test_docker_source(self) -> None:
self.assertEqual(ValidationArgs().distribution, "docker")
self.assertEqual(ValidationArgs().docker_source, ["dockerhub", "ecr"])

@patch("argparse._sys.argv", [VALIDATION_PY, "--version", "1.3.6", "--platform", "linux"])
def test_platform_default(self) -> None:
self.assertEqual(ValidationArgs().platform, "linux")
Expand Down

0 comments on commit 58712d2

Please sign in to comment.