-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.yaml
152 lines (148 loc) · 5.4 KB
/
pipeline.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
AWSTemplateFormatVersion: '2010-09-09'
Description: Build and Deployment pipeline for the PipelineNotifier service
Parameters:
ServiceName:
Description: The name of the project
Default: PipelineNotifier
Type: String
RepositoryName:
Description: The full repository name e.g some-user/my-repo
Default: mdinicola/aws-pipeline-notifier
Type: String
RepositoryBranchName:
Description: The repository branch to watch for changes
Default: main
Type: String
RepositoryConnectionArn:
Description: The ARN of the CodeStar connection to the external repository
Type: String
BuildProjectRoleName:
Description: The IAM role name to use with CodeBuild
Default: CodeBuildRole
Type: String
DeployRoleName:
Description: The IAM role name to deploy the CloudFormation stack
Default: ServerlessDeploymentRole
Type: String
PipelineRoleName:
Description: The IAM role name of the pipeline role
Default: CodePipelineRole
Type: String
PipelineNotificationTopicName:
Description: The SNS topic name for pipeline notifications
Default: CodePipelineNotifications
Type: String
ArtifactsBucketName:
Description: The name of the artifacts bucket
Type: String
CustomizedNotificationTopicName:
Description: The SNS topic name for sending customized notifications
Default: CustomizedNotifications
Type: String
Resources:
BuildProject:
Type: AWS::CodeBuild::Project
Properties:
Name: !Ref ServiceName
ServiceRole: !Sub arn:aws:iam::${AWS::AccountId}:role/service-role/${BuildProjectRoleName}
Source:
Type: CODEPIPELINE
BuildSpec: buildspec.yaml
Artifacts:
Type: CODEPIPELINE
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: 'aws/codebuild/amazonlinux2-x86_64-standard:5.0'
Type: LINUX_CONTAINER
EnvironmentVariables:
- Name: ARTIFACTS_BUCKET
Value: !Ref ArtifactsBucketName
- Name: ARTIFACTS_FOLDER
Value: !Ref ServiceName
Pipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
Name: !Ref ServiceName
ArtifactStore:
Location: !Ref ArtifactsBucketName
Type: S3
RoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/service-role/${PipelineRoleName}
Stages:
- Name: Source
Actions:
- Name: GitHubSource
ActionTypeId:
Category: Source
Owner: AWS
Provider: CodeStarSourceConnection
Version: 1
Configuration:
ConnectionArn: !Ref RepositoryConnectionArn
FullRepositoryId: !Ref RepositoryName
BranchName: !Ref RepositoryBranchName
OutputArtifactFormat: CODE_ZIP
DetectChanges: true
OutputArtifacts:
- Name: SourceArtifact
- Name: Build
Actions:
- Name: Build
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: 1
Configuration:
ProjectName: !Ref ServiceName
InputArtifacts:
- Name: SourceArtifact
OutputArtifacts:
- Name: BuildArtifact
- Name: Deploy
Actions:
- Name: CreateChangeSet
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: CloudFormation
Version: 1
InputArtifacts:
- Name: BuildArtifact
Configuration:
ActionMode: CHANGE_SET_REPLACE
Capabilities: CAPABILITY_IAM,CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND
RoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/${DeployRoleName}
StackName: !Ref ServiceName
TemplatePath: "BuildArtifact::packaged-template.yaml"
ChangeSetName: !Sub a-${ServiceName}-Deploy
ParameterOverrides: !Sub "{\"PipelineTopicArn\": \"arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${PipelineNotificationTopicName}\", \"CustomizedNotificationTopicArn\": \"arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${CustomizedNotificationTopicName}\"}"
RunOrder: 1
- Name: ExecuteChangeSet
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: CloudFormation
Version: 1
Configuration:
ActionMode: CHANGE_SET_EXECUTE
StackName: !Ref ServiceName
ChangeSetName: !Sub a-${ServiceName}-Deploy
RunOrder: 2
PipelineNotificationRule:
Type: 'AWS::CodeStarNotifications::NotificationRule'
Properties:
Name: !Sub "${ServiceName}-PipelineNotificationRule"
DetailType: BASIC
Resource: !Sub "arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline}"
EventTypeIds:
- codepipeline-pipeline-pipeline-execution-succeeded
- codepipeline-pipeline-pipeline-execution-canceled
- codepipeline-pipeline-pipeline-execution-failed
Targets:
- TargetType: SNS
TargetAddress: !Sub "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${PipelineNotificationTopicName}"
Outputs:
PipelineName:
Value: !Ref Pipeline
PipelineVersion:
Value: !GetAtt Pipeline.Version