-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcircle.yml
70 lines (64 loc) · 2.99 KB
/
circle.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
# CircleCI Environment Variables:
# - AWS_ACCOUNT_ID
# - AWS_ACCESS_KEY_ID
# - AWS_SECRET_ACCESS_KEY
# - AWS_REGION
# - AWS_S3_BUCKET
# - AWS_CODEDEPLOY_APPLICATION_NAME
# - AWS_CODEDEPLOY_DEPLOYMENT_GROUP
# - AWS_ECS_CLUSTER
# - AWS_ECS_TASK
# - AWS_ECS_SERVICE
general:
artifacts:
- docker
machine:
environment:
AWS_S3_KEY: demo/$( echo ${CIRCLE_SHA1} | cut -c 1-7 )-${CIRCLE_BUILD_NUM}.tar.gz
services:
- docker
dependencies:
pre:
- docker version
- docker info
- aws --version
override:
- docker build -f app-api/Dockerfile -t api .
- docker build -f app-web/Dockerfile -t web .
test:
override:
- docker run -d -p 8001:80 api
- docker run -d -p 8002:80 web; sleep 10
- curl --retry 10 --retry-delay 5 -v http://localhost:8001
- curl --retry 10 --retry-delay 5 -v http://localhost:8002
deployment:
staging_api:
tag: /api-.*/
commands:
# Build docker images
- aws --region ${AWS_REGION} ecr get-login | sh
- docker tag api ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/demo/api:latest
- docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/demo/api:latest
#
# Send contents to S3
- aws --region ${AWS_REGION} deploy push --application-name ${AWS_CODEDEPLOY_APPLICATION_NAME} --s3-location s3://${AWS_S3_BUCKET}/${AWS_S3_KEY} --source ./app-api
#
# Deploy with CodeDeploy
- aws --region ${AWS_REGION} s3api wait object-exists --bucket ${AWS_S3_BUCKET} --key ${AWS_S3_KEY}
- aws --region ${AWS_REGION} deploy create-deployment --application-name ${AWS_CODEDEPLOY_APPLICATION_NAME} --deployment-group-name ${AWS_CODEDEPLOY_DEPLOYMENT_GROUP} --deployment-config-name CodeDeployDefault.AllAtOnce --s3-location bucket=${AWS_S3_BUCKET},key=${AWS_S3_KEY},eTag=$( aws s3api head-object --bucket ${AWS_S3_BUCKET} --key ${AWS_S3_KEY} --query 'ETag' --output text | sed 's/^"\(.*\)"$/\1/' ),bundleType=zip --ignore-application-stop-failures
staging_web:
tag: /web-.*/
commands:
# Build docker images
- aws --region ${AWS_REGION} ecr get-login | sh
- docker tag web ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/demo/web:${CIRCLE_TAG}
- docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/demo/web:${CIRCLE_TAG}
#
# Update an ECS TaskDefinition
- sed -i -e 's/AWS_ACCOUNT_ID/'${AWS_ACCOUNT_ID}'/g' app-web/TaskDefinition.json
- sed -i -e 's/AWS_REGION/'${AWS_REGION}'/g' app-web/TaskDefinition.json
- sed -i -e 's/IMAGE_TAG/'${CIRCLE_TAG}'/g' app-web/TaskDefinition.json
- aws --region ${AWS_REGION} ecs register-task-definition --family ${AWS_ECS_TASK} --cli-input-json file://app-web/TaskDefinition.json
#
# Deploy with ECS
- aws --region ${AWS_REGION} ecs update-service --cluster ${AWS_ECS_CLUSTER} --service ${AWS_ECS_SERVICE} --desired-count 2 --task-definition $(aws --region ${AWS_REGION} ecs list-task-definitions --query 'sort(taskDefinitionArns)[-1]' --output text)