Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudformation templates to deploy feature branch to crowd-test #758

Merged
merged 22 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6aa3bbd
If Django secret key is not in the env, use random key in settings_ecs
rstorey Jan 10, 2019
d2cdf9b
first pass at cloudformation template for deploying feature branches …
rstorey Jan 10, 2019
0d4d166
WIP deploying feature branches to crowd-test
rstorey Jan 11, 2019
7e1c94a
Remove unused deployment code
rstorey Jan 14, 2019
8cd1d8b
populate values for deploying feature branches to existing infrastruc…
rstorey Jan 14, 2019
a1402ad
Move private subnets to avoid cfn-lint warning, delete unneeded conta…
rstorey Jan 14, 2019
302998f
Modify cpu and memory values for single container
rstorey Jan 14, 2019
249a681
Move private subnets for elasticache into template file due to CF quirks
rstorey Jan 14, 2019
ba1bf9a
Use abbreviated name to avoid exceeding char limits on elasticache se…
rstorey Jan 14, 2019
5f7fd45
Use crowd-test task role for feature branch deployments
rstorey Jan 14, 2019
da824be
Correct import path for get_random_secret_key
rstorey Jan 14, 2019
8960929
Fix bug in initial site config management command
rstorey Jan 14, 2019
2f6a2fd
Remove unneeded parameter
rstorey Jan 14, 2019
674b251
Merge branch 'master' into deploy-feature-branch
rstorey Jan 14, 2019
3b2cdf6
Merge branch 'container-build-script' into deploy-feature-branch
rstorey Jan 14, 2019
cb12e85
Remove unused deployment code
rstorey Jan 14, 2019
7ac1ebb
As long as feature branch has its own elasticache template, simplify …
rstorey Jan 15, 2019
6d30276
Clarify description of concordiaversion for feature branch deploys
rstorey Jan 15, 2019
138d0ff
Unify quotes in featurebranch.yaml
rstorey Jan 15, 2019
19f9b8e
Merge branch 'master' into deploy-feature-branch
rstorey Jan 15, 2019
5ec588d
Merge branch 'master' into deploy-feature-branch
rstorey Jan 17, 2019
d07deb6
Clean up container build script that had messy merge
rstorey Jan 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build_containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ BUILD_ALL=${BUILD_ALL:=0}
BUILD_NUMBER=${BUILD_NUMBER:=1}
TAG=${TAG:-test}

BUILD_ALL=${BUILD_ALL:=0}
BUILD_NUMBER=${BUILD_NUMBER:=1}
TAG=${TAG:-test}

# Get an unique venv folder to using *inside* workspace
VENV=".venv-${BUILD_NUMBER}"

Expand All @@ -29,11 +33,13 @@ eval "$(aws ecr get-login --no-include-email --region us-east-1)"
python3 setup.py build

docker build -t concordia .

docker tag concordia:latest "${AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/concordia:${VERSION_NUMBER}"
docker tag concordia:latest "${AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/concordia:${TAG}"
docker push "${AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/concordia:${VERSION_NUMBER}"
docker push "${AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/concordia:${TAG}"


if [ $BUILD_ALL -eq 1 ]; then

docker build -t concordia/importer --file importer/Dockerfile .
Expand Down Expand Up @@ -61,3 +67,4 @@ if [ $BUILD_ALL -eq 1 ]; then
docker push "${AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/concordia/indexer:${TAG}"

fi

58 changes: 58 additions & 0 deletions cloudformation/featurebranch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
AWSTemplateFormatVersion: '2010-09-09'
Description: >
Deploy a feature branch to a subdomain of crowd-test.loc.gov
using pre-existing infrastructure.
Assumes docker images have been published to ECR with
tag matching the feature branch name.

Parameters:

ConcordiaBranch:
Description: which branch name to deploy
Type: String
Default: release

AbbreviatedName:
Description: an abbreviation used for creating short-named cloudformation resources
Type: String
Default: rel

Resources:

RDS:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: 'https://s3.amazonaws.com/crowd-deployment/infrastructure/rds.yaml'
Parameters:
DbPassword: '{{resolve:secretsmanager:crowd/test/DB/MasterUserPassword:SecretString:password}}'
DatabaseSecurityGroup: 'sg-0496910b800de2869'
PrivateSubnet1: 'subnet-0aa55b322229b945a'
PrivateSubnet2: 'subnet-0f65558b319b2d4dc'

ElastiCache:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: 'https://s3.amazonaws.com/crowd-deployment/infrastructure/elasticache-feature.yaml'
Parameters:
EnvironmentName: !Ref AbbreviatedName
SecurityGroup: 'sg-028ebfe14211447c4'

FargateCluster:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: 'https://s3.amazonaws.com/crowd-deployment/infrastructure/fargate-featurebranch.yaml'
Parameters:
EnvName: 'test'
FullEnvironmentName: 'test'
S3BucketName: 'crowd-test-content'
ExportS3BucketName: 'crowd-test-export'
ConcordiaVersion: !Ref ConcordiaBranch
CanonicalHostName: !Sub '${ConcordiaBranch}.crowd-test.loc.gov'
VpcId: 'vpc-018e5a73079d0b350'
SecurityGroup: 'sg-04de21574623caca7'
RedisAddress: !GetAtt ElastiCache.Outputs.RedisAddress
RedisPort: !GetAtt ElastiCache.Outputs.RedisPort
MemcachedAddress: !GetAtt ElastiCache.Outputs.MemcachedAddress
MemcachedPort: !GetAtt ElastiCache.Outputs.MemcachedPort
DatabaseEndpoint: !GetAtt RDS.Outputs.DatabaseHostName
60 changes: 60 additions & 0 deletions cloudformation/infrastructure/elasticache-feature.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Description: >
This template deploys an elasticache cluster to the provided VPC and subnets

Parameters:

EnvironmentName:
Description: An environment name that will be prefixed to resource names
Type: String

SecurityGroup:
Description: Select the Security Group to use for the ECS cluster hosts
Type: AWS::EC2::SecurityGroup::Id

CacheNodeType:
Type: String
Default: cache.m1.small

Resources:

MemcachedService:
Type: AWS::ElastiCache::CacheCluster
Properties:
VpcSecurityGroupIds:
- !Ref 'SecurityGroup'
CacheSubnetGroupName: 'crowd-cache-1frtjeewr57u7'
CacheNodeType: !Ref 'CacheNodeType'
ClusterName: !Sub '${EnvironmentName}-cache'
Engine: memcached
AutoMinorVersionUpgrade: true
NumCacheNodes: 1
RedisService:
Type: AWS::ElastiCache::CacheCluster
Properties:
VpcSecurityGroupIds:
- !Ref 'SecurityGroup'
CacheSubnetGroupName: 'crowd-cache-1frtjeewr57u7'
CacheNodeType: !Ref 'CacheNodeType'
ClusterName: !Sub '${EnvironmentName}-redis'
Engine: redis
AutoMinorVersionUpgrade: true
NumCacheNodes: 1
SnapshotRetentionLimit: 1

Outputs:

RedisAddress:
Description: Redis endpoint address
Value: !GetAtt 'RedisService.RedisEndpoint.Address'

RedisPort:
Description: Redis endpoint port
Value: !GetAtt 'RedisService.RedisEndpoint.Port'

MemcachedAddress:
Description: memcached endpoint address
Value: !GetAtt 'MemcachedService.ConfigurationEndpoint.Address'

MemcachedPort:
Description: memcached endpoint port
Value: !GetAtt 'MemcachedService.ConfigurationEndpoint.Port'
2 changes: 1 addition & 1 deletion cloudformation/infrastructure/fargate-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Resources:
ConcordiaTask:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Sub concordia-${EnvName}
Family: !Sub crowd-${EnvName}
Cpu: '4096'
Memory: '16384'
NetworkMode: awsvpc
Expand Down
190 changes: 190 additions & 0 deletions cloudformation/infrastructure/fargate-featurebranch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
Description: >
This template deploys a fargate cluster to the provided VPC and subnets

Parameters:

SecurityGroup:
Description: Select the Security Group to use for the ECS cluster hosts
Type: AWS::EC2::SecurityGroup::Id

VpcId:
Description: The Id of the VPC for this cluster
Type: AWS::EC2::VPC::Id

ConcordiaVersion:
Type: String
Description: docker tag of concordia app image to pull and deploy
Default: latest

EnvName:
Type: String
Description: which environment to target
AllowedValues:
- 'dev'
- 'test'
- 'stage'
- 'prod'
ConstraintDescription: Must match a location for secret storage in secretsmanager

FullEnvironmentName:
Type: String
Description: Full name of deployment environment
AllowedValues:
- 'development'
- 'test'
- 'staging'
- 'production'

RedisAddress:
Type: String
Description: Redis endpoint address

RedisPort:
Type: String
Description: Redis endpoint port

MemcachedAddress:
Type: String
Description: memcached endpoint address

MemcachedPort:
Type: String
Description: memcached endpoint port

CanonicalHostName:
Type: String
Description: canonical host name of the application, e.g. crowd-test.loc.gov

DatabaseEndpoint:
Type: String
Description: Host name of the Postgres RDS service

S3BucketName:
Type: String
Description: name of the S3 bucket (public) where collection images will be stored

ExportS3BucketName:
Type: String
Description: name of the S3 bucket (public) where exported transcriptions will be stored


Resources:

ConcordiaAppLogsGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Ref AWS::StackName
RetentionInDays: 30


ConcordiaExternalTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 30
HealthCheckPath: /healthz
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 2
UnhealthyThresholdCount: 10
TargetType: ip
Port: 80
Protocol: HTTP
VpcId: !Ref VpcId

SubdomainListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- TargetGroupArn: !Ref ConcordiaExternalTargetGroup
Type: forward
Conditions:
- Field: host-header
Values:
- !Ref CanonicalHostName
ListenerArn: arn:aws:elasticloadbalancing:us-east-1:619333082511:listener/app/crowd-test/81e4820e354ea810/187fd94e534ad833
Priority: 100

ConcordiaTask:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Sub crowd-${ConcordiaVersion}
Cpu: '2048'
Memory: '8192'
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: ecsTaskExecutionRole
TaskRoleArn: !Sub 'arn:aws:iam::${AWS::AccountId}:role/ConcordiaServerTaskRole-crowd-test'
Volumes:
- Name: images_volume
ContainerDefinitions:
- Name: app
Cpu: 2048
Memory: 8192
Image: !Sub '${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/concordia:${ConcordiaVersion}'
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref 'ConcordiaAppLogsGroup'
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: ConcordiaServer
Environment:
- Name: AWS
Value: '1'
- Name: ENV_NAME
Value: !Ref EnvName
- Name: CONCORDIA_ENVIRONMENT
Value: !Ref FullEnvironmentName
- Name: S3_BUCKET_NAME
Value: !Ref S3BucketName
- Name: EXPORT_S3_BUCKET_NAME
Value: !Ref ExportS3BucketName
- Name: CELERY_BROKER_URL
Value: pyamqp://guest@localhost:5672
- Name: AWS_DEFAULT_REGION
Value: !Ref AWS::Region
- Name: SENTRY_BACKEND_DSN
Value: http://[email protected]/2
- Name: SENTRY_FRONTEND_DSN
Value: https://[email protected]/3
- Name: REDIS_ADDRESS
Value: !Ref RedisAddress
- Name: REDIS_PORT
Value: !Ref RedisPort
- Name: MEMCACHED_ADDRESS
Value: !Ref MemcachedAddress
- Name: MEMCACHED_PORT
Value: !Ref MemcachedPort
- Name: POSTGRESQL_HOST
Value: !Ref DatabaseEndpoint
- Name: HOST_NAME
Value: !Ref CanonicalHostName
- Name: DJANGO_SETTINGS_MODULE
Value: concordia.settings_ecs
MountPoints:
- SourceVolume: images_volume
ContainerPath: /concordia_images
PortMappings:
- ContainerPort: 80

ConcordiaExternalService:
Type: AWS::ECS::Service
Properties:
Cluster: crowd-test
LaunchType: FARGATE
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 75
DesiredCount: 1
NetworkConfiguration:
AwsvpcConfiguration:
SecurityGroups:
- !Ref SecurityGroup
Subnets:
- subnet-0aa55b322229b945a
- subnet-0f65558b319b2d4dc
TaskDefinition: !Ref ConcordiaTask
LoadBalancers:
- ContainerName: 'app'
ContainerPort: 80
TargetGroupArn: !Ref ConcordiaExternalTargetGroup
6 changes: 3 additions & 3 deletions cloudformation/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Description: >
route on the public subnets. It deploys a pair of NAT Gateways (one in each AZ),
and default routes for them in the private subnets.

It then deploys a highly available ECS cluster using an AutoScaling Group, with
ECS hosts distributed across multiple Availability Zones.
It then deploys a Fargate ECS cluster distributed across multiple
Availability Zones.

Finally, it deploys a pair of example ECS services from containers published in
Finally, it deploys crowd ECS services from containers published in
Amazon EC2 Container Registry (Amazon ECR).
Mappings:
EnvironmentMapping:
Expand Down
14 changes: 0 additions & 14 deletions cloudformation/setup.sh

This file was deleted.

Loading