From e94ad8bf5e13644d00c9b57752ddf4b1b90e35d0 Mon Sep 17 00:00:00 2001 From: Ahmed Elbayaa Date: Thu, 27 May 2021 14:44:21 -0700 Subject: [PATCH 1/4] Rename ecr-repo to image-repository --- samcli/commands/pipeline/bootstrap/cli.py | 32 ++++++------ .../pipeline/bootstrap/guided_context.py | 22 ++++---- samcli/lib/pipeline/bootstrap/environment.py | 52 +++++++++---------- .../bootstrap/environment_resources.yaml | 34 ++++++------ samcli/lib/pipeline/bootstrap/resource.py | 4 +- .../pipeline/bootstrap/test_guided_context.py | 20 +++---- .../pipeline/bootstrap/test_environment.py | 30 +++++------ .../lib/pipeline/bootstrap/test_resource.py | 8 +-- 8 files changed, 103 insertions(+), 99 deletions(-) diff --git a/samcli/commands/pipeline/bootstrap/cli.py b/samcli/commands/pipeline/bootstrap/cli.py index 1b9ee588bb..5cf70632fb 100644 --- a/samcli/commands/pipeline/bootstrap/cli.py +++ b/samcli/commands/pipeline/bootstrap/cli.py @@ -68,17 +68,17 @@ required=False, ) @click.option( - "--create-ecr-repo/--no-create-ecr-repo", + "--create-image-repository/--no-create-image-repository", is_flag=True, default=False, help="If set to true and no ECR repository is provided, this command will create an ECR repository to hold the" " container images of Lambda functions having an Image package type.", ) @click.option( - "--ecr-repo", + "--image-repository", help="The ARN of an ECR repository to hold the containers images of Lambda functions of Image package type. " - "If provided, the --create-ecr-repo argument is ignored. If not provided and --create-ecr-repo is set to true, " - "the command will create one.", + "If provided, the --create-image-repository argument is ignored. If not provided and --create-image-repository is " + "set to true, the command will create one.", required=False, ) @click.option( @@ -106,8 +106,8 @@ def cli( pipeline_execution_role: Optional[str], cloudformation_execution_role: Optional[str], artifacts_bucket: Optional[str], - create_ecr_repo: bool, - ecr_repo: Optional[str], + create_image_repository: bool, + image_repository: Optional[str], pipeline_ip_range: Optional[str], confirm_changeset: bool, config_file: Optional[str], @@ -125,8 +125,8 @@ def cli( pipeline_execution_role_arn=pipeline_execution_role, cloudformation_execution_role_arn=cloudformation_execution_role, artifacts_bucket_arn=artifacts_bucket, - create_ecr_repo=create_ecr_repo, - ecr_repo_arn=ecr_repo, + create_image_repository=create_image_repository, + image_repository_arn=image_repository, pipeline_ip_range=pipeline_ip_range, confirm_changeset=confirm_changeset, config_file=config_env, @@ -143,8 +143,8 @@ def do_cli( pipeline_execution_role_arn: Optional[str], cloudformation_execution_role_arn: Optional[str], artifacts_bucket_arn: Optional[str], - create_ecr_repo: bool, - ecr_repo_arn: Optional[str], + create_image_repository: bool, + image_repository_arn: Optional[str], pipeline_ip_range: Optional[str], confirm_changeset: bool, config_file: Optional[str], @@ -163,8 +163,8 @@ def do_cli( pipeline_execution_role_arn=pipeline_execution_role_arn, cloudformation_execution_role_arn=cloudformation_execution_role_arn, artifacts_bucket_arn=artifacts_bucket_arn, - create_ecr_repo=create_ecr_repo, - ecr_repo_arn=ecr_repo_arn, + create_image_repository=create_image_repository, + image_repository_arn=image_repository_arn, pipeline_ip_range=pipeline_ip_range, ) guided_context.run() @@ -174,8 +174,8 @@ def do_cli( pipeline_ip_range = guided_context.pipeline_ip_range cloudformation_execution_role_arn = guided_context.cloudformation_execution_role_arn artifacts_bucket_arn = guided_context.artifacts_bucket_arn - create_ecr_repo = guided_context.create_ecr_repo - ecr_repo_arn = guided_context.ecr_repo_arn + create_image_repository = guided_context.create_image_repository + image_repository_arn = guided_context.image_repository_arn if not environment_name: raise click.UsageError("Missing required parameter '--environment'") @@ -189,8 +189,8 @@ def do_cli( pipeline_ip_range=pipeline_ip_range, cloudformation_execution_role_arn=cloudformation_execution_role_arn, artifacts_bucket_arn=artifacts_bucket_arn, - create_ecr_repo=create_ecr_repo, - ecr_repo_arn=ecr_repo_arn, + create_image_repository=create_image_repository, + image_repository_arn=image_repository_arn, ) bootstrapped: bool = environment.bootstrap(confirm_changeset=confirm_changeset) diff --git a/samcli/commands/pipeline/bootstrap/guided_context.py b/samcli/commands/pipeline/bootstrap/guided_context.py index 332280fc77..c8d94cb9f6 100644 --- a/samcli/commands/pipeline/bootstrap/guided_context.py +++ b/samcli/commands/pipeline/bootstrap/guided_context.py @@ -15,8 +15,8 @@ def __init__( pipeline_execution_role_arn: Optional[str] = None, cloudformation_execution_role_arn: Optional[str] = None, artifacts_bucket_arn: Optional[str] = None, - create_ecr_repo: bool = False, - ecr_repo_arn: Optional[str] = None, + create_image_repository: bool = False, + image_repository_arn: Optional[str] = None, pipeline_ip_range: Optional[str] = None, ) -> None: self.environment_name = environment_name @@ -24,8 +24,8 @@ def __init__( self.pipeline_execution_role_arn = pipeline_execution_role_arn self.cloudformation_execution_role_arn = cloudformation_execution_role_arn self.artifacts_bucket_arn = artifacts_bucket_arn - self.create_ecr_repo = create_ecr_repo - self.ecr_repo_arn = ecr_repo_arn + self.create_image_repository = create_image_repository + self.image_repository_arn = image_repository_arn self.pipeline_ip_range = pipeline_ip_range def run(self) -> None: @@ -70,22 +70,22 @@ def run(self) -> None: default="", type=click.STRING, ) - if not self.ecr_repo_arn: + if not self.image_repository_arn: click.echo( "\nIf your SAM template includes (or going to include) Lambda functions of Image package type, " - "then an ECR repository is required. Should we create one?" + "then an ECR image repository is required. Should we create one?" ) click.echo("\t1 - No, My SAM template won't include Lambda functions of Image package type") click.echo("\t2 - Yes, I need help creating one") - click.echo("\t3 - I already have an ECR repository") + click.echo("\t3 - I already have an ECR image repository") choice = click.prompt(text="Choice", show_choices=False, type=click.Choice(["1", "2", "3"])) if choice == "1": - self.create_ecr_repo = False + self.create_image_repository = False elif choice == "2": - self.create_ecr_repo = True + self.create_image_repository = True else: # choice == "3" - self.create_ecr_repo = False - self.ecr_repo_arn = click.prompt("ECR repo", type=click.STRING) + self.create_image_repository = False + self.image_repository_arn = click.prompt("ECR image repository", type=click.STRING) if not self.pipeline_ip_range: click.echo("\nWe can deny requests not coming from a recognized IP address range.") diff --git a/samcli/lib/pipeline/bootstrap/environment.py b/samcli/lib/pipeline/bootstrap/environment.py index 196b019d91..42362c0458 100644 --- a/samcli/lib/pipeline/bootstrap/environment.py +++ b/samcli/lib/pipeline/bootstrap/environment.py @@ -8,7 +8,7 @@ from samcli.lib.config.samconfig import SamConfig from samcli.lib.utils.managed_cloudformation_stack import manage_stack, StackOutput -from .resource import Resource, IAMUser, ECRRepo +from .resource import Resource, IAMUser, ECRImageRepository CFN_TEMPLATE_PATH = str(pathlib.Path(os.path.dirname(__file__))) STACK_NAME_PREFIX = "aws-sam-cli-managed" @@ -18,7 +18,7 @@ PIPELINE_EXECUTION_ROLE = "pipeline_execution_role" CLOUDFORMATION_EXECUTION_ROLE = "cloudformation_execution_role" ARTIFACTS_BUCKET = "artifacts_bucket" -ECR_REPO = "ecr_repo" +ECR_IMAGE_REPOSITORY = "image_repository" REGION = "region" @@ -47,16 +47,16 @@ class Environment: The IAM role assumed by the CloudFormation service to executes the CloudFormation stack. artifacts_bucket: Resource The S3 bucket to hold the SAM build artifacts of the application's CFN template. - create_ecr_repo: bool - A boolean flag that determins whether the user wants to create an ECR repository or not - ecr_repo: ECRRepo - The ECR repo to hold the image container of lambda functions with Image package-type + create_image_repository: bool + A boolean flag that determines whether the user wants to create an ECR image repository or not + image_repository: ECRImageRepository + The ECR image repository to hold the image container of lambda functions with Image package-type Methods: -------- did_user_provide_all_required_resources(self) -> bool: checks if all of the environment's required resources (pipeline_user, pipeline_execution_role, - cloudformation_execution_role, artifacts_bucket and ecr_repo) are provided by the user. + cloudformation_execution_role, artifacts_bucket and image_repository) are provided by the user. bootstrap(self, confirm_changeset: bool = True) -> None: deploys the CFN template ./environment_resources.yaml to the AWS account identified by aws_profile and aws_region member fields. if aws_profile is not provided, it will fallback to default boto3 credentials' @@ -64,7 +64,7 @@ class Environment: any) as parameters and it will skip the creation of those resources but will use the ARNs to set the proper permissions of other missing resources(resources created by the template) save_config(self, config_dir: str, filename: str, cmd_names: List[str]): - save the Artifacts bucket name, ECR repo URI and ARNs of pipeline_user, pipeline_execution_role and + save the Artifacts bucket name, ECR image repository URI and ARNs of pipeline_user, pipeline_execution_role and cloudformation_execution_role to the "pipelineconfig.toml" file so that it can be auto-filled during the `sam pipeline init` command. print_resources_summary(self) -> None: @@ -81,8 +81,8 @@ def __init__( pipeline_ip_range: Optional[str] = None, cloudformation_execution_role_arn: Optional[str] = None, artifacts_bucket_arn: Optional[str] = None, - create_ecr_repo: bool = False, - ecr_repo_arn: Optional[str] = None, + create_image_repository: bool = False, + image_repository_arn: Optional[str] = None, ) -> None: self.name: str = name self.aws_profile: Optional[str] = aws_profile @@ -92,8 +92,8 @@ def __init__( self.pipeline_ip_range: Optional[str] = pipeline_ip_range self.cloudformation_execution_role: Resource = Resource(arn=cloudformation_execution_role_arn) self.artifacts_bucket: Resource = Resource(arn=artifacts_bucket_arn) - self.create_ecr_repo: bool = create_ecr_repo - self.ecr_repo: ECRRepo = ECRRepo(arn=ecr_repo_arn) + self.create_image_repository: bool = create_image_repository + self.image_repository: ECRImageRepository = ECRImageRepository(arn=image_repository_arn) def did_user_provide_all_required_resources(self) -> bool: """Check if the user provided all of the environment resources or not""" @@ -109,8 +109,8 @@ def _get_non_user_provided_resources_msg(self) -> str: missing_resources_msg += "\n\tCloudFormation execution role." if not self.artifacts_bucket.is_user_provided: missing_resources_msg += "\n\tArtifacts bucket." - if self.create_ecr_repo and not self.ecr_repo.is_user_provided: - missing_resources_msg += "\n\tECR repo." + if self.create_image_repository and not self.image_repository.is_user_provided: + missing_resources_msg += "\n\tECR image repository." return missing_resources_msg def bootstrap(self, confirm_changeset: bool = True) -> bool: @@ -120,7 +120,7 @@ def bootstrap(self, confirm_changeset: bool = True) -> bool: * Pipeline execution IAM role * CloudFormation execution IAM role * Artifacts' S3 Bucket - * ECR Repo + * ECR image repository to the AWS account associated with the given environment. It will not redeploy the stack if already exists. This CFN template accepts the ARNs of the resources as parameters and will not create a resource if already provided, this way we can conditionally create a resource only if the user didn't provide it @@ -166,8 +166,8 @@ def bootstrap(self, confirm_changeset: bool = True) -> bool: "PipelineIpRange": self.pipeline_ip_range or "", "CloudFormationExecutionRoleArn": self.cloudformation_execution_role.arn or "", "ArtifactsBucketArn": self.artifacts_bucket.arn or "", - "CreateECRRepo": "true" if self.create_ecr_repo else "false", - "ECRRepoArn": self.ecr_repo.arn or "", + "CreateImageRepository": "true" if self.create_image_repository else "false", + "ImageRepositoryArn": self.image_repository.arn or "", }, ) @@ -177,7 +177,7 @@ def bootstrap(self, confirm_changeset: bool = True) -> bool: self.pipeline_execution_role.arn = output.get("PipelineExecutionRole") self.cloudformation_execution_role.arn = output.get("CloudFormationExecutionRole") self.artifacts_bucket.arn = output.get("ArtifactsBucket") - self.ecr_repo.arn = output.get("ECRRepo") + self.image_repository.arn = output.get("ImageRepository") return True @staticmethod @@ -189,7 +189,7 @@ def _read_template(template_file_name: str) -> str: def save_config(self, config_dir: str, filename: str, cmd_names: List[str]) -> None: """ - save the Artifacts bucket name, ECR repo URI and ARNs of pipeline_user, pipeline_execution_role and + save the Artifacts bucket name, ECR image repository URI and ARNs of pipeline_user, pipeline_execution_role and cloudformation_execution_role to the given filename and directory. Parameters @@ -203,7 +203,7 @@ def save_config(self, config_dir: str, filename: str, cmd_names: List[str]) -> N Raises ------ - ValueError: if the artifacts_bucket or ecr_repo ARNs are invalid + ValueError: if the artifacts_bucket or ImageRepository ARNs are invalid """ samconfig: SamConfig = SamConfig(config_dir=config_dir, filename=filename) @@ -211,22 +211,22 @@ def save_config(self, config_dir: str, filename: str, cmd_names: List[str]) -> N if self.pipeline_user.arn: samconfig.put(cmd_names=cmd_names, section="parameters", key=PIPELINE_USER, value=self.pipeline_user.arn) - # Computing Artifacts bucket name and ECR repo URL may through an exception if the ARNs are wrong + # Computing Artifacts bucket name and ECR repository URL may through an exception if the ARNs are wrong # Let's swallow such an exception to be able to save the remaining resources try: artifacts_bucket_name: Optional[str] = self.artifacts_bucket.name() except ValueError: artifacts_bucket_name = "" try: - ecr_repo_uri: Optional[str] = self.ecr_repo.get_uri() + image_repository_uri: Optional[str] = self.image_repository.get_uri() except ValueError: - ecr_repo_uri = "" + image_repository_uri = "" environment_specific_configs: Dict[str, Optional[str]] = { PIPELINE_EXECUTION_ROLE: self.pipeline_execution_role.arn, CLOUDFORMATION_EXECUTION_ROLE: self.cloudformation_execution_role.arn, ARTIFACTS_BUCKET: artifacts_bucket_name, - ECR_REPO: ecr_repo_uri, + ECR_IMAGE_REPOSITORY: image_repository_uri, REGION: self.aws_region, } @@ -258,8 +258,8 @@ def _get_resources(self) -> List[Resource]: self.cloudformation_execution_role, self.artifacts_bucket, ] - if self.create_ecr_repo: # ECR Repo is optional - resources.append(self.ecr_repo) + if self.create_image_repository or self.image_repository.arn: # Image Repository is optional + resources.append(self.image_repository) return resources def print_resources_summary(self) -> None: diff --git a/samcli/lib/pipeline/bootstrap/environment_resources.yaml b/samcli/lib/pipeline/bootstrap/environment_resources.yaml index 61b5e72355..d8d06d2795 100644 --- a/samcli/lib/pipeline/bootstrap/environment_resources.yaml +++ b/samcli/lib/pipeline/bootstrap/environment_resources.yaml @@ -12,11 +12,11 @@ Parameters: Type: String ArtifactsBucketArn: Type: String - CreateECRRepo: + CreateImageRepository: Type: String Default: false AllowedValues: [true, false] - ECRRepoArn: + ImageRepositoryArn: Type: String Conditions: @@ -25,8 +25,8 @@ Conditions: HasPipelineIpRange: !Not [!Equals [!Ref PipelineIpRange, ""]] MissingCloudFormationExecutionRole: !Equals [!Ref CloudFormationExecutionRoleArn, ""] MissingArtifactsBucket: !Equals [!Ref ArtifactsBucketArn, ""] - ECRRepoRequired: !Equals [!Ref CreateECRRepo, "true"] - MissingECRRepo: !And [!Condition ECRRepoRequired, !Equals [!Ref ECRRepoArn, ""]] + ShouldHaveImageRepository: !Or [!Equals [!Ref CreateImageRepository, "true"], !Not [!Equals [!Ref ImageRepositoryArn, ""]]] + MissingImageRepository: !And [!Condition ShouldHaveImageRepository, !Equals [!Ref ImageRepositoryArn, ""]] Resources: PipelineUser: @@ -205,13 +205,13 @@ Resources: - - !Join [ '',[ !Ref ArtifactsBucketArn, '/*' ] ] - !Ref ArtifactsBucketArn - Fn::If: - - ECRRepoRequired + - ShouldHaveImageRepository - Effect: "Allow" Action: "ecr:GetAuthorizationToken" Resource: "*" - !Ref AWS::NoValue - Fn::If: - - ECRRepoRequired + - ShouldHaveImageRepository - Effect: "Allow" Action: - "ecr:GetDownloadUrlForLayer" @@ -223,16 +223,16 @@ Resources: - "ecr:CompleteLayerUpload" Resource: Fn::If: - - MissingECRRepo - - !GetAtt ECRRepo.Arn - - !Ref ECRRepoArn + - MissingImageRepository + - !GetAtt ImageRepository.Arn + - !Ref ImageRepositoryArn - !Ref AWS::NoValue Roles: - !Ref PipelineExecutionRole - ECRRepo: + ImageRepository: Type: AWS::ECR::Repository - Condition: MissingECRRepo + Condition: MissingImageRepository Properties: RepositoryPolicyText: Version: "2012-10-17" @@ -311,7 +311,11 @@ Outputs: - !GetAtt ArtifactsBucket.Arn - !Ref ArtifactsBucketArn - ECRRepo: - Description: ARN of the ECR repo - Condition: MissingECRRepo - Value: !GetAtt ECRRepo.Arn + ImageRepository: + Description: ARN of the ECR image repository + Condition: ShouldHaveImageRepository + Value: + Fn::If: + - MissingImageRepository + - !GetAtt ImageRepository.Arn + - !Ref ImageRepositoryArn diff --git a/samcli/lib/pipeline/bootstrap/resource.py b/samcli/lib/pipeline/bootstrap/resource.py index 8dd2462b4b..4bfd24277c 100644 --- a/samcli/lib/pipeline/bootstrap/resource.py +++ b/samcli/lib/pipeline/bootstrap/resource.py @@ -104,8 +104,8 @@ def __init__(self, arn: Optional[str], kms_key_arn: Optional[str] = None) -> Non super().__init__(arn=arn) -class ECRRepo(Resource): - """ Represents an AWS ECR repo resource """ +class ECRImageRepository(Resource): + """ Represents an AWS ECR image repository resource """ def __init__(self, arn: Optional[str]) -> None: super().__init__(arn=arn) diff --git a/tests/unit/commands/pipeline/bootstrap/test_guided_context.py b/tests/unit/commands/pipeline/bootstrap/test_guided_context.py index 47849de404..2ee4dcd676 100644 --- a/tests/unit/commands/pipeline/bootstrap/test_guided_context.py +++ b/tests/unit/commands/pipeline/bootstrap/test_guided_context.py @@ -22,8 +22,8 @@ def test_guided_context_will_not_prompt_for_fields_that_are_already_provided(sel pipeline_execution_role_arn=ANY_PIPELINE_EXECUTION_ROLE_ARN, cloudformation_execution_role_arn=ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, - create_ecr_repo=True, - ecr_repo_arn=ANY_ECR_REPO_ARN, + create_image_repository=True, + image_repository_arn=ANY_ECR_REPO_ARN, pipeline_ip_range=ANY_PIPELINE_IP_RANGE, ) gc.run() @@ -32,7 +32,7 @@ def test_guided_context_will_not_prompt_for_fields_that_are_already_provided(sel @patch("samcli.commands.pipeline.bootstrap.guided_context.click") def test_guided_context_will_prompt_for_fields_that_are_not_provided(self, click_mock): gc: GuidedContext = GuidedContext( - ecr_repo_arn=ANY_ECR_REPO_ARN # Exclude ECR repo, it has its own detailed test below + image_repository_arn=ANY_ECR_REPO_ARN # Exclude ECR repo, it has its own detailed test below ) gc.run() self.assertTrue(self.did_prompt_text_like("Environment Name", click_mock.prompt)) @@ -58,25 +58,25 @@ def test_guided_context_will_not_prompt_for_not_provided_ecr_repo_if_no_ecr_repo pipeline_ip_range=ANY_PIPELINE_IP_RANGE, ) - self.assertIsNone(gc_without_ecr_info.ecr_repo_arn) + self.assertIsNone(gc_without_ecr_info.image_repository_arn) click_mock.prompt.return_value = "1" # the user chose to not CREATE an ECR repo gc_without_ecr_info.run() - self.assertIsNone(gc_without_ecr_info.ecr_repo_arn) - self.assertFalse(gc_without_ecr_info.create_ecr_repo) + self.assertIsNone(gc_without_ecr_info.image_repository_arn) + self.assertFalse(gc_without_ecr_info.create_image_repository) self.assertFalse(self.did_prompt_text_like("ECR repo", click_mock.prompt)) click_mock.prompt.return_value = "2" # the user chose to CREATE an ECR repo gc_without_ecr_info.run() - self.assertIsNone(gc_without_ecr_info.ecr_repo_arn) - self.assertTrue(gc_without_ecr_info.create_ecr_repo) + self.assertIsNone(gc_without_ecr_info.image_repository_arn) + self.assertTrue(gc_without_ecr_info.create_image_repository) self.assertFalse(self.did_prompt_text_like("ECR repo", click_mock.prompt)) click_mock.prompt.side_effect = ["3", ANY_ECR_REPO_ARN] # the user already has a repo gc_without_ecr_info.run() - self.assertFalse(gc_without_ecr_info.create_ecr_repo) + self.assertFalse(gc_without_ecr_info.create_image_repository) self.assertTrue(self.did_prompt_text_like("ECR repo", click_mock.prompt)) # we've asked about it - self.assertEqual(gc_without_ecr_info.ecr_repo_arn, ANY_ECR_REPO_ARN) + self.assertEqual(gc_without_ecr_info.image_repository_arn, ANY_ECR_REPO_ARN) @staticmethod def did_prompt_text_like(txt, click_prompt_mock): diff --git a/tests/unit/lib/pipeline/bootstrap/test_environment.py b/tests/unit/lib/pipeline/bootstrap/test_environment.py index 5f8a77f5e8..2288a0e721 100644 --- a/tests/unit/lib/pipeline/bootstrap/test_environment.py +++ b/tests/unit/lib/pipeline/bootstrap/test_environment.py @@ -22,7 +22,7 @@ def test_environment_name_is_the_only_required_field_to_initialize_an_environmen self.assertIsNotNone(environment.pipeline_execution_role) self.assertIsNotNone(environment.cloudformation_execution_role) self.assertIsNotNone(environment.artifacts_bucket) - self.assertIsNotNone(environment.ecr_repo) + self.assertIsNotNone(environment.image_repository) with self.assertRaises(TypeError): environment = Environment() @@ -51,7 +51,7 @@ def test_did_user_provide_all_required_resources_when_not_all_resources_are_prov pipeline_execution_role_arn=ANY_PIPELINE_EXECUTION_ROLE_ARN, cloudformation_execution_role_arn=ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, - create_ecr_repo=True, + create_image_repository=True, ) self.assertFalse(environment.did_user_provide_all_required_resources()) @@ -62,7 +62,7 @@ def test_did_user_provide_all_required_resources_ignore_ecr_repo_if_it_is_not_re pipeline_execution_role_arn=ANY_PIPELINE_EXECUTION_ROLE_ARN, cloudformation_execution_role_arn=ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, - create_ecr_repo=False, + create_image_repository=False, ) self.assertTrue(environment.did_user_provide_all_required_resources()) @@ -73,7 +73,7 @@ def test_did_user_provide_all_required_resources_when_ecr_repo_is_required(self) pipeline_execution_role_arn=ANY_PIPELINE_EXECUTION_ROLE_ARN, cloudformation_execution_role_arn=ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, - create_ecr_repo=True, + create_image_repository=True, ) self.assertFalse(environment.did_user_provide_all_required_resources()) environment: Environment = Environment( @@ -82,8 +82,8 @@ def test_did_user_provide_all_required_resources_when_ecr_repo_is_required(self) pipeline_execution_role_arn=ANY_PIPELINE_EXECUTION_ROLE_ARN, cloudformation_execution_role_arn=ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, - create_ecr_repo=True, - ecr_repo_arn=ANY_ECR_REPO_ARN, + create_image_repository=True, + image_repository_arn=ANY_ECR_REPO_ARN, ) self.assertTrue(environment.did_user_provide_all_required_resources()) @@ -106,7 +106,7 @@ def test_did_user_provide_all_required_resources_returns_false_if_the_environmen self.assertEqual(ANY_ARN, environment.pipeline_execution_role.arn) self.assertEqual(ANY_ARN, environment.cloudformation_execution_role.arn) self.assertEqual(ANY_ARN, environment.artifacts_bucket.arn) - self.assertEqual(ANY_ARN, environment.ecr_repo.arn) + self.assertEqual(ANY_ARN, environment.image_repository.arn) # although all of the resources got fulfilled, `did_user_provide_all_required_resources` should return false # as these resources are not provided by the user @@ -166,8 +166,8 @@ def test_bootstrap_will_pass_arns_of_all_user_provided_resources_any_empty_strin name=ANY_ENVIRONMENT_NAME, pipeline_user_arn=ANY_PIPELINE_USER_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, - create_ecr_repo=True, - ecr_repo_arn=ANY_ECR_REPO_ARN, + create_image_repository=True, + image_repository_arn=ANY_ECR_REPO_ARN, ) environment.bootstrap() manage_stack_mock.assert_called_once() @@ -261,7 +261,7 @@ def test_save_config_escapes_none_resources(self, samconfig_mock): ) self.trigger_and_assert_save_config_calls(environment, cmd_names, expected_calls, samconfig_instance_mock.put) - environment.ecr_repo.arn = "arn:aws:ecr:us-east-2:111111111111:repository/ecr_repo_name" + environment.image_repository.arn = "arn:aws:ecr:us-east-2:111111111111:repository/ecr_repo_name" expected_calls.append( call( cmd_names=cmd_names, @@ -294,7 +294,7 @@ def test_save_config_ignores_exceptions_thrown_while_calculating_artifacts_bucke def test_save_config_ignores_exceptions_thrown_while_calculating_ecr_repo_uri(self, samconfig_mock): samconfig_instance_mock = Mock() samconfig_mock.return_value = samconfig_instance_mock - environment: Environment = Environment(name=ANY_ENVIRONMENT_NAME, ecr_repo_arn="invalid ARN") + environment: Environment = Environment(name=ANY_ENVIRONMENT_NAME, image_repository_arn="invalid ARN") # calling ecr_repo.get_uri() during save_config() will raise a ValueError exception, we need to make sure # this exception is swallowed so that other configs can be safely saved to the pipelineconfig.toml file environment.save_config( @@ -323,8 +323,8 @@ def test_print_resources_summary_when_all_resources_are_provided_by_the_user(sel pipeline_execution_role_arn=ANY_PIPELINE_EXECUTION_ROLE_ARN, cloudformation_execution_role_arn=ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, - create_ecr_repo=True, - ecr_repo_arn=ANY_ECR_REPO_ARN, + create_image_repository=True, + image_repository_arn=ANY_ECR_REPO_ARN, ) environment.print_resources_summary() self.assert_summary_does_not_have_a_message_like("We have created the following resources", click_mock.secho) @@ -336,8 +336,8 @@ def test_print_resources_summary_when_some_resources_are_provided_by_the_user(se name=ANY_ENVIRONMENT_NAME, pipeline_user_arn=ANY_PIPELINE_USER_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, - create_ecr_repo=True, - ecr_repo_arn=ANY_ECR_REPO_ARN, + create_image_repository=True, + image_repository_arn=ANY_ECR_REPO_ARN, ) environment.print_resources_summary() self.assert_summary_has_a_message_like("We have created the following resources", click_mock.secho) diff --git a/tests/unit/lib/pipeline/bootstrap/test_resource.py b/tests/unit/lib/pipeline/bootstrap/test_resource.py index be7a9d3c31..ab32e4c566 100644 --- a/tests/unit/lib/pipeline/bootstrap/test_resource.py +++ b/tests/unit/lib/pipeline/bootstrap/test_resource.py @@ -1,6 +1,6 @@ from unittest import TestCase -from samcli.lib.pipeline.bootstrap.resource import ARNParts, Resource, IAMUser, ECRRepo +from samcli.lib.pipeline.bootstrap.resource import ARNParts, Resource, IAMUser, ECRImageRepository VALID_ARN = "arn:partition:service:region:account-id:resource-id" INVALID_ARN = "ARN" @@ -56,11 +56,11 @@ def test_create_iam_user(self): class TestECRRepo(TestCase): def test_get_uri_with_valid_ecr_arn(self): valid_ecr_arn = "arn:partition:service:region:account-id:repository/repository-name" - repo: ECRRepo = ECRRepo(arn=valid_ecr_arn) + repo: ECRImageRepository = ECRImageRepository(arn=valid_ecr_arn) self.assertEqual(repo.get_uri(), "account-id.dkr.ecr.region.amazonaws.com/repository-name") def test_get_uri_with_invalid_ecr_arn(self): - repo = ECRRepo(arn=INVALID_ARN) + repo = ECRImageRepository(arn=INVALID_ARN) with self.assertRaises(ValueError): repo.get_uri() @@ -68,6 +68,6 @@ def test_get_uri_with_valid_aws_arn_that_is_invalid_ecr_arn(self): ecr_arn_missing_repository_prefix = ( "arn:partition:service:region:account-id:repository-name-without-repository/-prefix" ) - repo = ECRRepo(arn=ecr_arn_missing_repository_prefix) + repo = ECRImageRepository(arn=ecr_arn_missing_repository_prefix) with self.assertRaises(ValueError): repo.get_uri() From 4ec4e06eea67d5859dc68173b91b12888c1a3e4d Mon Sep 17 00:00:00 2001 From: Ahmed Elbayaa Date: Thu, 27 May 2021 15:44:40 -0700 Subject: [PATCH 2/4] UT Fixes --- samcli/lib/pipeline/bootstrap/environment.py | 2 +- samcli/lib/pipeline/bootstrap/resource.py | 2 +- .../commands/pipeline/bootstrap/test_cli.py | 20 ++++++------- .../pipeline/bootstrap/test_guided_context.py | 28 +++++++++-------- .../pipeline/bootstrap/test_environment.py | 30 +++++++++---------- .../lib/pipeline/bootstrap/test_resource.py | 2 +- 6 files changed, 43 insertions(+), 41 deletions(-) diff --git a/samcli/lib/pipeline/bootstrap/environment.py b/samcli/lib/pipeline/bootstrap/environment.py index 42362c0458..eb87a8167b 100644 --- a/samcli/lib/pipeline/bootstrap/environment.py +++ b/samcli/lib/pipeline/bootstrap/environment.py @@ -211,7 +211,7 @@ def save_config(self, config_dir: str, filename: str, cmd_names: List[str]) -> N if self.pipeline_user.arn: samconfig.put(cmd_names=cmd_names, section="parameters", key=PIPELINE_USER, value=self.pipeline_user.arn) - # Computing Artifacts bucket name and ECR repository URL may through an exception if the ARNs are wrong + # Computing Artifacts bucket name and ECR image repository URL may through an exception if the ARNs are wrong # Let's swallow such an exception to be able to save the remaining resources try: artifacts_bucket_name: Optional[str] = self.artifacts_bucket.name() diff --git a/samcli/lib/pipeline/bootstrap/resource.py b/samcli/lib/pipeline/bootstrap/resource.py index 4bfd24277c..a2bd3cb284 100644 --- a/samcli/lib/pipeline/bootstrap/resource.py +++ b/samcli/lib/pipeline/bootstrap/resource.py @@ -112,7 +112,7 @@ def __init__(self, arn: Optional[str]) -> None: def get_uri(self) -> Optional[str]: """ - extracts and returns the URI of the given ECR repo from its ARN + extracts and returns the URI of the given ECR image repository from its ARN see https://docs.aws.amazon.com/AmazonECR/latest/userguide/Registries.html Raises ------ diff --git a/tests/unit/commands/pipeline/bootstrap/test_cli.py b/tests/unit/commands/pipeline/bootstrap/test_cli.py index e6730dc6a9..f843e9fded 100644 --- a/tests/unit/commands/pipeline/bootstrap/test_cli.py +++ b/tests/unit/commands/pipeline/bootstrap/test_cli.py @@ -20,7 +20,7 @@ ANY_PIPELINE_EXECUTION_ROLE_ARN = "ANY_PIPELINE_EXECUTION_ROLE_ARN" ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN = "ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN" ANY_ARTIFACTS_BUCKET_ARN = "ANY_ARTIFACTS_BUCKET_ARN" -ANY_ECR_REPO_ARN = "ANY_ECR_REPO_ARN" +ANY_IMAGE_REPOSITORY_ARN = "ANY_IMAGE_REPOSITORY_ARN" ANY_ARN = "ANY_ARN" ANY_PIPELINE_IP_RANGE = "111.222.333.0/24" ANY_CONFIG_FILE = "ANY_CONFIG_FILE" @@ -39,8 +39,8 @@ def setUp(self) -> None: "pipeline_execution_role_arn": ANY_PIPELINE_EXECUTION_ROLE_ARN, "cloudformation_execution_role_arn": ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN, "artifacts_bucket_arn": ANY_ARTIFACTS_BUCKET_ARN, - "create_ecr_repo": True, - "ecr_repo_arn": ANY_ECR_REPO_ARN, + "create_image_repository": True, + "image_repository_arn": ANY_IMAGE_REPOSITORY_ARN, "pipeline_ip_range": ANY_PIPELINE_IP_RANGE, "confirm_changeset": True, "config_file": ANY_CONFIG_FILE, @@ -53,7 +53,7 @@ def test_bootstrap_command_default_argument_values(self, do_cli_mock): runner.invoke(bootstrap_cmd) # Test the defaults are as following: # interactive -> True - # create_ecr_repo -> False + # create_image_repository -> False # confirm_changeset -> True # region, profile, environment_name and all ARNs are None do_cli_mock.assert_called_once_with( @@ -65,8 +65,8 @@ def test_bootstrap_command_default_argument_values(self, do_cli_mock): pipeline_execution_role_arn=None, cloudformation_execution_role_arn=None, artifacts_bucket_arn=None, - create_ecr_repo=False, - ecr_repo_arn=None, + create_image_repository=False, + image_repository_arn=None, pipeline_ip_range=None, confirm_changeset=True, config_file="default", @@ -76,16 +76,16 @@ def test_bootstrap_command_default_argument_values(self, do_cli_mock): @patch("samcli.commands.pipeline.bootstrap.cli.do_cli") def test_bootstrap_command_flag_arguments(self, do_cli_mock): runner: CliRunner = CliRunner() - runner.invoke(bootstrap_cmd, args=["--interactive", "--no-create-ecr-repo", "--confirm-changeset"]) + runner.invoke(bootstrap_cmd, args=["--interactive", "--no-create-image-repository", "--confirm-changeset"]) args, kwargs = do_cli_mock.call_args self.assertTrue(kwargs["interactive"]) - self.assertFalse(kwargs["create_ecr_repo"]) + self.assertFalse(kwargs["create_image_repository"]) self.assertTrue(kwargs["confirm_changeset"]) - runner.invoke(bootstrap_cmd, args=["--no-interactive", "--create-ecr-repo", "--no-confirm-changeset"]) + runner.invoke(bootstrap_cmd, args=["--no-interactive", "--create-image-repository", "--no-confirm-changeset"]) args, kwargs = do_cli_mock.call_args self.assertFalse(kwargs["interactive"]) - self.assertTrue(kwargs["create_ecr_repo"]) + self.assertTrue(kwargs["create_image_repository"]) self.assertFalse(kwargs["confirm_changeset"]) @patch("samcli.commands.pipeline.bootstrap.cli.do_cli") diff --git a/tests/unit/commands/pipeline/bootstrap/test_guided_context.py b/tests/unit/commands/pipeline/bootstrap/test_guided_context.py index 2ee4dcd676..0879b902a4 100644 --- a/tests/unit/commands/pipeline/bootstrap/test_guided_context.py +++ b/tests/unit/commands/pipeline/bootstrap/test_guided_context.py @@ -8,7 +8,7 @@ ANY_PIPELINE_EXECUTION_ROLE_ARN = "ANY_PIPELINE_EXECUTION_ROLE_ARN" ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN = "ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN" ANY_ARTIFACTS_BUCKET_ARN = "ANY_ARTIFACTS_BUCKET_ARN" -ANY_ECR_REPO_ARN = "ANY_ECR_REPO_ARN" +ANY_IMAGE_REPOSITORY_ARN = "ANY_IMAGE_REPOSITORY_ARN" ANY_ARN = "ANY_ARN" ANY_PIPELINE_IP_RANGE = "111.222.333.0/24" @@ -23,7 +23,7 @@ def test_guided_context_will_not_prompt_for_fields_that_are_already_provided(sel cloudformation_execution_role_arn=ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, create_image_repository=True, - image_repository_arn=ANY_ECR_REPO_ARN, + image_repository_arn=ANY_IMAGE_REPOSITORY_ARN, pipeline_ip_range=ANY_PIPELINE_IP_RANGE, ) gc.run() @@ -32,7 +32,7 @@ def test_guided_context_will_not_prompt_for_fields_that_are_already_provided(sel @patch("samcli.commands.pipeline.bootstrap.guided_context.click") def test_guided_context_will_prompt_for_fields_that_are_not_provided(self, click_mock): gc: GuidedContext = GuidedContext( - image_repository_arn=ANY_ECR_REPO_ARN # Exclude ECR repo, it has its own detailed test below + image_repository_arn=ANY_IMAGE_REPOSITORY_ARN # Exclude ECR repo, it has its own detailed test below ) gc.run() self.assertTrue(self.did_prompt_text_like("Environment Name", click_mock.prompt)) @@ -44,11 +44,13 @@ def test_guided_context_will_prompt_for_fields_that_are_not_provided(self, click self.assertTrue(self.did_prompt_text_like("Pipeline IP address range", click_mock.prompt)) @patch("samcli.commands.pipeline.bootstrap.guided_context.click") - def test_guided_context_will_not_prompt_for_not_provided_ecr_repo_if_no_ecr_repo_is_required(self, click_mock): - # ECR Repo choices: + def test_guided_context_will_not_prompt_for_not_provided_image_repository_if_no_image_repository_is_required( + self, click_mock + ): + # ECR Image Repository choices: # 1 - No, My SAM Template won't include lambda functions of Image package-type # 2 - Yes, I need a help creating one - # 3 - I already have an ECR repo + # 3 - I already have an ECR image repository gc_without_ecr_info: GuidedContext = GuidedContext( environment_name=ANY_ENVIRONMENT_NAME, pipeline_user_arn=ANY_PIPELINE_USER_ARN, @@ -60,23 +62,23 @@ def test_guided_context_will_not_prompt_for_not_provided_ecr_repo_if_no_ecr_repo self.assertIsNone(gc_without_ecr_info.image_repository_arn) - click_mock.prompt.return_value = "1" # the user chose to not CREATE an ECR repo + click_mock.prompt.return_value = "1" # the user chose to not CREATE an ECR Image repository gc_without_ecr_info.run() self.assertIsNone(gc_without_ecr_info.image_repository_arn) self.assertFalse(gc_without_ecr_info.create_image_repository) - self.assertFalse(self.did_prompt_text_like("ECR repo", click_mock.prompt)) + self.assertFalse(self.did_prompt_text_like("ECR image repository", click_mock.prompt)) - click_mock.prompt.return_value = "2" # the user chose to CREATE an ECR repo + click_mock.prompt.return_value = "2" # the user chose to CREATE an ECR Image repository gc_without_ecr_info.run() self.assertIsNone(gc_without_ecr_info.image_repository_arn) self.assertTrue(gc_without_ecr_info.create_image_repository) - self.assertFalse(self.did_prompt_text_like("ECR repo", click_mock.prompt)) + self.assertFalse(self.did_prompt_text_like("ECR image repository", click_mock.prompt)) - click_mock.prompt.side_effect = ["3", ANY_ECR_REPO_ARN] # the user already has a repo + click_mock.prompt.side_effect = ["3", ANY_IMAGE_REPOSITORY_ARN] # the user already has a repo gc_without_ecr_info.run() self.assertFalse(gc_without_ecr_info.create_image_repository) - self.assertTrue(self.did_prompt_text_like("ECR repo", click_mock.prompt)) # we've asked about it - self.assertEqual(gc_without_ecr_info.image_repository_arn, ANY_ECR_REPO_ARN) + self.assertTrue(self.did_prompt_text_like("ECR image repository", click_mock.prompt)) # we've asked about it + self.assertEqual(gc_without_ecr_info.image_repository_arn, ANY_IMAGE_REPOSITORY_ARN) @staticmethod def did_prompt_text_like(txt, click_prompt_mock): diff --git a/tests/unit/lib/pipeline/bootstrap/test_environment.py b/tests/unit/lib/pipeline/bootstrap/test_environment.py index 2288a0e721..88c4361382 100644 --- a/tests/unit/lib/pipeline/bootstrap/test_environment.py +++ b/tests/unit/lib/pipeline/bootstrap/test_environment.py @@ -8,7 +8,7 @@ ANY_PIPELINE_EXECUTION_ROLE_ARN = "ANY_PIPELINE_EXECUTION_ROLE_ARN" ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN = "ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN" ANY_ARTIFACTS_BUCKET_ARN = "ANY_ARTIFACTS_BUCKET_ARN" -ANY_ECR_REPO_ARN = "ANY_ECR_REPO_ARN" +ANY_IMAGE_REPOSITORY_ARN = "ANY_IMAGE_REPOSITORY_ARN" ANY_ARN = "ANY_ARN" @@ -55,7 +55,7 @@ def test_did_user_provide_all_required_resources_when_not_all_resources_are_prov ) self.assertFalse(environment.did_user_provide_all_required_resources()) - def test_did_user_provide_all_required_resources_ignore_ecr_repo_if_it_is_not_required(self): + def test_did_user_provide_all_required_resources_ignore_image_repository_if_it_is_not_required(self): environment: Environment = Environment( name=ANY_ENVIRONMENT_NAME, pipeline_user_arn=ANY_PIPELINE_USER_ARN, @@ -66,7 +66,7 @@ def test_did_user_provide_all_required_resources_ignore_ecr_repo_if_it_is_not_re ) self.assertTrue(environment.did_user_provide_all_required_resources()) - def test_did_user_provide_all_required_resources_when_ecr_repo_is_required(self): + def test_did_user_provide_all_required_resources_when_image_repository_is_required(self): environment: Environment = Environment( name=ANY_ENVIRONMENT_NAME, pipeline_user_arn=ANY_PIPELINE_USER_ARN, @@ -83,7 +83,7 @@ def test_did_user_provide_all_required_resources_when_ecr_repo_is_required(self) cloudformation_execution_role_arn=ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, create_image_repository=True, - image_repository_arn=ANY_ECR_REPO_ARN, + image_repository_arn=ANY_IMAGE_REPOSITORY_ARN, ) self.assertTrue(environment.did_user_provide_all_required_resources()) @@ -167,7 +167,7 @@ def test_bootstrap_will_pass_arns_of_all_user_provided_resources_any_empty_strin pipeline_user_arn=ANY_PIPELINE_USER_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, create_image_repository=True, - image_repository_arn=ANY_ECR_REPO_ARN, + image_repository_arn=ANY_IMAGE_REPOSITORY_ARN, ) environment.bootstrap() manage_stack_mock.assert_called_once() @@ -178,8 +178,8 @@ def test_bootstrap_will_pass_arns_of_all_user_provided_resources_any_empty_strin "PipelineIpRange": "", "CloudFormationExecutionRoleArn": "", "ArtifactsBucketArn": ANY_ARTIFACTS_BUCKET_ARN, - "CreateECRRepo": "true", - "ECRRepoArn": ANY_ECR_REPO_ARN, + "CreateImageRepository": "true", + "ImageRepositoryArn": ANY_IMAGE_REPOSITORY_ARN, } self.assertEqual(expected_parameter_overrides, kwargs["parameter_overrides"]) @@ -261,14 +261,14 @@ def test_save_config_escapes_none_resources(self, samconfig_mock): ) self.trigger_and_assert_save_config_calls(environment, cmd_names, expected_calls, samconfig_instance_mock.put) - environment.image_repository.arn = "arn:aws:ecr:us-east-2:111111111111:repository/ecr_repo_name" + environment.image_repository.arn = "arn:aws:ecr:us-east-2:111111111111:repository/image_repository_name" expected_calls.append( call( cmd_names=cmd_names, section="parameters", env=ANY_ENVIRONMENT_NAME, - key="ecr_repo", - value="111111111111.dkr.ecr.us-east-2.amazonaws.com/ecr_repo_name", + key="image_repository", + value="111111111111.dkr.ecr.us-east-2.amazonaws.com/image_repository_name", ) ) self.trigger_and_assert_save_config_calls(environment, cmd_names, expected_calls, samconfig_instance_mock.put) @@ -291,12 +291,12 @@ def test_save_config_ignores_exceptions_thrown_while_calculating_artifacts_bucke ) @patch("samcli.lib.pipeline.bootstrap.environment.SamConfig") - def test_save_config_ignores_exceptions_thrown_while_calculating_ecr_repo_uri(self, samconfig_mock): + def test_save_config_ignores_exceptions_thrown_while_calculating_image_repository_uri(self, samconfig_mock): samconfig_instance_mock = Mock() samconfig_mock.return_value = samconfig_instance_mock environment: Environment = Environment(name=ANY_ENVIRONMENT_NAME, image_repository_arn="invalid ARN") - # calling ecr_repo.get_uri() during save_config() will raise a ValueError exception, we need to make sure - # this exception is swallowed so that other configs can be safely saved to the pipelineconfig.toml file + # calling image_repository.get_uri() during save_config() will raise a ValueError exception, we need to make + # sure this exception is swallowed so that other configs can be safely saved to the pipelineconfig.toml file environment.save_config( config_dir="any_config_dir", filename="any_pipeline.toml", cmd_names=["any", "commands"] ) @@ -324,7 +324,7 @@ def test_print_resources_summary_when_all_resources_are_provided_by_the_user(sel cloudformation_execution_role_arn=ANY_CLOUDFORMATION_EXECUTION_ROLE_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, create_image_repository=True, - image_repository_arn=ANY_ECR_REPO_ARN, + image_repository_arn=ANY_IMAGE_REPOSITORY_ARN, ) environment.print_resources_summary() self.assert_summary_does_not_have_a_message_like("We have created the following resources", click_mock.secho) @@ -337,7 +337,7 @@ def test_print_resources_summary_when_some_resources_are_provided_by_the_user(se pipeline_user_arn=ANY_PIPELINE_USER_ARN, artifacts_bucket_arn=ANY_ARTIFACTS_BUCKET_ARN, create_image_repository=True, - image_repository_arn=ANY_ECR_REPO_ARN, + image_repository_arn=ANY_IMAGE_REPOSITORY_ARN, ) environment.print_resources_summary() self.assert_summary_has_a_message_like("We have created the following resources", click_mock.secho) diff --git a/tests/unit/lib/pipeline/bootstrap/test_resource.py b/tests/unit/lib/pipeline/bootstrap/test_resource.py index ab32e4c566..7e3ef507da 100644 --- a/tests/unit/lib/pipeline/bootstrap/test_resource.py +++ b/tests/unit/lib/pipeline/bootstrap/test_resource.py @@ -53,7 +53,7 @@ def test_create_iam_user(self): self.assertEquals(user.secret_access_key, "any_secret_access_key") -class TestECRRepo(TestCase): +class TestECRImageRepository(TestCase): def test_get_uri_with_valid_ecr_arn(self): valid_ecr_arn = "arn:partition:service:region:account-id:repository/repository-name" repo: ECRImageRepository = ECRImageRepository(arn=valid_ecr_arn) From d221c97d39bc97ec11743d6842e2993477a556a5 Mon Sep 17 00:00:00 2001 From: Ahmed Elbayaa Date: Thu, 27 May 2021 17:36:41 -0700 Subject: [PATCH 3/4] typo --- samcli/commands/pipeline/bootstrap/cli.py | 8 ++++---- samcli/commands/pipeline/init/interactive_init_flow.py | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/samcli/commands/pipeline/bootstrap/cli.py b/samcli/commands/pipeline/bootstrap/cli.py index 5cf70632fb..c22300cefb 100644 --- a/samcli/commands/pipeline/bootstrap/cli.py +++ b/samcli/commands/pipeline/bootstrap/cli.py @@ -22,7 +22,7 @@ \n\t - Pipeline execution IAM role assumed by the pipeline user to obtain access to the AWS account \n\t - CloudFormation execution IAM role assumed by CloudFormation to deploy the AWS SAM application \n\t - Artifacts S3 bucket to hold the AWS SAM build artifacts -\n\t - Optionally, an ECR repository to hold container image Lambda deployment packages +\n\t - Optionally, an ECR image repository to hold container image Lambda deployment packages """ PIPELINE_CONFIG_DIR = os.path.join(".aws-sam", "pipeline") @@ -71,12 +71,12 @@ "--create-image-repository/--no-create-image-repository", is_flag=True, default=False, - help="If set to true and no ECR repository is provided, this command will create an ECR repository to hold the" - " container images of Lambda functions having an Image package type.", + help="If set to true and no ECR image repository is provided, this command will create an ECR image repository " + "to hold the container images of Lambda functions having an Image package type.", ) @click.option( "--image-repository", - help="The ARN of an ECR repository to hold the containers images of Lambda functions of Image package type. " + help="The ARN of an ECR image repository to hold the containers images of Lambda functions of Image package type. " "If provided, the --create-image-repository argument is ignored. If not provided and --create-image-repository is " "set to true, the command will create one.", required=False, diff --git a/samcli/commands/pipeline/init/interactive_init_flow.py b/samcli/commands/pipeline/init/interactive_init_flow.py index 2091d87dbc..f6c093f671 100644 --- a/samcli/commands/pipeline/init/interactive_init_flow.py +++ b/samcli/commands/pipeline/init/interactive_init_flow.py @@ -23,7 +23,7 @@ LOG = logging.getLogger(__name__) shared_path: Path = global_cfg.config_dir -APP_PIPELINE_TEMPLATES_REPO_URL = "https://github.com/aws/aws-sam-cli-pipeline-init-templates.git" +APP_PIPELINE_TEMPLATES_REPO_URL = "https://github.com/elbayaaa/aws-sam-cli-pipeline-init-templates.git" APP_PIPELINE_TEMPLATES_REPO_LOCAL_NAME = "aws-sam-cli-app-pipeline-templates" CUSTOM_PIPELINE_TEMPLATE_REPO_LOCAL_NAME = "custom-pipeline-template" SAM_PIPELINE_TEMPLATE_SOURCE = "AWS Quick Start Pipeline Templates" @@ -92,7 +92,6 @@ def _load_pipeline_bootstrap_context() -> Dict: config = SamConfig(PIPELINE_CONFIG_DIR, PIPELINE_CONFIG_FILENAME) if not config.exists(): return context - for env in config.get_env_names(): for key, value in config.get_all(bootstrap_command_names, section, env).items(): context[str([env, key])] = value From fde9677297cb67b2ff3ddd8f1b9f24c57407c3b3 Mon Sep 17 00:00:00 2001 From: Ahmed Elbayaa Date: Thu, 27 May 2021 17:40:48 -0700 Subject: [PATCH 4/4] typo --- samcli/commands/pipeline/init/interactive_init_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samcli/commands/pipeline/init/interactive_init_flow.py b/samcli/commands/pipeline/init/interactive_init_flow.py index f6c093f671..ef7a6287a1 100644 --- a/samcli/commands/pipeline/init/interactive_init_flow.py +++ b/samcli/commands/pipeline/init/interactive_init_flow.py @@ -23,7 +23,7 @@ LOG = logging.getLogger(__name__) shared_path: Path = global_cfg.config_dir -APP_PIPELINE_TEMPLATES_REPO_URL = "https://github.com/elbayaaa/aws-sam-cli-pipeline-init-templates.git" +APP_PIPELINE_TEMPLATES_REPO_URL = "https://github.com/aws/aws-sam-cli-pipeline-init-templates.git" APP_PIPELINE_TEMPLATES_REPO_LOCAL_NAME = "aws-sam-cli-app-pipeline-templates" CUSTOM_PIPELINE_TEMPLATE_REPO_LOCAL_NAME = "custom-pipeline-template" SAM_PIPELINE_TEMPLATE_SOURCE = "AWS Quick Start Pipeline Templates"