Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit 660f98d

Browse files
committed
First big step towards a 1-click deploy solution
1 parent b24727e commit 660f98d

File tree

4 files changed

+299
-12
lines changed

4 files changed

+299
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This sample code is made available under a modified MIT license. See the LICENSE
2323

2424
- Python 2.7+
2525
- Docker
26-
- Access to an AWS account
26+
- An AWS account
2727
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
2828

2929
## Examples

bin/runner.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222

2323
# List of regions where we have deployed the CloudFormation stack
2424
regions = [
25-
{
26-
'name': 'us-east-1',
27-
'stackName': 'dlt-fargate',
28-
'taskCount': 3
29-
},
30-
{
31-
'name': 'us-east-2',
32-
'stackName': 'dlt-fargate',
33-
'taskCount': 3
34-
},
25+
#{
26+
# 'name': 'us-east-1',
27+
# 'stackName': 'dlt-fargate',
28+
# 'taskCount': 3
29+
#},
30+
#{
31+
# 'name': 'us-east-2',
32+
# 'stackName': 'dlt-fargate',
33+
# 'taskCount': 3
34+
#},
3535
{
3636
'name': 'us-west-2',
3737
'stackName': 'dlt-fargate',

cloudformation/master.yaml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Description: >
1818
It deploys an ECR Repository, a Fargate Cluster, a VPC,
1919
a CloudWatch Log Group and an IAM Execution Role.
2020
21+
Parameters:
22+
GitRepositoryName:
23+
Type: String
24+
Default: "distributed-load-testing-using-aws-fargate"
25+
2126
Resources:
2227
DockerRegistry:
2328
Type: AWS::ECR::Repository
@@ -57,7 +62,25 @@ Resources:
5762
- !Ref DockerRegistry
5863
- ':latest'
5964

65+
Pipeline:
66+
Type: AWS::CloudFormation::Stack
67+
DependsOn: Vpc
68+
Properties:
69+
TemplateURL: "https://s3.amazonaws.com/load-testing-using-aws-fargate/artifacts/templates/pipeline.yaml"
70+
Parameters:
71+
DockerRegistryArn: !GetAtt DockerRegistry.Arn
72+
GitRepositoryName: !Ref GitRepositoryName
73+
DockerRegistryURL: !Join
74+
- ''
75+
- - !Ref 'AWS::AccountId'
76+
- '.dkr.ecr.'
77+
- !Ref 'AWS::Region'
78+
- '.amazonaws.com/'
79+
- !Ref DockerRegistry
80+
6081
Outputs:
82+
GitRepoHttpUrl:
83+
Value: !GetAtt Pipeline.Outputs.GitRepoHttpUrl
6184
DockerRegistryName:
6285
Value: !Ref DockerRegistry
6386
DockerRegistryURL:
@@ -69,4 +92,18 @@ Outputs:
6992
- '.amazonaws.com/'
7093
- !Ref DockerRegistry
7194
TaskExecutionRoleArn:
72-
Value: !GetAtt TaskExecutionRole.Arn
95+
Value: !GetAtt TaskExecutionRole.Arn
96+
FargateClusterName:
97+
Value: !GetAtt FargateCluster.Outputs.FargateClusterName
98+
TaskSecurityGroup:
99+
Value: !GetAtt FargateCluster.Outputs.TaskSecurityGroup
100+
TaskDefinitionArn:
101+
Value: !GetAtt FargateCluster.Outputs.TaskDefinitionArn
102+
VpcId:
103+
Value: !GetAtt Vpc.Outputs.VpcId
104+
SubnetA:
105+
Value: !GetAtt Vpc.Outputs.SubnetA
106+
SubnetB:
107+
Value: !GetAtt Vpc.Outputs.SubnetB
108+
SubnetC:
109+
Value: !GetAtt Vpc.Outputs.SubnetC

cloudformation/pipeline.yaml

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
# software and associated documentation files (the "Software"), to deal in the Software
5+
# without restriction, including without limitation the rights to use, copy, modify,
6+
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
# permit persons to whom the Software is furnished to do so.
8+
#
9+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
10+
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
11+
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
12+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
13+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15+
AWSTemplateFormatVersion: 2010-09-09
16+
Description: >
17+
Deployment pipeline for Distributed Load Test Using AWS Fargate.
18+
It creates a CodeBuild project used to configure and run a load test.
19+
20+
Parameters:
21+
GitRepositoryName:
22+
Type: String
23+
DockerRegistryURL:
24+
Type: String
25+
DockerRegistryArn:
26+
Type: String
27+
ContainersPerRegion:
28+
Type: Number
29+
Default: 3
30+
31+
Resources:
32+
CodeRepository:
33+
Type: AWS::CodeCommit::Repository
34+
Properties:
35+
RepositoryDescription: "Distributed load testing using AWS Fargate"
36+
RepositoryName: !Ref GitRepositoryName
37+
38+
ArtifactStoreBucket:
39+
Type: AWS::S3::Bucket
40+
Properties:
41+
VersioningConfiguration:
42+
Status: Enabled
43+
44+
CodeBuild:
45+
Type: AWS::CodeBuild::Project
46+
Properties:
47+
Description: Builds distributed load testing suite
48+
TimeoutInMinutes: 20
49+
ServiceRole: !GetAtt CodeBuildRole.Arn
50+
Artifacts:
51+
Type: CODEPIPELINE
52+
Environment:
53+
Type: LINUX_CONTAINER
54+
ComputeType: BUILD_GENERAL1_MEDIUM
55+
Image: "aws/codebuild/docker:18.09.0"
56+
EnvironmentVariables:
57+
-
58+
Name: DOCKER_REGISTRY_URL
59+
Value: !Ref DockerRegistryURL
60+
Source:
61+
Type: CODEPIPELINE
62+
BuildSpec: !Sub |
63+
version: 0.2
64+
phases:
65+
pre_build:
66+
commands:
67+
- echo $DOCKER_REGISTRY_URL
68+
- echo $CODEBUILD_RESOLVED_SOURCE_VERSION
69+
- aws --version
70+
- $(aws ecr get-login --region ${AWS::Region} --no-include-email)
71+
build:
72+
commands:
73+
- docker build -t $DOCKER_REGISTRY_URL:latest .
74+
- docker tag $DOCKER_REGISTRY_URL:latest $DOCKER_REGISTRY_URL:$CODEBUILD_RESOLVED_SOURCE_VERSION
75+
post_build:
76+
commands:
77+
- docker push $DOCKER_REGISTRY_URL:latest
78+
- docker push $DOCKER_REGISTRY_URL:$CODEBUILD_RESOLVED_SOURCE_VERSION
79+
80+
# Leverage CodeBuild to kick start the test suite.
81+
# It could very well be replaced with a Lambda function
82+
LoadTestRunner:
83+
Type: AWS::CodeBuild::Project
84+
Properties:
85+
Description: Runs the load tests in Fargate
86+
TimeoutInMinutes: 240 # 2 hours
87+
ServiceRole: !GetAtt CodeBuildRole.Arn
88+
Artifacts:
89+
Type: CODEPIPELINE
90+
Environment:
91+
Type: LINUX_CONTAINER
92+
ComputeType: BUILD_GENERAL1_SMALL
93+
Image: "aws/codebuild/python:3.6.5"
94+
Source:
95+
Type: CODEPIPELINE
96+
BuildSpec: !Sub |
97+
version: 0.2
98+
phases:
99+
build:
100+
commands:
101+
- cd bin
102+
- python runner.py
103+
104+
CodePipeline:
105+
Type: AWS::CodePipeline::Pipeline
106+
Properties:
107+
RoleArn: !GetAtt CodePipelineRole.Arn
108+
ArtifactStore:
109+
Type: S3
110+
Location: !Ref ArtifactStoreBucket
111+
Stages:
112+
-
113+
Name: Source
114+
Actions:
115+
-
116+
Name: Source
117+
ActionTypeId:
118+
Category: Source
119+
Provider: CodeCommit
120+
Owner: AWS
121+
Version: 1
122+
OutputArtifacts:
123+
- Name: SourceOutput
124+
Configuration:
125+
RepositoryName: !GetAtt CodeRepository.Name
126+
BranchName: 'master'
127+
128+
-
129+
Name: Build
130+
Actions:
131+
-
132+
Name: Build
133+
ActionTypeId:
134+
Category: Build
135+
Owner: AWS
136+
Version: 1
137+
Provider: CodeBuild
138+
InputArtifacts:
139+
- Name: SourceOutput
140+
OutputArtifacts:
141+
- Name: BuildOutput
142+
Configuration:
143+
ProjectName:
144+
Ref: CodeBuild
145+
146+
-
147+
Name: LoadTest
148+
Actions:
149+
- Name: Runner
150+
ActionTypeId:
151+
Category: Build
152+
Owner: AWS
153+
Version: 1
154+
Provider: CodeBuild
155+
InputArtifacts:
156+
- Name: SourceOutput
157+
Configuration:
158+
ProjectName:
159+
Ref: LoadTestRunner
160+
161+
# Shared IAM policy for CodePipeline and CodeBuild projects for simplicity.
162+
# We could be more strict and create a separate role for each build
163+
# project and another one for the pipeline.
164+
BuildAndPipelinePolicy:
165+
Type: AWS::IAM::Policy
166+
Properties:
167+
PolicyName: "distributed-load-testing-using-aws-fargate"
168+
Roles:
169+
- !Ref CodeBuildRole
170+
- !Ref CodePipelineRole
171+
PolicyDocument:
172+
Version: 2012-10-17
173+
Statement:
174+
- Effect: Allow
175+
Resource:
176+
- !GetAtt ArtifactStoreBucket.Arn
177+
- !Join
178+
- ''
179+
- - !GetAtt ArtifactStoreBucket.Arn
180+
- '/*'
181+
Action:
182+
- "s3:*"
183+
- Effect: Allow
184+
Resource: !GetAtt CodeRepository.Arn
185+
Action:
186+
- "codecommit:GetBranch"
187+
- "codecommit:GetCommit"
188+
- "codecommit:UploadArchive"
189+
- "codecommit:GetUploadArchiveStatus"
190+
- "codecommit:CancelUploadArchive"
191+
- Effect: Allow
192+
Resource: !Ref DockerRegistryArn
193+
Action:
194+
- "ecr:DescribeImages"
195+
- "ecr:PutImage"
196+
- "ecr:UploadLayerPart"
197+
- "ecr:CompleteLayerUpload"
198+
- "ecr:InitiateLayerUpload"
199+
- "ecr:GetDownloadUrlForLayer"
200+
- "ecr:ListImages"
201+
- "ecr:BatchCheckLayerAvailability"
202+
- "ecr:GetRepositoryPolicy"
203+
- Effect: Allow
204+
Resource: "*"
205+
Action:
206+
- "codebuild:StartBuild"
207+
- "codebuild:StopBuild"
208+
- "codebuild:BatchGetBuilds"
209+
- "logs:CreateLogStream"
210+
- "logs:CreateLogGroup"
211+
- "logs:PutLogEvents"
212+
- "ecr:GetAuthorizationToken"
213+
- "cloudformation:DescribeStacks"
214+
- "ecs:RunTask"
215+
- "iam:PassRole"
216+
217+
CodeBuildRole:
218+
Type: AWS::IAM::Role
219+
Properties:
220+
AssumeRolePolicyDocument:
221+
Version: 2012-10-17
222+
Statement:
223+
-
224+
Effect: Allow
225+
Principal:
226+
Service:
227+
- codebuild.amazonaws.com
228+
Action:
229+
- sts:AssumeRole
230+
Path: "/"
231+
232+
CodePipelineRole:
233+
Type: AWS::IAM::Role
234+
Properties:
235+
AssumeRolePolicyDocument:
236+
Version: 2012-10-17
237+
Statement:
238+
- Effect: Allow
239+
Principal:
240+
Service:
241+
- codepipeline.amazonaws.com
242+
Action:
243+
- sts:AssumeRole
244+
Path: "/"
245+
246+
Outputs:
247+
GitRepoHttpUrl:
248+
Value: !GetAtt CodeRepository.CloneUrlHttp
249+
GitRepoSshUrl:
250+
Value: !GetAtt CodeRepository.CloneUrlSsh

0 commit comments

Comments
 (0)