-
Notifications
You must be signed in to change notification settings - Fork 5
/
ci_cd_pipeline.yaml
executable file
·180 lines (174 loc) · 5.71 KB
/
ci_cd_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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
AWSTemplateFormatVersion: "2010-09-09"
Description: AWS CloudFormation template for CI/CD pipeline on AWS for Python
Resources:
CodeBuildIAMRole:
Type: AWS::IAM::Role
Properties:
RoleName: demo-ci-cd-pipeline-codebuild-role
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "codebuild.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/service-role/"
Policies:
-
PolicyName: demo-ci-cd-pipeline-codebuild-policy
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "s3:GetBucketAcl"
- "s3:GetBucketLocation"
Resource:
- !GetAtt CodePipelineArtifacts.Arn
-
Effect: "Allow"
Action:
- "s3:PutObject"
- "s3:GetObject"
- "s3:GetObjectVersion"
Resource:
- !Sub ${CodePipelineArtifacts.Arn}/*
-
Effect: "Allow"
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource:
- !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/demo-ci-cd-pipeline*
- !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/demo-ci-cd-pipeline:*
CodePipelineIAMRole:
Type: AWS::IAM::Role
Properties:
RoleName: demo-ci-cd-pipeline-codepipeline-role
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "codepipeline.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/service-role/"
Policies:
-
PolicyName: demo-ci-cd-pipeline-codepipeline-policy
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "s3:ListBucket"
- "s3:GetBucketPolicy"
Resource:
- !GetAtt CodePipelineArtifacts.Arn
-
Effect: "Allow"
Action:
- "s3:PutObject"
- "s3:GetObject"
- "s3:GetObjectVersion"
- "s3:DeleteObject"
Resource:
- !Sub ${CodePipelineArtifacts.Arn}/*
-
Effect: "Allow"
Action:
- "codecommit:CancelUploadArchive"
- "codecommit:GetBranch"
- "codecommit:GetCommit"
- "codecommit:GetUploadArchiveStatus"
- "codecommit:UploadArchive"
Resource: !GetAtt CodeCommitRepository.Arn
-
Effect: "Allow"
Action:
- "codebuild:BatchGetBuilds"
- "codebuild:StartBuild"
Resource:
- !GetAtt CodeBuildProject.Arn
- !Sub arn:aws:codebuild:${AWS::Region}:${AWS::AccountId}:build/demo-ci-cd-pipeline:*
CodePipelineArtifacts:
Type: AWS::S3::Bucket
CodeCommitRepository:
Type: AWS::CodeCommit::Repository
Properties:
RepositoryName: demo-ci-cd-pipeline
RepositoryDescription: CI/CD pipeline on AWS for Python
Code:
S3:
Bucket: korniichuk.share
Key: code/ci_cd_pipeline_init_code_20200827.zip
CodeBuildProject:
Type: AWS::CodeBuild::Project
Properties:
Name: demo-ci-cd-pipeline
Source:
Type: CODEPIPELINE
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
Image: aws/codebuild/amazonlinux2-x86_64-standard:3.0 # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
ComputeType: BUILD_GENERAL1_SMALL
ServiceRole: !GetAtt CodeBuildIAMRole.Arn
TimeoutInMinutes: 15
QueuedTimeoutInMinutes: 60
LogsConfig:
CloudWatchLogs:
Status: ENABLED
CodePipelinePipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
Name: demo-ci-cd-pipeline
ArtifactStore:
Location: !Ref CodePipelineArtifacts
Type: S3
RoleArn: !GetAtt CodePipelineIAMRole.Arn
Stages:
-
Name: Source
Actions:
-
Name: Source
ActionTypeId:
Category: Source
Owner: AWS
Provider: CodeCommit
Version: '1'
Configuration:
RepositoryName: demo-ci-cd-pipeline
BranchName: master
PollForSourceChanges: true
OutputArtifacts:
-
Name: SourceOutput
RunOrder: 1
-
Name: Build
Actions:
-
Name: Build
InputArtifacts:
-
Name: SourceOutput
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: '1'
Configuration:
ProjectName: !Ref CodeBuildProject
RunOrder: 1