forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.drone.yml
More file actions
321 lines (287 loc) · 9.58 KB
/
Copy path.drone.yml
File metadata and controls
321 lines (287 loc) · 9.58 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
---
# Drone CI pipeline running at: https://drone.cdn-code.org/code-dot-org/code-dot-org/
#
# Docs here: https://docs.google.com/document/d/1Qls20xfNN6T_DErOMwVQOFJsxAEAdMWFHzBDIbxyUQQ/edit#heading=h.9bln2fv2lgqd
#
# NOTE: after making changes to this file, you'll need to sign them using
# `drone sign code-dot-org/code-dot-org --save`
kind: pipeline
type: docker
name: unit
clone:
disable: true
services:
- name: unit-tests-redis
image: redis
ports:
- 6379
steps:
- name: bin/drone/shell
image: curlimages/curl
commands:
- set +x
# If running on EC2, get hostname from ec2 metadata
- "IMDS_TOKEN=$(curl -s -X PUT http://169.254.169.254/latest/api/token -H \"X-aws-ec2-metadata-token-ttl-seconds: 21600\")"
- "hostname=$(curl -s -H \"X-aws-ec2-metadata-token: $IMDS_TOKEN\" http://169.254.169.254/latest/meta-data/public-hostname)"
- |
cat <<EOF
Running on hostname: $hostname
To "ssh" into this drone instance, wait until the 'unit-tests' step starts and run:
bin/drone/shell $hostname
You can also open a VSCode tunnel into drone to edit live:
bin/drone/vscode $hostname
EOF
# We cache a clone of staging in the `cache-staging-clone` pipeline
- name: get-cached-staging
image: plugins/s3-cache
settings:
filename: cache-staging-clone.tar
endpoint: s3://cdo-drone
restore: true
debug: true
pull: true
mount:
- .
- name: checkout
image: bitnami/git
commands:
- git lfs install --skip-repo
# We should be in a cached git repo, but clone if the cache failed
- "[ -d .git ] || (echo 'WARNING: get-cached-staging failed: checkout will be SLOW and LFS $$$!' && git clone --branch $DRONE_BRANCH $DRONE_GIT_HTTP_URL .)"
# Checkout our target branch (=the PR)
- git fetch origin $DRONE_SOURCE_BRANCH
- git checkout $DRONE_SOURCE_BRANCH
- git pull
- git reset --hard $DRONE_COMMIT
# Fetch the target branch (which is staging for pull requests.) We need this for determining which tests to run based on changed files.
- git remote set-branches --add origin $DRONE_TARGET_BRANCH
- git fetch --depth 100 origin $DRONE_TARGET_BRANCH
# Merge so we're up-to-date with the target before running tests.
- git config user.name "Drone"
- git config user.email "drone-fake-user@code.org"
- git merge origin/$DRONE_TARGET_BRANCH
- name: restore-cache
image: plugins/s3-cache
settings:
endpoint: s3://cdo-drone
debug: true
pull: true
restore: true
filename: unit-tests-cache-ubuntu-20.tar
- name: unit-tests
# see: docker/ci/Dockerfile
# TODO: switch to codedotorg/cdo-ci
image: codedotorg/code-dot-org:1.15
pull: always
volumes:
- name: rbenv
path: /home/ci/.rbenv
- name: mysql
path: /var/lib/mysql
environment:
# Each Drone secret below must be explicitly written to locals.yml in /docker/unit_tests.sh
CLOUDFRONT_KEY_PAIR_ID:
from_secret: CLOUDFRONT_KEY_PAIR_ID
CLOUDFRONT_PRIVATE_KEY:
from_secret: CLOUDFRONT_PRIVATE_KEY
commands:
- sudo chown -R ci:ci .
# cache is restored to source directory, so we need to copy it into the right place
- cp -rn "$(pwd)/home/ci/.rbenv" /home/ci || true
- rm -rf "$(pwd)/home/ci/.rbenv"
# Depended on by CI: https://github.com/code-dot-org/code-dot-org/blob/048e4ddffd52e62fd6a13566ea6ccd38a6701d89/lib/cdo/ci.rb/#L16
- export GIT_COMMIT=$DRONE_COMMIT
- export CI_BASE_BRANCH=$DRONE_TARGET_BRANCH
- export CI_HEAD_BRANCH=$DRONE_SOURCE_BRANCH
- EXIT_CODE=0
- /entrypoint.sh docker/unit_tests.sh || EXIT_CODE=$?
- while pgrep bash >/dev/null; do echo "found bash process; keeping container alive"; sleep 20; done
- exit $EXIT_CODE
- name: update-cache
image: plugins/s3-cache
volumes:
- name: rbenv
path: /home/ci/.rbenv
settings:
endpoint: s3://cdo-drone
debug: true
pull: true
rebuild: true
filename: unit-tests-cache-ubuntu-20.tar
mount:
- /home/ci/.rbenv
volumes:
- name: rbenv
temp: {}
- name: mysql
temp: {}
trigger:
branch:
exclude:
- "production"
- "test"
- "levelbuilder"
event:
- pull_request
---
kind: pipeline
type: docker
name: ui
clone:
disable: true
services:
- name: ui-tests-redis
image: redis
ports:
- 6379
steps:
- name: bin/drone/shell
image: curlimages/curl
commands:
- set +x
# If running on EC2, get hostname from ec2 metadata
- "IMDS_TOKEN=$(curl -s -X PUT http://169.254.169.254/latest/api/token -H \"X-aws-ec2-metadata-token-ttl-seconds: 21600\")"
- "hostname=$(curl -s -H \"X-aws-ec2-metadata-token: $IMDS_TOKEN\" http://169.254.169.254/latest/meta-data/public-hostname)"
- |
cat <<EOF
Running on hostname: $hostname
To "ssh" into this drone instance, wait until the 'ui-tests' step starts and run:
bin/drone/shell $hostname
You can also open a VSCode tunnel into drone to edit live:
bin/drone/vscode $hostname
EOF
# We cache a clone of staging in the `cache-staging-clone` pipeline
- name: get-cached-staging
image: plugins/s3-cache
settings:
filename: cache-staging-clone.tar
endpoint: s3://cdo-drone
restore: true
debug: true
pull: true
mount:
- .
- name: checkout
image: bitnami/git
commands:
- git lfs install --skip-repo
# We should be in a cached git repo, but clone if the cache failed
- "[ -d .git ] || (echo 'get-cached-staging failed: checkout will be SLOW and LFS $$$!' && git clone --branch $DRONE_BRANCH $DRONE_GIT_HTTP_URL .)"
# Checkout our target branch (the PR's branch).
- git fetch origin $DRONE_SOURCE_BRANCH
- git checkout $DRONE_SOURCE_BRANCH
- git pull
- git reset --hard $DRONE_COMMIT
# Also fetch the target branch (which is staging or staging-next for pull requests.) We need this for determining which tests to run based on changed files.
- git remote set-branches --add origin $DRONE_TARGET_BRANCH
- git fetch --depth 100 origin $DRONE_TARGET_BRANCH
# Merge so we're up-to-date with the target before running tests.
- git config user.name "Drone"
- git config user.email "drone-fake-user@code.org"
- git merge origin/$DRONE_TARGET_BRANCH
- name: restore-cache
image: plugins/s3-cache
settings:
endpoint: s3://cdo-drone
debug: true
pull: true
restore: true
filename: ui-tests-cache-ubuntu-20.tar
- name: ui-tests
# see: docker/ci/Dockerfile
# TODO: switch to codedotorg/cdo-ci
image: codedotorg/code-dot-org:1.15
pull: always
volumes:
- name: rbenv
path: /home/ci/.rbenv
- name: mysql
path: /var/lib/mysql
environment:
# Each Drone secret below must be explicitly written to locals.yml in /docker/ui_tests.sh
CLOUDFRONT_KEY_PAIR_ID:
from_secret: CLOUDFRONT_KEY_PAIR_ID
CLOUDFRONT_PRIVATE_KEY:
from_secret: CLOUDFRONT_PRIVATE_KEY
PROPERTIES_ENCRYPTION_KEY:
from_secret: PROPERTIES_ENCRYPTION_KEY
SAUCE_USERNAME:
from_secret: SAUCE_USERNAME
SAUCE_ACCESS_KEY:
from_secret: SAUCE_ACCESS_KEY
commands:
- sudo chown -R ci:ci .
# cache is restored to source directory, so we need to copy it into the right place
- cp -rn "$(pwd)/home/ci/.rbenv" /home/ci || true
# Depended on by CI: https://github.com/code-dot-org/code-dot-org/blob/048e4ddffd52e62fd6a13566ea6ccd38a6701d89/lib/cdo/ci.rb/#L16
- export GIT_COMMIT=$DRONE_COMMIT
- export CI_BASE_BRANCH=$DRONE_TARGET_BRANCH
- export CI_HEAD_BRANCH=$DRONE_SOURCE_BRANCH
- export CI_BUILD_NUMBER=$DRONE_BUILD_NUMBER # used by UI tests to set their S3 log path
- EXIT_CODE=0
- /entrypoint.sh docker/ui_tests.sh || EXIT_CODE=$?
- while pgrep bash >/dev/null; do echo "found bash process; keeping container alive"; sleep 20; done
- exit $EXIT_CODE
- name: update-cache
image: plugins/s3-cache
volumes:
- name: rbenv
path: /home/ci/.rbenv
settings:
endpoint: s3://cdo-drone
debug: true
pull: true
rebuild: true
filename: ui-tests-cache-ubuntu-20.tar
mount:
- /home/ci/.rbenv
# Used to avoid re-seeding UI test data unless something changed - see cached_ui_test task in https://github.com/code-dot-org/code-dot-org/blob/staging/dashboard/lib/tasks/seed.rake
- dashboard/db/ui_test_data.hash
- dashboard/db/ui_test_data.sql
volumes:
- name: rbenv
temp: {}
- name: mysql
temp: {}
trigger:
branch:
exclude:
- "production"
- "test"
- "levelbuilder"
event:
- pull_request
---
# On push, cache a clone of staging to drone's S3 bucket.
# The staging cache reduces git bandwidth in PR pipelines.
kind: pipeline
type: docker
name: cache-staging-clone
clone:
disable: true
steps:
- name: clone
image: bitnami/git
commands:
- git lfs install
- git clone --branch $DRONE_BRANCH $DRONE_GIT_HTTP_URL .
- name: cache-staging-clone
image: plugins/s3-cache
settings:
filename: cache-staging-clone.tar
endpoint: s3://cdo-drone
rebuild: true
debug: true
pull: true
mount:
- .
trigger:
branch:
- "staging"
- "staging-next"
event:
- push
---
kind: signature
hmac: bee4dcf20e1a1dcbb6b1dddb9777ff0d9c7b73fda6ae26811edce8227fea5413
...