/
config.yml
302 lines (289 loc) · 9.02 KB
/
config.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
version: 2
# The following stanza defines a map named defaults with a variable that may be
# inserted using the YAML merge (<<: *) key later in the file to save some
# typing. See http://yaml.org/type/merge.html for details.
defaults: &defaults
environment:
- DOCKER_REPOSITORY: "reactioncommerce/reaction"
- DOCKER_NAMESPACE: "reactioncommerce"
- DOCKER_NAME: "reaction"
- GLOBAL_CACHE_VERSION: "v2"
- TOOL_NODE_FLAGS: "--max-old-space-size=4096"
working_directory: ~/reaction-app
docker:
- image: circleci/node:8-stretch
jobs:
build:
<<: *defaults
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- restore_cache:
name: Restoring Meteor cache
key: reaction-v2-meteor
- run:
name: Install Meteor
command: |
if [[ -f ~/.meteor/meteor ]]; then \
printf "\nMeteor already installed. Creating symlink.\n"
sudo ln -s ~/.meteor/meteor /usr/local/bin/meteor;
else
printf "\Installing Meteor\n"
curl https://install.meteor.com | /bin/sh
fi
- save_cache:
name: Saving Meteor to cache
key: reaction-v2-meteor-{{ epoch }}
paths:
- ~/.meteor
- run:
name: Meteor NPM Install
command: meteor npm install
- run:
name: Build dist bundle
command: meteor build --directory ../build/
- run:
name: Check .js file size
command: |
maxSize=2967000
size=$( wc -c ../build/bundle/programs/web.browser/*.js | awk '{$1=$1};1' | cut -d " " -f 1 )
if [[ $size -gt $maxSize ]]; then
echo "The production js file has size" $size "which exceeds limit of" $maxSize 1>&2
exit 3
else
echo "The js file size is" $size
fi
- run:
name: Check .css file size
command: |
maxSize=24888
size=$( wc -c ../build/bundle/programs/web.browser/*.css | awk '{$1=$1};1' | cut -d " " -f 1 )
if [[ $size -gt $maxSize ]]; then
echo "The production js file has size" $size "which exceeds limit of" $maxSize 1>&2
exit 3
else
echo "The css file size is" $size
fi
# Store node_modules dependency cache.
# Saved with package.json checksum and timestamped branch name keys.
- save_cache:
key: reaction-v2-node-modules-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
paths:
- node_modules
- save_cache:
key: reaction-v2-node-modules-{{ .Branch }}-{{ epoch }}
paths:
- node_modules
docker-build:
<<: *defaults
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- attach_workspace:
at: docker-cache
- run:
name: Discover Docker Tags
command: |
mkdir -p docker-cache
.circleci/bin/docker-tags "$CIRCLE_SHA1" "$CIRCLE_BRANCH" | sed 's/\//-/g' \
> docker-cache/docker-tags.txt
- run:
name: Docker build
command: |
docker build \
--build-arg TOOL_NODE_FLAGS="--max-old-space-size=4096" \
-t "$DOCKER_REPOSITORY:$CIRCLE_SHA1" .
mkdir -p docker-cache
docker save \
-o docker-cache/docker-image.tar \
"$DOCKER_REPOSITORY:$CIRCLE_SHA1"
no_output_timeout: 30m
- persist_to_workspace:
root: docker-cache
paths:
- docker-image.tar
- docker-tags.txt
docker-push:
<<: *defaults
steps:
- setup_remote_docker:
docker_layer_caching: true
- attach_workspace:
at: docker-cache
- run:
name: Load Docker Image
command: |
docker load < docker-cache/docker-image.tar
- run:
name: Tag Docker Image
command: |
cat docker-cache/docker-tags.txt \
| xargs -t -I % \
docker tag \
"$DOCKER_REPOSITORY:$CIRCLE_SHA1" \
"$DOCKER_REPOSITORY:%"
- run:
name: Docker Push
command: |
if [ -z "$CIRCLE_PR_USERNAME" ]; then \
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
docker push "$DOCKER_REPOSITORY:$CIRCLE_SHA1"
cat docker-cache/docker-tags.txt \
| xargs -t -I % \
docker push "$DOCKER_REPOSITORY:%"
else
echo "No deploy for forks"
fi
deploy-docs:
<<: *defaults
steps:
- checkout
- run:
name: Install AWS CLI
command: sudo apt-get -y -qq install awscli
- run:
name: NPM Install JSDoc
command: sudo npm install -g jsdoc
- run:
name: Build JSDoc files
command: |
jsdoc . \
--verbose \
--configure .reaction/jsdoc/jsdoc.json \
--readme .reaction/jsdoc/templates/static/README.md
- run:
name: Deploy Doc files to S3
command: |
if [[ "${API_DOC_BUCKET}" && "${API_DOC_BUCKET_REGION}" ]]; then
aws s3 sync /tmp/reaction-docs ${API_DOC_BUCKET} --delete --region ${API_DOC_BUCKET_REGION}
else
echo "S3 bucket configuration not found for jsdocs"
echo "Set API_DOC_BUCKET and API_DOC_BUCKET_REGION to build and deploy jsdocs to S3"
exit 1;
fi
eslint:
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- reaction-v2-node-modules-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
- reaction-v2-node-modules-{{ .Branch }}
- reaction-v2-node-modules-master
- run:
name: Run Lint
command: |
npm run lint -- --quiet
graphql-lint:
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- reaction-v2-node-modules-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
- reaction-v2-node-modules-{{ .Branch }}
- reaction-v2-node-modules-master
- run:
name: Lint GraphQL schemas
command: |
npm run lint:gql
test-unit:
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- reaction-v2-node-modules-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
- reaction-v2-node-modules-{{ .Branch }}
- reaction-v2-node-modules-master
- run:
name: Run Unit Tests
command: npm run test:unit
test-integration:
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- reaction-v2-node-modules-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
- reaction-v2-node-modules-{{ .Branch }}
- reaction-v2-node-modules-master
- run:
name: Run Integration Tests
command: npm run test:integration
test-e2e:
<<: *defaults
docker:
- image: reactioncommerce/reaction-automation-client:latest
steps:
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Run Tests
command: |
docker run -t -e URL=${STAGING_URL} reactioncommerce/reaction-automation-client:latest npm run-script chrome
test-metrics:
<<: *defaults
steps:
- checkout
- run:
name: California
command: |
.circleci/bin/calibre-deploy.sh ${STAGING_URL} California
- run:
name: North Virginia
command: |
.circleci/bin/calibre-deploy.sh ${STAGING_URL} NorthVirginia
- run:
name: London
command: |
.circleci/bin/calibre-deploy.sh ${STAGING_URL} London
- run:
name: Frankfurt
command: |
.circleci/bin/calibre-deploy.sh ${STAGING_URL} Frankfurt
dockerfile-lint:
<<: *defaults
docker:
- image: hadolint/hadolint:v1.6.6-6-g254b4ff
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Dockerfile Lint
command: |
hadolint Dockerfile
workflows:
version: 2
build_and_test:
jobs:
- build
- dockerfile-lint
- test-unit:
requires:
- build
- test-integration:
requires:
- build
- eslint:
requires:
- build
- graphql-lint:
requires:
- build
- docker-build:
context: reaction-build-read
- docker-push:
context: reaction-publish-docker
requires:
- docker-build
- deploy-docs:
requires:
- test-unit
- docker-build
filters:
branches:
only: /^master$/