-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathTaskfile.yml
More file actions
375 lines (313 loc) · 13.6 KB
/
Taskfile.yml
File metadata and controls
375 lines (313 loc) · 13.6 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
version: '3'
env:
CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY: "ghcr.io/pierrebeucher/cloudypad"
CLOUDYPAD_BUILD_CORE_IMAGE_TAG: "local"
CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY: "ghcr.io/pierrebeucher/cloudypad/sunshine"
CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG: "local"
tasks:
#
# Build and test
#
# Run unit tests.
# By default, all tests are run recursively with "test/unit --recursive",
# CLI arguments are passed directly to mocha to allow running specific tests
#
# Note that by passing CLI arguments you MUST pass "--" (to separate CLI args from task args)
# and a test file like "test/unit" otherwise mocha will not run any tests
#
# eg.
# task test-unit -- test/unit --recursive # run all tests
# task test-unit -- test/unit --recursive --grep "should list all quota instance types" # run a single test
# task test-unit -- test/unit/instance/quota/accessor.spec.ts # run a single test file
test-unit:
cmds:
- npx mocha --config test/unit/.mocharc.json {{ .CLI_ARGS | default "test/unit --recursive" }}
build-pnpm:
cmds:
- pnpm run build
build-pnpm-tar:
cmds:
- task: build-pnpm
- (cd dist && pnpm pack)
test-compile:
cmds:
- npx tsc
#
# Local development
#
# For faster development workflow, build and import Sunshine image into dev VM
# - Build image locally as tar archive
# - Copy image to dev VM
# - Import image into dev VM
# - Run Sunshine container in dev VM
# Note: might as well use a bind mount from host to dev VM instead of scp
dev-docker-sunshine-to-vm:
cmds:
- task: build-sunshine-container-local
- >
docker image save $CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG -o tmp/sunshine-container-image.tar
- scp -i .vagrant/machines/default/virtualbox/private_key tmp/sunshine-container-image.tar vagrant@192.168.56.43:/tmp
- ssh -i .vagrant/machines/default/virtualbox/private_key vagrant@192.168.56.43 docker load -i /tmp/sunshine-container-image.tar
- ansible-playbook -i ansible/inventories/dev-vagrant.yml ansible/sunshine.yml -t sunshine-docker
- ssh -i .vagrant/machines/default/virtualbox/private_key vagrant@192.168.56.43
docker compose -f sunshine/docker-compose.yml -p sunshine up -d
# Quick dev build + deploy for rapid Sunshine container feedback loop
dev-ansible-config:
cmds:
- ansible-playbook -i ansible/inventories/dev-vagrant.yml ansible/sunshine.yml
dev-ansible-config-with-docker:
cmds:
- task: dev-docker-sunshine-to-vm
- task: dev-ansible-config
- vagrant ssh -c "docker restart cloudy"
dev-docker-sunshine-build-push-image:
cmds:
- task: build-sunshine-container-local
- docker tag $CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG $CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:dev
- docker push $CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:dev
dev-docker-core-build-push-image:
cmds:
- task: build-core-container-local
- docker tag $CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG $CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:dev
- docker push $CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:dev
#
# Tests
#
# Detect potential circular deps with Madge
test-circular-deps:
cmd: npx -y madge --ts-config ./tsconfig.json -c .
test-integ-stable:
cmds:
- task: test-integ-s3-side-effects
- task: test-integ-provider-dummy
- task: test-integ-provider-scaleway
- task: test-integ-provider-aws
- task: test-integ-provider-azure
- task: test-integ-provider-gcp
- task: test-integ-provider-paperspace
- task: test-integ-provider-linode
# Setup containers for integration tests
# Cleanup and start containers
test-integ-setup:
cmds:
- task: test-integ-cleanup
- docker compose -f test/integ/docker-compose.yml up -d
test-integ-cleanup:
cmds:
- docker compose -f test/integ/docker-compose.yml down -v
# Run side-effects tests
test-integ-s3-side-effects:
cmds:
- task: test-integ-setup
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/state/side-effects/s3.spec.ts
test-integ-provider-aws:
cmds:
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/aws/client.spec.ts
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/aws/lifecycle.spec.ts
test-integ-provider-scaleway:
cmds:
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/scaleway/client.spec.ts
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/scaleway/lifecycle.spec.ts
test-integ-provider-azure:
cmds:
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/azure/client.spec.ts
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/azure/lifecycle.spec.ts
test-integ-provider-gcp:
cmds:
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/gcp/lifecycle.spec.ts
test-integ-provider-paperspace:
cmds:
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/paperspace/client.spec.ts
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/paperspace/lifecycle.spec.ts
test-integ-provider-dummy:
cmds:
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/dummy/lifecycle.spec.ts
test-integ-provider-linode:
cmds:
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/linode/client.spec.ts
- npx mocha --config test/integ/.mocharc.json ./test/integ/stable/core/providers/linode/lifecycle.spec.ts
# Ensure analytics key are matching in various places in code
test-analytics-key-match:
- cmd: test/shell/test-matching-analytics-key.sh
# Ensure install script is working
test-install-script:
- cmd: test/shell/test-install.sh
# Smoke test to check container image is working
test-container-smoke-test:
cmds:
- task: build-core-container-local
- docker run $CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG --version
- >-
[ $(docker run $CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG --version) = $(cat package.json | jq .version -r) ]
|| echo "Version in container image doesn't match package.json version"
# Check documentation links for broken links
# Self-contained: starts mdbook server, runs test, cleans up
#
# Skip epicgames.com as it returns 403 for bot calls
# Skip github.com/.../edit as it's edit links generated by mdbook and may be rate-limited
# Skip localhost:47990 as it's an example link
test-doc-links:
dir: docs
cmd: |
echo "Starting local mdbook serve in background..."
mdbook serve &
echo "mdbook serve started..."
# Wait for mdbook serve to be ready
timeout 30 bash -c 'until curl -s http://localhost:3000 > /dev/null; do sleep 1; done'
docker run --network host --rm raviqqe/muffet@sha256:76b5dd90b589470abd8b93c08e115016d098104ca7d819ff077d5894c501bebc \
http://localhost:3000 \
-b 8192 \
-e 'https://localhost:47990' \
-e 'https://repo.steampowered.com' \
--max-response-body-size 100000000 \
--accepted-status-codes='200..300,429,403' \
--timeout 30
RESULT=$?
echo "Dead link result check result: $RESULT"
# Not perfect but sufficient for now
echo "Killing mdbook serve..."
killall mdbook
exit $RESULT
#
# Utils
#
mdbook-serve:
dir: docs
cmd: mdbook serve
# Generate Typescript Paperspace client from OpenAPI specifications
paperspace-client-gen:
vars:
PAPERSPACE_OPENAPI_DIR: "src/providers/paperspace/client/openapi"
PAPERSPACE_GENERATED_DIR: "src/providers/paperspace/client/generated-api"
cmds:
- curl https://api.paperspace.com/v1/openapi.json -o {{ .PAPERSPACE_OPENAPI_DIR }}/openapi.json
# Filter only machine-related operations
# Our client doesn't need the rest for now
- >-
cat {{ .PAPERSPACE_OPENAPI_DIR }}/openapi.json | jq '{ openapi, info, servers, components, externalDocs, paths: {
"/auth/session": .paths."/auth/session",
"/public-ips": .paths."/public-ips",
"/public-ips/{ip}": .paths."/public-ips/{ip}",
"/machines": .paths."/machines",
"/machines/{id}": .paths."/machines/{id}",
"/machines/{id}/restart": .paths."/machines/{id}/restart",
"/machines/{id}/start": .paths."/machines/{id}/start",
"/machines/{id}/stop": .paths."/machines/{id}/stop",
}}' > {{ .PAPERSPACE_OPENAPI_DIR }}/machines-only.json
# # Cleanup old files before generation
- rm -rf {{ .PAPERSPACE_GENERATED_DIR }} || true
# Run generator
- >-
podman run -it --rm -v $PWD:/local -w /local docker.io/openapitools/openapi-generator-cli:latest@sha256:6747991566e4c3e43a30d5982f21da08c1cad78e95093fab04f494687b341788 generate
-i {{ .PAPERSPACE_OPENAPI_DIR }}/machines-only.json
--skip-validate-spec
-g typescript-axios
-o {{ .PAPERSPACE_GENERATED_DIR }}
#
# Build
#
#
# Build Core and Sunshine containers
# - local: inline cache, no push
# - ci: use and push cache, but don't push image itself
# - release: use cache, push final image
# Core
build-core-container-local:
cmds:
- >
docker buildx build .
--cache-from type=local,src=./tmp/core-container.cache.tgz
--cache-to type=inline
--cache-to type=local,dest=./tmp/core-container.cache.tgz
-t $CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG
--load
build-core-container-ci:
cmds:
- >
docker buildx build .
--cache-from type=registry,ref=$CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG-cache
--cache-from type=registry,ref=$CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:master-cache
--cache-to type=registry,ref=$CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG-cache
-t $CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG
--load
# Push currently built core container image as "dev" tag
build-core-container-push-current-as-dev:
cmds:
- >-
docker tag
$CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG
$CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:dev
- docker push $CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:dev
# Build and push core container image for release with required labels and target architectures
# Image labels are important for some processing (eg. cleanup), don't remove them
build-core-container-release:
vars:
CLOUDYPAD_VERSION:
sh: jq -r .version package.json
cmds:
- >
if [ -z "{{ .CLOUDYPAD_VERSION }}" ]; then
echo "CLOUDYPAD_VERSION={{ .CLOUDYPAD_VERSION }}"
echo "CLOUDYPAD_VERSION not set. It should have been set from package.json - this is certainly a bug."
exit 1
fi
- >
if [ -z "{{ .CLOUDYPAD_VERSION }}" ]; then
echo "CLOUDYPAD_VERSION={{ .CLOUDYPAD_VERSION }}"
echo "CLOUDYPAD_VERSION not set. It should have been set from package.json - this is certainly a bug."
exit 1
fi
- >
docker buildx build .
--cache-from type=registry,ref=$CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG-cache
--cache-from type=registry,ref=$CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:master-cache
-t $CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG
--platform "linux/amd64,linux/arm64"
--label "cloudypad.version={{ .CLOUDYPAD_VERSION }}"
--push
- echo "Built $CLOUDYPAD_BUILD_CORE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_CORE_IMAGE_TAG"
# Sunshine
build-sunshine-container-local:
cmds:
- >
docker buildx build containers/sunshine/
--cache-from type=local,src=./tmp/sunshine-container.cache.tgz
--cache-to type=inline
--cache-to type=local,dest=./tmp/sunshine-container.cache.tgz
-t $CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG
--load
- echo "Built $CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG"
build-sunshine-container-ci:
cmds:
- >
docker buildx build containers/sunshine/
--cache-from type=registry,ref=$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG-cache
--cache-from type=registry,ref=$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:master-cache
--cache-to type=registry,ref=$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG-cache
-t $CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG
--load
# Push currently built Sunshine image as "dev" tag
build-sunshine-container-push-current-as-dev:
cmds:
- >-
docker tag
$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG
$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:dev
- docker push $CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:dev
build-sunshine-container-release:
cmds:
- >
docker buildx build containers/sunshine/
--cache-from type=registry,ref=$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG-cache
--cache-from type=registry,ref=$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:master-cache
-t $CLOUDYPAD_BUILD_SUNSHINE_IMAGE_REGISTRY:$CLOUDYPAD_BUILD_SUNSHINE_IMAGE_TAG
--push
#
# Release
#
release-check-version:
cmds:
- >
[[ -z "{{ .CLOUDYPAD_RELEASE_VERSION }}" ]] && echo "CLOUDYPAD_RELEASE_VERSION not set" && exit 1 || true
release-create:
cmd: ./hack/release-create.sh