Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f599d87

Browse files
initial working template
1 parent 603ff9d commit f599d87

File tree

4 files changed

+467
-0
lines changed

4 files changed

+467
-0
lines changed

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# aws-cft-pipeline-codebuild-codedeploy-statichosting-frontendapp
22
Template for hosting a Vue app into s3 using cloudformation, codebuild, codedeploy and codepipeline.
3+
4+
Note:
5+
1. Get Access Token
6+
This pipeline will take the source code from the github. So you need get a developer access token (make sure it is having read access).
7+
8+
2. Place your code in Github
9+
Make sure your vue code is placed in a github repo. And you need to have a username/orgname and reponame as input parameters to your cft.
10+
11+
# Setup
12+
Use the frontend-pipeline-cft.yml and give as an input in the cloudformation. Provide appropriate values.

‎buildspec.yml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 0.2
2+
phases:
3+
install:
4+
commands:
5+
- npm i npm@latest -g
6+
- pip install --upgrade pip
7+
- pip install --upgrade awscli
8+
pre_build:
9+
commands:
10+
- npm install
11+
build:
12+
commands:
13+
- npm run build
14+
post_build:
15+
commands:
16+
- aws s3 sync ./dist $S3_BUCKET --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
AWSTemplateFormatVersion: '2010年09月09日'
2+
Description: Pipeline using CodePipeline and CodeBuild for continuous delivery of a single-page application to S3
3+
Parameters:
4+
SiteBucketName:
5+
Type: String
6+
Description: Name of bucket to create to host the website
7+
GitHubUser:
8+
Type: String
9+
Description: GitHub User/Repo
10+
Default: "<your github user>"
11+
GitHubRepo:
12+
Type: String
13+
Description: GitHub Repo to pull from. Only the Name. not the URL
14+
Default: "<reponame>"
15+
GitHubBranch:
16+
Type: String
17+
Description: GitHub Branch
18+
Default: "master"
19+
GitHubToken:
20+
NoEcho: true
21+
Type: String
22+
Description: Secret. It might look something like 9b189a1654643522561f7b3ebd44a1531a4287af OAuthToken with access to Repo. Go to https://github.com/settings/tokens
23+
BuildType:
24+
Type: String
25+
Default: "LINUX_CONTAINER"
26+
Description: The build container type to use for building the app
27+
BuildComputeType:
28+
Type: String
29+
Default: "BUILD_GENERAL1_SMALL"
30+
Description: The build compute type to use for building the app
31+
BuildImage:
32+
Type: String
33+
Default: "aws/codebuild/standard:2.0"
34+
Description: The build image to use for building the app
35+
Metadata:
36+
AWS::CloudFormation::Interface:
37+
ParameterGroups:
38+
- Label:
39+
default: "Site Configuration"
40+
Parameters:
41+
- SiteBucketName
42+
- Label:
43+
default: "GitHub Configuration"
44+
Parameters:
45+
- GitHubUser
46+
- GitHubToken
47+
- GitHubRepo
48+
- GitHubBranch
49+
- Label:
50+
default: "Build Configuration"
51+
Parameters:
52+
- BuildType
53+
- BuildComputeType
54+
- BuildImage
55+
ParameterLabels:
56+
SiteBucketName:
57+
default: Name of S3 Bucket to create for website hosting
58+
GitHubToken:
59+
default: GitHub OAuth2 Token
60+
GitHubUser:
61+
default: GitHub User/Org Name
62+
GitHubRepo:
63+
default: GitHub Repository Name
64+
GitHubBranch:
65+
default: GitHub Branch Name
66+
BuildType:
67+
default: CodeBuild type
68+
BuildComputeType:
69+
default: CodeBuild instance type
70+
BuildImage:
71+
default: CodeBuild image
72+
Resources:
73+
CodeBuildRole:
74+
Type: AWS::IAM::Role
75+
Properties:
76+
AssumeRolePolicyDocument:
77+
Statement:
78+
- Effect: Allow
79+
Principal:
80+
Service:
81+
- codebuild.amazonaws.com
82+
Action:
83+
- sts:AssumeRole
84+
Path: "/"
85+
Policies:
86+
- PolicyName: codebuild-service
87+
PolicyDocument:
88+
Statement:
89+
- Effect: Allow
90+
Action: "*"
91+
Resource: "*"
92+
Version: '2012年10月17日'
93+
CodePipelineRole:
94+
Type: AWS::IAM::Role
95+
Properties:
96+
AssumeRolePolicyDocument:
97+
Statement:
98+
- Effect: Allow
99+
Principal:
100+
Service:
101+
- codepipeline.amazonaws.com
102+
Action:
103+
- sts:AssumeRole
104+
Path: "/"
105+
Policies:
106+
- PolicyName: codepipeline-service
107+
PolicyDocument:
108+
Statement:
109+
- Action:
110+
- codebuild:*
111+
Resource: "*"
112+
Effect: Allow
113+
- Action:
114+
- s3:GetObject
115+
- s3:GetObjectVersion
116+
- s3:GetBucketVersioning
117+
Resource: "*"
118+
Effect: Allow
119+
- Action:
120+
- s3:PutObject
121+
Resource:
122+
- arn:aws:s3:::codepipeline*
123+
Effect: Allow
124+
- Action:
125+
- s3:*
126+
- cloudformation:*
127+
- iam:PassRole
128+
Resource: "*"
129+
Effect: Allow
130+
Version: '2012年10月17日'
131+
SiteBucket:
132+
Type: AWS::S3::Bucket
133+
DeletionPolicy: Delete
134+
Properties:
135+
AccessControl: PublicRead
136+
BucketName: !Ref SiteBucketName
137+
WebsiteConfiguration:
138+
IndexDocument: index.html
139+
ErrorDocument: index.html
140+
141+
PipelineBucket:
142+
Type: AWS::S3::Bucket
143+
DeletionPolicy: Delete
144+
CodeBuildDeploySite:
145+
Type: AWS::CodeBuild::Project
146+
Properties:
147+
Name: !Sub ${AWS::StackName}-DeploySite
148+
Description: Deploy site to S3
149+
ServiceRole: !GetAtt CodeBuildRole.Arn
150+
Artifacts:
151+
Type: CODEPIPELINE
152+
Environment:
153+
Type: !Ref BuildType
154+
ComputeType: !Ref BuildComputeType
155+
Image: !Sub ${BuildImage}
156+
EnvironmentVariables:
157+
- Name: S3_BUCKET
158+
Value: !Ref SiteBucketName
159+
Source:
160+
Type: CODEPIPELINE
161+
BuildSpec: !Sub |
162+
version: 0.2
163+
phases:
164+
install:
165+
commands:
166+
- npm i npm@latest -g
167+
- pip install --upgrade pip
168+
- pip install --upgrade awscli
169+
pre_build:
170+
commands:
171+
- npm install
172+
build:
173+
commands:
174+
- npm run build
175+
post_build:
176+
commands:
177+
- aws s3 sync ./dist $S3_BUCKET --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
178+
TimeoutInMinutes: 50
179+
Pipeline:
180+
Type: AWS::CodePipeline::Pipeline
181+
DependsOn: SiteBucket
182+
Properties:
183+
RoleArn: !GetAtt CodePipelineRole.Arn
184+
Stages:
185+
- Name: Source
186+
Actions:
187+
- InputArtifacts: []
188+
Name: Source
189+
ActionTypeId:
190+
Category: Source
191+
Owner: ThirdParty
192+
Version: '1'
193+
Provider: GitHub
194+
OutputArtifacts:
195+
- Name: SourceArtifacts
196+
Configuration:
197+
Owner: !Ref GitHubUser
198+
Repo: !Ref GitHubRepo
199+
Branch: !Ref GitHubBranch
200+
OAuthToken: !Ref GitHubToken
201+
RunOrder: 1
202+
- Name: Deploy
203+
Actions:
204+
- Name: Artifact
205+
ActionTypeId:
206+
Category: Build
207+
Owner: AWS
208+
Version: '1'
209+
Provider: CodeBuild
210+
InputArtifacts:
211+
- Name: SourceArtifacts
212+
OutputArtifacts:
213+
- Name: DeploymentArtifacts
214+
Configuration:
215+
ProjectName: !Ref CodeBuildDeploySite
216+
RunOrder: 1
217+
ArtifactStore:
218+
Type: S3
219+
Location: !Ref PipelineBucket
220+
Outputs:
221+
PipelineUrl:
222+
Value: !Sub https://console.aws.amazon.com/codepipeline/home?region=${AWS::Region}#/view/${Pipeline}
223+
Description: CodePipeline URL
224+
SiteUrl:
225+
Value: !GetAtt [SiteBucket, WebsiteURL]
226+
Description: S3 Website URL

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /