forked from aws/copilot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add cfn snippets for bare-boned pre/post deployment actions (a…
…ws#5109) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
- Loading branch information
1 parent
af736c9
commit 7dd974f
Showing
10 changed files
with
295 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
internal/pkg/template/templates/cicd/partials/action-config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{{- if or (eq .Build.EnvironmentType "LINUX_CONTAINER") (eq .Build.EnvironmentType "ARM_CONTAINER")}} | ||
Cache: | ||
Modes: | ||
- LOCAL_DOCKER_LAYER_CACHE | ||
Type: LOCAL | ||
{{- else }} | ||
Cache: | ||
Type: "NO_CACHE" | ||
{{- end }} | ||
Environment: | ||
Type: {{.Build.EnvironmentType}} | ||
ComputeType: BUILD_GENERAL1_SMALL | ||
PrivilegedMode: true | ||
Image: {{.Build.Image}} | ||
EnvironmentVariables: | ||
- Name: AWS_ACCOUNT_ID | ||
Value: !Sub '${AWS::AccountId}' | ||
- Name: PARTITION | ||
Value: !Ref AWS::Partition | ||
Source: | ||
Type: CODEPIPELINE | ||
BuildSpec: {{.Build.BuildspecPath}} | ||
TimeoutInMinutes: 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{{- range $stage := .Stages}} | ||
{{- range $action := $stage.PreDeployments}} | ||
Pre{{logicalIDSafe $stage.Name}}DeploymentAction{{logicalIDSafe $action.Name}}BuildProjectRole: | ||
Type: AWS::IAM::Role | ||
Properties: | ||
Path: / | ||
{{ include "role-config" $ | indent 4}} | ||
{{- if $.PermissionsBoundary }} | ||
PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/{{$.PermissionsBoundary}}' | ||
{{- end }} | ||
Policies: | ||
- PolicyName: assume-env-manager | ||
PolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Effect: Allow | ||
Resource: 'arn:aws:iam::{{$stage.AccountID}}:role/{{$.AppName}}-{{$stage.Name}}-EnvManagerRole' | ||
Action: | ||
- sts:AssumeRole | ||
- PolicyName: build-role-policy | ||
PolicyDocument: | ||
{{ include "role-policy-document" $ | indent 10 }} | ||
|
||
Pre{{logicalIDSafe $stage.Name}}DeploymentAction{{logicalIDSafe $action.Name}}: | ||
Type: AWS::CodeBuild::Project | ||
Properties: | ||
EncryptionKey: !ImportValue {{$.AppName}}-ArtifactKey | ||
ServiceRole: !GetAtt Pre{{logicalIDSafe $stage.Name}}DeploymentAction{{logicalIDSafe $action.Name}}BuildProjectRole.Arn | ||
Artifacts: | ||
Type: CODEPIPELINE | ||
{{ include "action-config" $action | indent 4}} | ||
{{- end}} | ||
{{- end}} | ||
|
||
{{- range $stage := .Stages}} | ||
{{- range $action := $stage.PostDeployments}} | ||
Post{{logicalIDSafe $stage.Name}}DeploymentAction{{logicalIDSafe $action.Name}}BuildProjectRole: | ||
Type: AWS::IAM::Role | ||
Properties: | ||
Path: / | ||
{{ include "role-config" $ | indent 4}} | ||
{{- if $.PermissionsBoundary }} | ||
PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/{{$.PermissionsBoundary}}' | ||
{{- end }} | ||
Policies: | ||
- PolicyName: assume-env-manager | ||
PolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Effect: Allow | ||
Resource: 'arn:aws:iam::{{$stage.AccountID}}:role/{{$.AppName}}-{{$stage.Name}}-EnvManagerRole' | ||
Action: | ||
- sts:AssumeRole | ||
- PolicyName: build-role-policy | ||
PolicyDocument: | ||
{{ include "role-policy-document" $ | indent 10 }} | ||
|
||
Post{{logicalIDSafe $stage.Name}}DeploymentAction{{logicalIDSafe $action.Name}}: | ||
Type: AWS::CodeBuild::Project | ||
Properties: | ||
EncryptionKey: !ImportValue {{$.AppName}}-ArtifactKey | ||
ServiceRole: !GetAtt Post{{logicalIDSafe $stage.Name}}DeploymentAction{{logicalIDSafe $action.Name}}BuildProjectRole.Arn | ||
Artifacts: | ||
Type: CODEPIPELINE | ||
{{ include "action-config" $action | indent 4}} | ||
{{- end}} | ||
{{- end}} |
53 changes: 53 additions & 0 deletions
53
internal/pkg/template/templates/cicd/partials/build-action.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
BuildProjectRole: | ||
Type: AWS::IAM::Role | ||
Properties: | ||
Path: / | ||
{{ include "role-config" . | indent 4}} | ||
{{- if $.PermissionsBoundary }} | ||
PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/{{$.PermissionsBoundary}}' | ||
{{- end }} | ||
Policies: | ||
- PolicyName: assume-env-manager | ||
PolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
{{- range $stage := .Stages}} | ||
- Effect: Allow | ||
Resource: 'arn:aws:iam::{{$stage.AccountID}}:role/{{$.AppName}}-{{$stage.Name}}-EnvManagerRole' | ||
Action: | ||
- sts:AssumeRole | ||
{{- end }} | ||
|
||
BuildProjectPolicy: | ||
Type: AWS::IAM::Policy | ||
DependsOn: BuildProjectRole | ||
Properties: | ||
PolicyName: !Sub ${AWS::StackName}-CodeBuildPolicy | ||
Roles: | ||
- !Ref BuildProjectRole | ||
PolicyDocument: | ||
{{ include "role-policy-document" . | indent 6 }} | ||
|
||
{{- if .Build.AdditionalPolicyDocument }} | ||
BuildProjectAdditionalPolicy: | ||
Type: 'AWS::IAM::Policy' | ||
Properties: | ||
PolicyName: !Sub ${AWS::StackName}-BuildProjectAdditionalPolicy | ||
PolicyDocument: | ||
{{.Build.AdditionalPolicyDocument | indent 8}} | ||
Roles: | ||
- !Ref BuildProjectRole | ||
{{- end}} | ||
|
||
BuildProject: | ||
Type: AWS::CodeBuild::Project | ||
Properties: | ||
Name: !Sub ${AWS::StackName}-BuildProject | ||
Description: !Sub Build for ${AWS::StackName} | ||
# ArtifactKey is the KMS key ID or ARN that is used with the artifact bucket | ||
# created in the same region as this pipeline. | ||
EncryptionKey: !ImportValue {{$.AppName}}-ArtifactKey | ||
ServiceRole: !GetAtt BuildProjectRole.Arn | ||
Artifacts: | ||
Type: CODEPIPELINE | ||
{{- include "action-config" . | indent 4}} |
162 changes: 0 additions & 162 deletions
162
internal/pkg/template/templates/cicd/partials/build.yml
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
internal/pkg/template/templates/cicd/partials/role-config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
AssumeRolePolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Effect: Allow | ||
Principal: | ||
Service: | ||
- codebuild.amazonaws.com | ||
Action: | ||
- sts:AssumeRole | ||
ManagedPolicyArns: | ||
- 'arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess' # for env ls | ||
- 'arn:aws:iam::aws:policy/AWSCloudFormationReadOnlyAccess' # for service package |
Oops, something went wrong.