From f56a0b9a3b18aafa4ede10f279eb43d6c629e85b Mon Sep 17 00:00:00 2001 From: Stewart Wallace Date: Fri, 17 Sep 2021 09:11:09 +0100 Subject: [PATCH 1/6] adding in ability to define CodeCommit artifact format --- .../cdk/cdk_constructs/adf_codepipeline.py | 6 ++- .../tests/test_pipeline_creation.py | 51 +++++++++++++++++++ .../adf-build/shared/schema_validation.py | 1 + 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codepipeline.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codepipeline.py index cf1eb739a..83a3abacb 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codepipeline.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codepipeline.py @@ -247,7 +247,7 @@ def _generate_configuration(self): #pylint: disable=R0912, R0911, R0915 'deployment_group_name') } if self.provider == "CodeCommit": - return { + props = { "BranchName": self.map_params['default_providers']['source'].get('properties', {}).get('branch', 'master'), "RepositoryName": self.map_params['default_providers']['source'].get('properties', {}).get('repository', {}) or self.map_params['name'], "PollForSourceChanges": ( @@ -255,6 +255,10 @@ def _generate_configuration(self): #pylint: disable=R0912, R0911, R0915 and self.map_params['default_providers']['source'].get('properties', {}).get('poll_for_changes', False) ) } + output_artifcat_format = self.map_params['default_providers']['source'].get('properties', {}).get('output_artifact_format', None) + if output_artifcat_format: + props["OutputArtifactFormat"] = output_artifcat_format + return props raise Exception("{0} is not a valid provider".format(self.provider)) def _generate_codepipeline_access_role(self): #pylint: disable=R0911 diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_stacks/tests/test_pipeline_creation.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_stacks/tests/test_pipeline_creation.py index fba72ecb6..88932eaae 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_stacks/tests/test_pipeline_creation.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_stacks/tests/test_pipeline_creation.py @@ -140,3 +140,54 @@ def test_pipeline_creation_outputs_as_expected_when_source_is_codecommit_and_bui assert build_stage_action['ActionTypeId']['Provider'] == "CodeBuild" assert len(build_stage['Actions']) == 1 + +def test_pipeline_creation_outputs_as_expected_when_source_is_codecommit_with_codebuild_clone_ref_and_build_is_codebuild(): + region_name = "eu-central-1" + acount_id = "123456789012" + + stack_input = { + "input": {"params": {}, "default_providers": {}, "regions": {}}, + "ssm_params": {"fake-region": {}}, + } + + stack_input["input"]["name"] = "test-stack" + + stack_input["input"]["default_providers"]["source"] = { + "provider": "codecommit", + "properties": {"account_id": "123456789012", "output_artifact_format": "CODEBUILD_CLONE_REF"}, + } + stack_input["input"]["default_providers"]["build"] = { + "provider": "codebuild", + "properties": {"account_id": "123456789012"}, + } + + stack_input["ssm_params"][region_name] = { + "modules": "fake-bucket-name", + "kms": f"arn:aws:kms:{region_name}:{acount_id}:key/my-unique-kms-key-id", + } + app = core.App() + PipelineStack(app, stack_input) + + cloud_assembly = app.synth() + resources = {k[0:-8]: v for k, v in cloud_assembly.stacks[0].template['Resources'].items()} + code_pipeline = resources['codepipeline'] + assert code_pipeline['Type'] == "AWS::CodePipeline::Pipeline" + assert len(code_pipeline["Properties"]["Stages"]) == 2 + + source_stage = code_pipeline['Properties']["Stages"][0] + assert len(source_stage['Actions']) == 1 + + source_stage_action = source_stage['Actions'][0] + assert source_stage_action['ActionTypeId']['Category'] == "Source" + assert source_stage_action['ActionTypeId']['Owner'] == "AWS" + assert source_stage_action['ActionTypeId']['Provider'] == "CodeCommit" + assert source_stage_action['Configuration']['OutputArtifactFormat'] == "CODEBUILD_CLONE_REF" + + build_stage = code_pipeline['Properties']["Stages"][1] + build_stage_action = build_stage['Actions'][0] + assert build_stage_action['ActionTypeId']['Category'] == "Build" + assert build_stage_action['ActionTypeId']['Owner'] == "AWS" + assert build_stage_action['ActionTypeId']['Provider'] == "CodeBuild" + + assert len(build_stage['Actions']) == 1 + diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py index 90d22dad9..4324eee2e 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py @@ -51,6 +51,7 @@ Optional("owner"): str, Optional("role"): str, Optional("trigger_on_changes"): bool, + Optional("output_artifact_format", default=None): Or(str, None) } CODECOMMIT_SOURCE = { "provider": 'codecommit', From fee8f97ca2ba0cd9313cff8cf0843725728fd7f2 Mon Sep 17 00:00:00 2001 From: Stewart Wallace Date: Thu, 23 Sep 2021 11:26:20 +0100 Subject: [PATCH 2/6] Fixing Typo --- .../adf-build/shared/cdk/cdk_constructs/adf_codepipeline.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codepipeline.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codepipeline.py index 83a3abacb..2c3a6a4fe 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codepipeline.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codepipeline.py @@ -255,9 +255,9 @@ def _generate_configuration(self): #pylint: disable=R0912, R0911, R0915 and self.map_params['default_providers']['source'].get('properties', {}).get('poll_for_changes', False) ) } - output_artifcat_format = self.map_params['default_providers']['source'].get('properties', {}).get('output_artifact_format', None) - if output_artifcat_format: - props["OutputArtifactFormat"] = output_artifcat_format + output_artifact_format = self.map_params['default_providers']['source'].get('properties', {}).get('output_artifact_format', None) + if output_artifact_format: + props["OutputArtifactFormat"] = output_artifact_format return props raise Exception("{0} is not a valid provider".format(self.provider)) From a943a34ec5e927cf5608a670de4666660e5da663 Mon Sep 17 00:00:00 2001 From: Stewart Wallace Date: Thu, 23 Sep 2021 11:33:03 +0100 Subject: [PATCH 3/6] Updating Provider Documentation --- docs/providers-guide.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/providers-guide.md b/docs/providers-guide.md index dcab56f4e..a9969bff3 100644 --- a/docs/providers-guide.md +++ b/docs/providers-guide.md @@ -87,6 +87,10 @@ Provider type: `codecommit`. > > By default, it will trigger on changes using the event triggered by > CodeCommit when an update to the repository took place. +- *output_artifact_format* - *(String)* default CODE_ZIP + > The output artifact format. Values can be either CODEBUILD_CLONE_REF or CODE_ZIP. If unspecified, the default is CODE_ZIP. + > If you are using CODEBUILD_CLONE_REF, you need to ensure that the IAM role passed in via the *role* property has the CodeCommit:GitPull permission. + > NB: The CODEBUILD_CLONE_REF value can only be used by CodeBuild downstream actions. ### GitHub From 67a20789e05e7929a717c4457412c93f2ea52cad Mon Sep 17 00:00:00 2001 From: Stewart Wallace Date: Thu, 11 Nov 2021 15:57:51 +0000 Subject: [PATCH 4/6] Update docs/providers-guide.md Co-authored-by: Simon --- docs/providers-guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/providers-guide.md b/docs/providers-guide.md index a9969bff3..ee0585653 100644 --- a/docs/providers-guide.md +++ b/docs/providers-guide.md @@ -87,7 +87,7 @@ Provider type: `codecommit`. > > By default, it will trigger on changes using the event triggered by > CodeCommit when an update to the repository took place. -- *output_artifact_format* - *(String)* default CODE_ZIP +- *output_artifact_format* - *(String)* default: `CODE_ZIP` > The output artifact format. Values can be either CODEBUILD_CLONE_REF or CODE_ZIP. If unspecified, the default is CODE_ZIP. > If you are using CODEBUILD_CLONE_REF, you need to ensure that the IAM role passed in via the *role* property has the CodeCommit:GitPull permission. > NB: The CODEBUILD_CLONE_REF value can only be used by CodeBuild downstream actions. From 8852e207e3e21d7756e35b6eb67cf7c854d78700 Mon Sep 17 00:00:00 2001 From: Stewart Wallace Date: Thu, 11 Nov 2021 15:57:59 +0000 Subject: [PATCH 5/6] Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py Co-authored-by: Simon --- .../bootstrap_repository/adf-build/shared/schema_validation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py index 4324eee2e..d85333ec5 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py @@ -51,7 +51,7 @@ Optional("owner"): str, Optional("role"): str, Optional("trigger_on_changes"): bool, - Optional("output_artifact_format", default=None): Or(str, None) + Optional("output_artifact_format", default=None): Or("CODEBUILD_CLONE_REF", "CODE_ZIP", None) } CODECOMMIT_SOURCE = { "provider": 'codecommit', From 6a55babfd86a56066604e24923ae66141190646e Mon Sep 17 00:00:00 2001 From: Stewart Wallace Date: Fri, 12 Nov 2021 08:28:29 +0000 Subject: [PATCH 6/6] Updating test to check OutputArtifactFormat not in configuration if not required --- .../shared/cdk/cdk_stacks/tests/test_pipeline_creation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_stacks/tests/test_pipeline_creation.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_stacks/tests/test_pipeline_creation.py index 88932eaae..b5dfd6508 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_stacks/tests/test_pipeline_creation.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_stacks/tests/test_pipeline_creation.py @@ -139,8 +139,11 @@ def test_pipeline_creation_outputs_as_expected_when_source_is_codecommit_and_bui assert build_stage_action['ActionTypeId']['Owner'] == "AWS" assert build_stage_action['ActionTypeId']['Provider'] == "CodeBuild" + assert "OutputArtifactFormat" not in source_stage_action['Configuration'] + assert len(build_stage['Actions']) == 1 + def test_pipeline_creation_outputs_as_expected_when_source_is_codecommit_with_codebuild_clone_ref_and_build_is_codebuild(): region_name = "eu-central-1" acount_id = "123456789012"