From 2fa5155c7f8773c882ffbb1495075a9a5a6d2ab2 Mon Sep 17 00:00:00 2001 From: Greg Hoggard Date: Wed, 5 Dec 2018 10:52:27 -0500 Subject: [PATCH 1/3] Added conditional statements to determine parameters based on an S3 SourceProvider --- .../cloudformation/artifact-pipeline.yml | 20 ++++++++++++++++++- templates/assets/cloudformation/pipeline.yml | 8 ++++++-- workflows/pipeline_upsert.go | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/templates/assets/cloudformation/artifact-pipeline.yml b/templates/assets/cloudformation/artifact-pipeline.yml index f855fc05..9036fd73 100644 --- a/templates/assets/cloudformation/artifact-pipeline.yml +++ b/templates/assets/cloudformation/artifact-pipeline.yml @@ -11,6 +11,16 @@ Parameters: SourceBranch: Type: String Description: Branch to trigger pipeline + {{if eq .SourceProvider "S3" -}} + SourceBucket: + Type: String + Description: Source Bucket + Default: "" + SourceObjectKey: + Type: String + Description: Source Object Key + Default: "" + {{- end}} {{if eq .SourceProvider "GitHub" -}} GitHubToken: NoEcho: true @@ -90,6 +100,10 @@ Resources: CodeDeployBucket: {{ .CodeDeployBucket }} SourceProvider: {{ .SourceProvider }} SourceRepo: !Ref SourceRepo + {{if eq .SourceProvider "S3" -}} + SourceBucket: !Ref SourceBucket + SourceObjectKey: !Ref SourceObjectKey + {{- end}} {{if eq .EnableAcptStage "true" -}} AcptEnv: {{ .AcptEnv }} {{- end}} @@ -103,7 +117,7 @@ Resources: AcptCloudFormationRoleArn: {{ .AcptCloudFormationRoleArn }} {{- end}} {{if eq .EnableProdStage "true" -}} - ProdCloudFormationRoleArn: {{ .ProdCloudFormationRoleArn }} + ProdCloudFormationRoleArn: {{ .ProdCloudFormationRoleArn }} {{- end}} Tags: - Key: mu:name @@ -130,6 +144,10 @@ Resources: SourceProvider: {{ .SourceProvider }} SourceRepo: !Ref SourceRepo SourceBranch: !Ref SourceBranch + {{if eq .SourceProvider "S3" -}} + SourceBucket: !Ref SourceBucket + SourceObjectKey: !Ref SourceObjectKey + {{- end}} {{if eq .SourceProvider "GitHub" -}} GitHubToken: !Ref GitHubToken {{- end}} diff --git a/templates/assets/cloudformation/pipeline.yml b/templates/assets/cloudformation/pipeline.yml index 0d1b3c56..fa1a66b5 100644 --- a/templates/assets/cloudformation/pipeline.yml +++ b/templates/assets/cloudformation/pipeline.yml @@ -428,8 +428,12 @@ Resources: - HasGitHubToken - !Ref GitHubToken - !Ref AWS::NoValue - - RepositoryName: !Ref SourceRepo - BranchName: !Ref SourceBranch + - + Fn::If: + - IsCodeCommit + - RepositoryName: !Ref SourceRepo + BranchName: !Ref SourceBranch + - !Ref AWS::NoValue RunOrder: 10 - Fn::If: - IsBuildEnabled diff --git a/workflows/pipeline_upsert.go b/workflows/pipeline_upsert.go index 00bb0a0b..379cb860 100644 --- a/workflows/pipeline_upsert.go +++ b/workflows/pipeline_upsert.go @@ -254,7 +254,7 @@ func (workflow *pipelineWorkflow) pipelineCatalogUpserter(namespace string, pipe productParams["ServiceName"] = workflow.serviceName productParams["SourceBranch"] = workflow.codeBranch productParams["SourceRepo"] = pipeline.Source.Repo - productParams["GitHubToken"] = params["GitHubToken"] + //productParams["GitHubToken"] = params["GitHubToken"] return catalogProvisioner.UpsertProvisionedProduct(stack.Outputs["ProductId"], pipeline.Catalog.Version, fmt.Sprintf("%s-%s", namespace, workflow.serviceName), productParams) } From 40f9a26fd133e971d7f02333ca8a098e29896545 Mon Sep 17 00:00:00 2001 From: Greg Hoggard Date: Wed, 5 Dec 2018 12:23:47 -0500 Subject: [PATCH 2/3] Add conditional for CodeCommit in Source ActionTypeId. Added conditional statement in the pipelineCatalogUpserter workflow of pipeline_upsert.go that adds the SourceBucket and SourceObjectKey parameters if the SourceProvider is S3 --- templates/assets/cloudformation/pipeline.yml | 12 ++++++++---- workflows/pipeline_upsert.go | 11 ++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/templates/assets/cloudformation/pipeline.yml b/templates/assets/cloudformation/pipeline.yml index fa1a66b5..01a30480 100644 --- a/templates/assets/cloudformation/pipeline.yml +++ b/templates/assets/cloudformation/pipeline.yml @@ -408,10 +408,14 @@ Resources: Owner: ThirdParty Version: '1' Provider: GitHub - - Category: Source - Owner: AWS - Version: '1' - Provider: CodeCommit + - + Fn::If: + - IsCodeCommit + - Category: Source + Owner: AWS + Version: '1' + Provider: CodeCommit + - !Ref AWS::NoValue Configuration: Fn::If: - IsS3 diff --git a/workflows/pipeline_upsert.go b/workflows/pipeline_upsert.go index 379cb860..b35d8887 100644 --- a/workflows/pipeline_upsert.go +++ b/workflows/pipeline_upsert.go @@ -254,7 +254,16 @@ func (workflow *pipelineWorkflow) pipelineCatalogUpserter(namespace string, pipe productParams["ServiceName"] = workflow.serviceName productParams["SourceBranch"] = workflow.codeBranch productParams["SourceRepo"] = pipeline.Source.Repo - //productParams["GitHubToken"] = params["GitHubToken"] + + if pipeline.Source.Provider == "GitHub" { + productParams["GitHubToken"] = params["GitHubToken"] + } + + if pipeline.Source.Provider == "S3" { + repoParts := strings.Split(pipeline.Source.Repo, "/") + productParams["SourceBucket"] = repoParts[0] + productParams["SourceObjectKey"] = strings.Join(repoParts[1:], "/") + } return catalogProvisioner.UpsertProvisionedProduct(stack.Outputs["ProductId"], pipeline.Catalog.Version, fmt.Sprintf("%s-%s", namespace, workflow.serviceName), productParams) } From 6315336406a27b172cb40ad29b2954403fbe1064 Mon Sep 17 00:00:00 2001 From: Greg Hoggard Date: Wed, 5 Dec 2018 17:09:11 -0500 Subject: [PATCH 3/3] Remove unnecessary Fn::If statements. Fix issue where pipelineCatalogUpserter was not passing the correct value of the SourceBranch --- templates/assets/cloudformation/pipeline.yml | 20 ++++++-------------- workflows/pipeline_upsert.go | 7 ++++++- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/templates/assets/cloudformation/pipeline.yml b/templates/assets/cloudformation/pipeline.yml index 01a30480..0d1b3c56 100644 --- a/templates/assets/cloudformation/pipeline.yml +++ b/templates/assets/cloudformation/pipeline.yml @@ -408,14 +408,10 @@ Resources: Owner: ThirdParty Version: '1' Provider: GitHub - - - Fn::If: - - IsCodeCommit - - Category: Source - Owner: AWS - Version: '1' - Provider: CodeCommit - - !Ref AWS::NoValue + - Category: Source + Owner: AWS + Version: '1' + Provider: CodeCommit Configuration: Fn::If: - IsS3 @@ -432,12 +428,8 @@ Resources: - HasGitHubToken - !Ref GitHubToken - !Ref AWS::NoValue - - - Fn::If: - - IsCodeCommit - - RepositoryName: !Ref SourceRepo - BranchName: !Ref SourceBranch - - !Ref AWS::NoValue + - RepositoryName: !Ref SourceRepo + BranchName: !Ref SourceBranch RunOrder: 10 - Fn::If: - IsBuildEnabled diff --git a/workflows/pipeline_upsert.go b/workflows/pipeline_upsert.go index b35d8887..fba441a1 100644 --- a/workflows/pipeline_upsert.go +++ b/workflows/pipeline_upsert.go @@ -252,9 +252,14 @@ func (workflow *pipelineWorkflow) pipelineCatalogUpserter(namespace string, pipe productParams := make(map[string]string) productParams["ServiceName"] = workflow.serviceName - productParams["SourceBranch"] = workflow.codeBranch productParams["SourceRepo"] = pipeline.Source.Repo + if workflow.codeBranch != "" { + productParams["SourceBranch"] = workflow.codeBranch + } else { + productParams["SourceBranch"] = pipeline.Source.Branch + } + if pipeline.Source.Provider == "GitHub" { productParams["GitHubToken"] = params["GitHubToken"] }