-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodebuild.yml
171 lines (158 loc) · 4.99 KB
/
codebuild.yml
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
# Code pipeline for scala applications
AWSTemplateFormatVersion: '2010-09-09'
Description: >
Template to create codebuild service for components and libraries
#
#--------------------------------------------------------------------------
# PARAMETERS
#--------------------------------------------------------------------------
#
# Required and optional parameters to create simple build service
#
Parameters:
#
#--------------------------------------------------------------------------
# General application settings
#--------------------------------------------------------------------------
#
AppName:
Description: Name of the application
Type: String
CodacyProjectToken:
Description: Codacy Prject token for submitting code coverage information
Type: String
NoEcho: true
#
#--------------------------------------------------------------------------
# GitHub settings
#--------------------------------------------------------------------------
#
GitHubOwner:
Type: String
Description: GitHub repository owner
GitHubRepo:
Type: String
Description: GitHub repository name
GitHubBranch:
Type: String
Default: master
Description: GitHub repository branch
#
#--------------------------------------------------------------------------
# Code build settings
#--------------------------------------------------------------------------
#
CodeBuildComputeType:
Description: The build compute type
Type: String
Default: BUILD_GENERAL1_SMALL
AllowedValues:
- BUILD_GENERAL1_SMALL
- BUILD_GENERAL1_MEDIUM
- BUILD_GENERAL1_LARGE
CodeBuildDockerImage:
Description: The docker image to be used for code build
Type: String
Default: onema/scala-sbt:8u171-2.12.6-1.2.1-build
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "Application Settings"
Parameters:
- AppName
- CodacyProjectToken
- Label:
default: "CodeBuild Settings"
Parameters:
- CodeBuildComputeType
- CodeBuildDockerImage
- Label:
default: "GitHub Settings"
Parameters:
- GitHubBranch
- GitHubOwner
- GitHubRepo
#
#--------------------------------------------------------------------------
# RESOURCES
#--------------------------------------------------------------------------
#
# Definition of all the resources required for the service
#
Resources:
#
#--------------------------------------------------------------------------
# CodeBuild Role and permissions.
#--------------------------------------------------------------------------
#
CodeBuildDeploymentRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AppName}-code-build-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "codebuild.amazonaws.com"
Action:
- "sts:AssumeRole"
ManagedPolicyArns:
#================================================================
# NOTE: This role has admin access
# lock down to fit your needs!
#================================================================
- arn:aws:iam::aws:policy/AdministratorAccess
#
#--------------------------------------------------------------------------
# CodeBuild definitions
#--------------------------------------------------------------------------
#
#========================================================================
# NOTE: GitHub requires a one time manual oauth authentication step
# see https://itonaut.com/2018/06/18/use-github-source-in-aws-codebuild-project-using-aws-cloudformation/
# for more information.
#========================================================================
CodeBuild:
Type: AWS::CodeBuild::Project
Properties:
Name: !Sub "${AppName}"
Description: !Sub "Run unit test for ${AppName}"
BadgeEnabled: true
Artifacts:
Type: NO_ARTIFACTS
ServiceRole: !Ref CodeBuildDeploymentRole
Environment:
ComputeType: !Ref CodeBuildComputeType
EnvironmentVariables:
- Name: CODACY_PROJECT_TOKEN
Value: !Ref CodacyProjectToken
- Name: APP_NAME
Value: !Ref AppName
Image: !Ref CodeBuildDockerImage
Type: LINUX_CONTAINER
Source:
Auth:
Type: OAUTH
Type: GITHUB
GitCloneDepth: 1
Location: !Sub "https://github.com/${GitHubOwner}/${GitHubRepo}.git"
BuildSpec: "buildspec.yml"
ReportBuildStatus: true
Triggers:
Webhook: true
#
#--------------------------------------------------------------------------
# OUTPUTS
#--------------------------------------------------------------------------
#
# Outputs of the resources generated by the code pipeline
#
Outputs:
CodeBuild:
Description: CodeBuild resource for the master branch
Value: !Ref CodeBuild
Export:
Name: !Sub "${AppName}-codebuild"