-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeployCodeBuildProject-Cfn.yaml
120 lines (113 loc) · 3.92 KB
/
DeployCodeBuildProject-Cfn.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
AWSTemplateFormatVersion: "2010-09-09"
Description: AWS resources for building an example ML inference container with ArmNN
Parameters:
CodeCommitRepositoryName:
Type: String
Description: CodeCommit repository name (must exist already)
MinLength: 1
ContainerImageName:
Type: String
Description: Container image name for ECR
MinLength: 1
Resources:
ECRRepository:
Type: AWS::ECR::Repository
Properties:
ImageScanningConfiguration:
ScanOnPush: true
CodeBuildRole:
Type: AWS::IAM::Role
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "Asterisks are required"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- codebuild.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: CodeBuildPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: CloudWatchLogsPolicy
Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- "*"
- Sid: CodeCommitPolicy
Effect: Allow
Action:
- "codecommit:GitPull"
Resource:
- !Sub "arn:aws:codecommit:${AWS::Region}:${AWS::AccountId}:${CodeCommitRepositoryName}"
- Sid: ECRPolicy
Effect: Allow
Action:
- ecr:PutImage
- ecr:BatchCheckLayerAvailability
- ecr:CompleteLayerUpload
- ecr:UploadLayerPart
- ecr:InitiateLayerUpload
Resource:
- !Sub "arn:aws:ecr:${AWS::Region}:${AWS::AccountId}:repository/${ECRRepository}"
- Sid: ECRAuthPolicy
Effect: Allow
Action:
- ecr:GetAuthorizationToken
Resource:
- "*"
CodeBuildProject:
Type: AWS::CodeBuild::Project
Metadata:
cfn_nag:
rules_to_suppress:
- id: W32
reason: "No build output artifacts to encrypt"
Properties:
ServiceRole: !GetAtt CodeBuildRole.Arn
Artifacts:
Type: NO_ARTIFACTS
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Type: ARM_CONTAINER
Image: "aws/codebuild/amazonlinux2-aarch64-standard:2.0"
PrivilegedMode: true
EnvironmentVariables:
- Name: ECR_REPO_NAME
Value: !Ref ECRRepository
Source:
BuildSpec: !Sub |
version: 0.2
phases:
build:
commands:
- "echo 'Building container image with ArmNN'"
- "docker build -t $ECR_REPO_NAME:${ContainerImageName} ."
- "echo 'Pushing container image to ECR'"
- "aws ecr get-login-password --region ${AWS::Region} | docker login --username AWS --password-stdin ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com"
- "docker tag $ECR_REPO_NAME:${ContainerImageName} ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/$ECR_REPO_NAME:${ContainerImageName}"
- "docker push ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/$ECR_REPO_NAME:${ContainerImageName}"
Type: CODECOMMIT
Location: !Sub "https://git-codecommit.${AWS::Region}.amazonaws.com/v1/repos/${CodeCommitRepositoryName}"
Outputs:
ECRRepo:
Description: Name of the ECR repository created
Value: !Ref ECRRepository
Export:
Name: ECRRepositoryName
ECRContainerImage:
Description: Name of the ECR container image
Value: !Ref ContainerImageName
Export:
Name: ContainerImageName