-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
124 lines (117 loc) · 4.11 KB
/
.gitlab-ci.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
variables:
PROD_BACKEND_URL: "recru-app-backend.scalac.io"
DEVEL_BACKEND_URL: "recru-app-devel-backend.scalac.io"
PROD_S3_BUCKET: "new.scalac.io"
DEVEL_S3_BUCKET: "devel-new.scalac.io"
PROD_CLOUDFRONT_ID: "E39OM94WC3J4I3"
DEVEL_CLOUDFRONT_ID: "E3CQDMNIMIRHIN"
cache:
paths:
- build/
stages:
- build
- deploy
build:
stage: build
image: node:4.8.7
script:
- npm install
- node_modules/.bin/gulp build -p
- mv build/app-*.css build/app.css
- mv build/app-*.js build/app.js
- sed -i 's#../../../assets#./assets#g' build/app.js
- chmod -R 777 build
deploy_devel:
stage: deploy
variables:
S3_BUCKET: $DEVEL_S3_BUCKET
CLOUDFRONT_ID: $DEVEL_CLOUDFRONT_ID
BACKEND_URL: $DEVEL_BACKEND_URL
image:
name: garland/aws-cli-docker:latest
#entrypoint: [""]
script:
- set -x
- sed -i "s#${PROD_BACKEND_URL}#${BACKEND_URL}#g" build/app.js
- export EPOCH=$(date +%s)
- aws s3 cp s3://${S3_BUCKET}/join_us s3://${S3_BUCKET}/join_us_${EPOCH} --recursive
# retain last 5 backups
- aws s3 ls s3://${S3_BUCKET}/ | egrep -o "join_us_[[:digit:]]+" | egrep -o '[[:digit:]]+$' | sort -r | tail -n +5 | xargs -n 1 -I {} aws s3 rm s3://${S3_BUCKET}/join_us_{} --recursive
- aws s3 rm s3://${S3_BUCKET}/join_us/ --recursive
- aws s3 cp assets s3://${S3_BUCKET}/join_us/assets --recursive
- aws s3 cp build/ s3://${S3_BUCKET}/join_us/ --recursive
- aws s3 cp index.html s3://${S3_BUCKET}/join_us/
- aws configure set preview.cloudfront true
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths "/*"
only:
- devel
environment:
name: $CI_COMMIT_REF_NAME
revert_devel:
stage: deploy
variables:
S3_BUCKET: $DEVEL_S3_BUCKET
CLOUDFRONT_ID: $DEVEL_CLOUDFRONT_ID
BACKEND_URL: $DEVEL_BACKEND_URL
image:
name: garland/aws-cli-docker:latest
#entrypoint: [""]
script:
- set -x
- aws s3 rm s3://${S3_BUCKET}/join_us/ --recursive
- NEWEST_EPOCH=$(s3 ls s3://${S3_BUCKET}/ | egrep -o "join_us_[[:digit:]]+" | egrep -o '[[:digit:]]+$' | sort -r | head -1)
- aws s3 cp s3://${S3_BUCKET}/join_us_${NEWEST_EPOCH} s3://${S3_BUCKET}/join_us --recursive
- aws configure set preview.cloudfront true
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths "/*"
only:
- devel
when: manual
environment:
name: $CI_COMMIT_REF_NAME
deploy_production:
stage: deploy
variables:
S3_BUCKET: $PROD_S3_BUCKET
CLOUDFRONT_ID: $PROD_CLOUDFRONT_ID
BACKEND_URL: $PROD_BACKEND_URL
image:
name: garland/aws-cli-docker:latest
entrypoint: [""]
script:
- set -x
- export EPOCH=$(date +%s)
- aws s3 cp s3://${S3_BUCKET}/join_us s3://${S3_BUCKET}/join_us_${EPOCH} --recursive
# retain last 5 backups
- aws s3 ls s3://${S3_BUCKET}/ | egrep -o "join_us_[[:digit:]]+" | egrep -o '[[:digit:]]+$' | sort -r | tail -n +5 | xargs -n 1 -I {} aws s3 rm s3://${S3_BUCKET}/join_us_{} --recursive
- aws s3 rm s3://${S3_BUCKET}/join_us/ --recursive
- aws s3 cp assets s3://${S3_BUCKET}/join_us/assets --recursive
- aws s3 cp build/ s3://${S3_BUCKET}/join_us/ --recursive
- aws s3 cp index.html s3://${S3_BUCKET}/join_us/
- aws configure set preview.cloudfront true
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths "/*"
only:
- master
when: manual
environment:
name: $CI_COMMIT_REF_NAME
revert_production:
stage: deploy
variables:
S3_BUCKET: $PROD_S3_BUCKET
CLOUDFRONT_ID: $PROD_CLOUDFRONT_ID
BACKEND_URL: $PROD_BACKEND_URL
image:
name: garland/aws-cli-docker:latest
entrypoint: [""]
script:
- set -x
- aws s3 rm s3://${S3_BUCKET}/join_us/ --recursive
- NEWEST_EPOCH=$(s3 ls s3://${S3_BUCKET}/ | egrep -o "join_us_[[:digit:]]+" | egrep -o '[[:digit:]]+$' | sort -r | head -1)
- aws s3 cp s3://${S3_BUCKET}/join_us_${NEWEST_EPOCH} s3://${S3_BUCKET}/join_us --recursive
- aws configure set preview.cloudfront true
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths "/*"
only:
- master
when: manual
environment:
name: $CI_COMMIT_REF_NAME