-
Notifications
You must be signed in to change notification settings - Fork 2
/
circle.yml
89 lines (83 loc) · 3.75 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
defaults: &defaults
working_directory: ~/project
docker:
- image: circleci/node:10
environment:
TERM: xterm
version: 2
jobs:
build:
<<: *defaults
steps:
- checkout
- run: npm install
- run: npm run build:lib
- run: npm run build:docs
- store_artifacts:
path: dist
- persist_to_workspace:
root: ./
paths:
- ./
deploy:
<<: *defaults
steps:
- attach_workspace:
at: ~/project
- run: sudo apt-get update
- run: sudo apt-get install python3 python3-pip
- run: sudo pip3 install awscli --upgrade
- run:
name: Create or update S3 bucket
command: |
sed -i 's|{{ S3_BUCKET }}|'${DEPLOY_URI}'|g' .aws/config/s3.json
(aws cloudformation create-stack --stack-name "${DEPLOY_STACK}-s3" --template-body "file://.aws/templates/s3.template" --parameters "file://.aws/config/s3.json" --region eu-west-1 \
&& aws cloudformation wait stack-create-complete --stack-name "${DEPLOY_STACK}-s3" --region eu-west-1) \
|| (aws cloudformation update-stack --stack-name "${DEPLOY_STACK}-s3" --template-body "file://.aws/templates/s3.template" --parameters "file://.aws/config/s3.json" --region eu-west-1 \
&& aws cloudformation wait stack-update-complete --stack-name "${DEPLOY_STACK}-s3" --region eu-west-1) \
|| echo "SKIPPING create & update of 's3'"
no_output_timeout: 30m
- run:
name: Create or update CloudFront distribution
command: |
sed -i 's|{{ AWS_CERT }}|'${DEPLOY_CERT}'|g' .aws/config/cloudfront.json
sed -i 's|{{ S3_STACK }}|'${DEPLOY_STACK}-s3'|g' .aws/config/cloudfront.json
(aws cloudformation create-stack --stack-name "${DEPLOY_STACK}-cloudfront" --template-body "file://.aws/templates/cloudfront.template" --parameters "file://.aws/config/cloudfront.json" --region eu-west-1 \
&& aws cloudformation wait stack-create-complete --stack-name "${DEPLOY_STACK}-cloudfront" --region eu-west-1) \
|| (aws cloudformation update-stack --stack-name "${DEPLOY_STACK}-cloudfront" --template-body "file://.aws/templates/cloudfront.template" --parameters "file://.aws/config/cloudfront.json" --region eu-west-1 \
&& aws cloudformation wait stack-update-complete --stack-name "${DEPLOY_STACK}-cloudfront" --region eu-west-1) \
|| echo "SKIPPING create & update of 'cloudfront'"
no_output_timeout: 1h
- run:
name: Sync assets to S3
command: aws s3 sync dist/bedrock s3://${DEPLOY_URI} --delete --region eu-west-1 --cache-control max-age=2592000,public
- run:
name: Invalidate CloudFront caches
command: aws cloudfront create-invalidation --distribution-id `aws cloudformation list-stack-resources --stack-name "${DEPLOY_STACK}-cloudfront" --region eu-west-1 | python -c 'import sys; import json; res=json.loads(sys.stdin.read()); print(res["StackResourceSummaries"][0]["PhysicalResourceId"])'` --paths '/*' --region eu-west-1
release:
<<: *defaults
steps:
- attach_workspace:
at: ~/project
- run: npm install
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: npm run release
workflows:
version: 2
docs-deploy:
jobs:
- build
- deploy:
context: bedrock-release
requires:
- build
filters:
branches:
only: master
- release:
context: bedrock-release
requires:
- build
filters:
branches:
only: master