-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
987 lines (872 loc) · 32 KB
/
Taskfile.yml
File metadata and controls
987 lines (872 loc) · 32 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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
version: "1"
name: mega-saas
description: >
Ultimate SaaS platform — multi-region, multi-platform, fleet deploy,
embedded functions, CI/CD pipeline, compose overrides, includes,
Quadlet, canary/rolling/parallel strategies. Showcases EVERY Taskfile feature.
default_env: local
default_platform: web
# ─── Include — split into sub-files ──────────────────
include:
- path: ./tasks/monitoring.yml
prefix: mon
- path: ./tasks/database.yml
prefix: db
# ─── Global Variables ────────────────────────────────
variables:
APP_NAME: mega-saas
ORG: myorg
REGISTRY: ghcr.io/${ORG}
IMAGE_API: ${REGISTRY}/mega-saas-api
IMAGE_WEB: ${REGISTRY}/mega-saas-web
IMAGE_WORKER: ${REGISTRY}/mega-saas-worker
TAG: latest
DOMAIN: mega-saas.example.com
SLACK_WEBHOOK: ${SLACK_WEBHOOK:-}
SENTRY_DSN: ${SENTRY_DSN:-}
DB_NAME: mega_saas
REDIS_URL: redis://localhost:6379
S3_BUCKET: mega-saas-assets
CDN_DISTRIBUTION: ${CDN_DISTRIBUTION:-}
LOG_LEVEL: info
REPLICAS: "2"
# ─── Compose — Docker Compose integration ────────────
compose:
file: docker-compose.yml
override_files:
- docker-compose.override.yml
- docker-compose.monitoring.yml
network: proxy
auto_update: true
# ─── Environments (WHERE to deploy) ──────────────────
environments:
local:
container_runtime: docker
compose_command: docker compose
compose_file: docker-compose.yml
env_file: .env.local
variables:
DOMAIN: localhost
LOG_LEVEL: debug
REDIS_URL: redis://localhost:6379
staging:
ssh_host: staging.mega-saas.example.com
ssh_user: deploy
ssh_key: ~/.ssh/id_ed25519
container_runtime: docker
compose_command: docker compose
service_manager: compose
env_file: .env.staging
compose_file: docker-compose.yml
variables:
DOMAIN: staging.mega-saas.example.com
LOG_LEVEL: info
REPLICAS: "1"
prod-eu:
ssh_host: eu.mega-saas.example.com
ssh_user: deploy
ssh_port: 2222
ssh_key: ~/.ssh/prod_ed25519
container_runtime: podman
service_manager: quadlet
env_file: .env.prod-eu
compose_file: docker-compose.yml
quadlet_dir: deploy/quadlet
quadlet_remote_dir: ~/.config/containers/systemd
variables:
DOMAIN: eu.mega-saas.example.com
AWS_REGION: eu-west-1
LOG_LEVEL: warn
REPLICAS: "4"
prod-us:
ssh_host: us.mega-saas.example.com
ssh_user: deploy
ssh_port: 2222
ssh_key: ~/.ssh/prod_ed25519
container_runtime: podman
service_manager: quadlet
env_file: .env.prod-us
compose_file: docker-compose.yml
quadlet_dir: deploy/quadlet
quadlet_remote_dir: ~/.config/containers/systemd
variables:
DOMAIN: us.mega-saas.example.com
AWS_REGION: us-east-1
LOG_LEVEL: warn
REPLICAS: "4"
prod-asia:
ssh_host: asia.mega-saas.example.com
ssh_user: deploy
ssh_port: 2222
ssh_key: ~/.ssh/prod_ed25519
container_runtime: podman
service_manager: quadlet
env_file: .env.prod-asia
compose_file: docker-compose.yml
quadlet_dir: deploy/quadlet
quadlet_remote_dir: ~/.config/containers/systemd
variables:
DOMAIN: asia.mega-saas.example.com
AWS_REGION: ap-southeast-1
LOG_LEVEL: warn
REPLICAS: "3"
edge-cdn-eu:
ssh_host: cdn-eu.mega-saas.example.com
ssh_user: edge
ssh_key: ~/.ssh/edge_ed25519
container_runtime: podman
variables:
NODE_TYPE: cdn
REGION: eu
edge-cdn-us:
ssh_host: cdn-us.mega-saas.example.com
ssh_user: edge
ssh_key: ~/.ssh/edge_ed25519
container_runtime: podman
variables:
NODE_TYPE: cdn
REGION: us
# ─── Environment Groups (fleet / batch deploy) ───────
environment_groups:
all-prod:
members: [prod-eu, prod-us, prod-asia]
strategy: canary
canary_count: 1
prod-west:
members: [prod-eu, prod-us]
strategy: rolling
max_parallel: 1
all-edge:
members: [edge-cdn-eu, edge-cdn-us]
strategy: parallel
global:
members: [staging, prod-eu, prod-us, prod-asia]
strategy: rolling
max_parallel: 1
# ─── Platforms (WHAT to deploy) ──────────────────────
platforms:
web:
desc: Web application (React SPA + API)
variables:
BUILD_DIR: dist/web
BUILD_TARGET: web
PORT: "3000"
desktop:
desc: Electron desktop application
variables:
BUILD_DIR: dist/desktop
BUILD_TARGET: desktop
PORT: "3100"
mobile-api:
desc: Mobile backend (REST + GraphQL)
variables:
BUILD_DIR: dist/mobile
BUILD_TARGET: mobile
PORT: "3200"
# ─── Embedded Functions ──────────────────────────────
functions:
# Inline Python — Slack notification
notify:
lang: python
desc: Send Slack notification with deploy status
code: |
import os, json, urllib.request, datetime
webhook = os.environ.get("SLACK_WEBHOOK", "")
if not webhook:
print("SLACK_WEBHOOK not set — skipping notification")
else:
args = os.environ.get("FN_ARGS", "Deploy event")
env = os.environ.get("TASKFILE_ENV", "unknown")
ts = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M UTC")
payload = {
"blocks": [
{"type": "header", "text": {"type": "plain_text", "text": f"🚀 {args}"}},
{"type": "section", "text": {"type": "mrkdwn",
"text": f"*Env:* {env}\n*Time:* {ts}\n*App:* {os.environ.get('APP_NAME', '?')}"}},
]
}
data = json.dumps(payload).encode()
req = urllib.request.Request(webhook, data=data,
headers={"Content-Type": "application/json"})
urllib.request.urlopen(req)
print(f"Slack notified: {args}")
# Inline Python — Sentry release tracking
sentry-release:
lang: python
desc: Register Sentry release and associate commits
code: |
import os, subprocess
dsn = os.environ.get("SENTRY_DSN", "")
if not dsn:
print("SENTRY_DSN not set — skipping")
else:
tag = os.environ.get("TAG", "latest")
app = os.environ.get("APP_NAME", "mega-saas")
print(f"Registering Sentry release: {app}@{tag}")
# Inline shell — quick port check
check-port:
lang: shell
desc: Check if a TCP port is open on localhost
code: |
PORT=${1:-3000}
nc -z localhost $PORT 2>/dev/null && echo "✅ Port $PORT is open" || echo "❌ Port $PORT is closed"
# External shell script — health check with retries
health-check:
lang: shell
desc: Health check with configurable retries and backoff
file: scripts/health.sh
# Inline Node.js — generate deployment manifest
generate-manifest:
lang: node
desc: Generate JSON deployment manifest
code: |
const app = process.env.APP_NAME || 'mega-saas';
const tag = process.env.TAG || 'latest';
const env = process.env.TASKFILE_ENV || 'local';
const platform = process.env.TASKFILE_PLATFORM || 'web';
const manifest = {
app, version: tag, environment: env, platform,
timestamp: new Date().toISOString(),
images: {
api: `${process.env.IMAGE_API}:${tag}`,
web: `${process.env.IMAGE_WEB}:${tag}`,
worker: `${process.env.IMAGE_WORKER}:${tag}`,
},
config: { replicas: parseInt(process.env.REPLICAS || '2'), logLevel: process.env.LOG_LEVEL || 'info' }
};
console.log(JSON.stringify(manifest, null, 2));
# External Python — deployment report generator
generate-report:
lang: python
desc: Generate HTML deployment report
file: scripts/report.py
# Binary tool — YAML linting
lint-yaml:
lang: binary
desc: Lint YAML files with yamllint
file: yamllint
# ─── Pipeline — CI/CD generation ─────────────────────
pipeline:
python_version: "3.12"
runner_image: ubuntu-latest
docker_in_docker: true
branches: [main, develop, "release/*"]
install_cmd: "pip install taskfile"
secrets:
- GHCR_TOKEN
- DEPLOY_SSH_KEY
- SLACK_WEBHOOK
- SENTRY_DSN
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
cache:
- ~/.cache/pip
- node_modules
- .next/cache
artifacts:
- dist/
- coverage/
- deploy/quadlet/
stages:
- name: lint
tasks: [lint, lint-types, security-scan]
cache: [~/.cache/pip, node_modules]
- name: test
tasks: [test-unit, test-integration, test-e2e]
artifacts: [coverage/]
cache: [~/.cache/pip]
- name: build
tasks: [build-api, build-web, build-worker]
docker_in_docker: true
artifacts: [dist/]
- name: push
tasks: [push-all]
docker_in_docker: true
- name: deploy-staging
tasks: [deploy-compose]
env: staging
when: "branch:develop"
- name: deploy-prod
tasks: [deploy-quadlet]
env: prod-eu
when: manual
- name: post-deploy
tasks: [smoke-test, notify-release]
when: auto
# ─── Tasks ───────────────────────────────────────────
tasks:
# ═══════════════════════════════════════════════════
# LINT & STATIC ANALYSIS
# ═══════════════════════════════════════════════════
lint:
desc: Run all linters (ruff + eslint + prettier)
stage: lint
tags: [ci, lint, quality]
ignore_errors: true
cmds:
- ruff check src/ --fix
- npm --prefix frontend run lint
- npm --prefix frontend run prettier -- --check .
lint-types:
desc: Type checking (mypy + TypeScript)
stage: lint
tags: [ci, lint, quality]
ignore_errors: true
cmds:
- mypy src/ --strict --no-error-summary
- npm --prefix frontend run tsc -- --noEmit
security-scan:
desc: Scan for vulnerabilities (pip-audit + npm audit + bandit)
stage: lint
tags: [ci, security]
ignore_errors: true
cmds:
- pip-audit --strict
- bandit -r src/ -ll
- npm --prefix frontend audit --production
lint-yaml-task:
desc: Lint all YAML files in the project
tags: [lint, quality]
cmds:
- "@fn lint-yaml *.yml **/*.yml"
# ═══════════════════════════════════════════════════
# TESTING
# ═══════════════════════════════════════════════════
test-unit:
desc: Run unit tests with coverage
stage: test
tags: [ci, test]
timeout: 300
register: TEST_RESULT
cmds:
- pytest tests/unit/ -v --cov=src/ --cov-report=html:coverage/unit/ --cov-report=term-missing
- "@python import json; print(json.dumps({'suite': 'unit', 'status': 'passed'}))"
test-integration:
desc: Run integration tests (requires Docker services)
stage: test
tags: [ci, test, integration]
timeout: 600
condition: "docker info >/dev/null 2>&1"
cmds:
- docker compose -f docker-compose.test.yml up -d postgres redis
- sleep 3
- pytest tests/integration/ -v --cov=src/ --cov-report=html:coverage/integration/
- docker compose -f docker-compose.test.yml down -v
test-e2e:
desc: Run end-to-end tests (Playwright)
stage: test
tags: [ci, test, e2e]
timeout: 900
condition: "command -v npx >/dev/null 2>&1"
cmds:
- docker compose -f docker-compose.test.yml up -d
- sleep 5
- npx playwright test --reporter=html
- docker compose -f docker-compose.test.yml down -v
test-smoke:
desc: Quick smoke test against running instance
tags: [test, smoke]
silent: true
retries: 3
retry_delay: 5
cmds:
- curl -sf https://${DOMAIN}/health || exit 1
- curl -sf https://${DOMAIN}/api/v1/status || exit 1
- "@fn check-port 3000"
# ═══════════════════════════════════════════════════
# BUILD
# ═══════════════════════════════════════════════════
build-api:
desc: Build API Docker image
stage: build
tags: [ci, build]
deps: [test-unit]
platform: [web, mobile-api]
dir: services/api
cmds:
- docker build -t ${IMAGE_API}:${TAG} --build-arg LOG_LEVEL=${LOG_LEVEL} .
register: BUILD_API_SHA
build-web:
desc: Build Web frontend Docker image
stage: build
tags: [ci, build]
deps: [test-unit]
platform: [web]
dir: services/web
cmds:
- docker build -t ${IMAGE_WEB}:${TAG} --build-arg BUILD_TARGET=${BUILD_TARGET} .
register: BUILD_WEB_SHA
build-worker:
desc: Build async worker Docker image
stage: build
tags: [ci, build]
deps: [test-unit]
cmds:
- docker build -t ${IMAGE_WORKER}:${TAG} -f services/worker/Dockerfile .
build-desktop:
desc: Build Electron desktop app
tags: [build]
platform: [desktop]
dir: services/desktop
cmds:
- npm install
- npm run build
- npm run package -- --linux --mac --win
build-all:
desc: Build all images (parallel deps)
deps: [build-api, build-web, build-worker]
parallel: true
tags: [build]
cmds:
- echo "All images built successfully"
- "@fn generate-manifest"
# ═══════════════════════════════════════════════════
# PUSH / REGISTRY
# ═══════════════════════════════════════════════════
registry-login:
desc: Login to GHCR
tags: [ci, registry]
silent: true
cmds:
- echo ${GHCR_TOKEN} | docker login ghcr.io -u ${ORG} --password-stdin
push-api:
desc: Push API image to registry
deps: [build-api, registry-login]
tags: [ci, push]
cmds:
- docker push ${IMAGE_API}:${TAG}
push-web:
desc: Push Web image to registry
deps: [build-web, registry-login]
tags: [ci, push]
cmds:
- docker push ${IMAGE_WEB}:${TAG}
push-worker:
desc: Push Worker image to registry
deps: [build-worker, registry-login]
tags: [ci, push]
cmds:
- docker push ${IMAGE_WORKER}:${TAG}
push-all:
desc: Push all images (parallel)
stage: push
deps: [push-api, push-web, push-worker]
parallel: true
tags: [ci, push]
cmds:
- echo "All images pushed to ${REGISTRY}"
# ═══════════════════════════════════════════════════
# DEPLOY — LOCAL (compose)
# ═══════════════════════════════════════════════════
dev:
desc: Start full local environment with hot-reload
env: [local]
tags: [dev]
cmds:
- ${COMPOSE} up -d --build
- echo ""
- "echo ' API: http://localhost:3000'"
- "echo ' Web: http://localhost:8080'"
- "echo ' Worker: running in background'"
- "echo ' Redis: localhost:6379'"
- "echo ' Postgres: localhost:5432'"
dev-stop:
desc: Stop local environment
env: [local]
tags: [dev]
cmds:
- ${COMPOSE} down
dev-logs:
desc: Tail local container logs
env: [local]
tags: [dev]
cmds:
- ${COMPOSE} logs -f --tail=200
# ═══════════════════════════════════════════════════
# DEPLOY — STAGING (compose via SSH)
# ═══════════════════════════════════════════════════
deploy-compose:
desc: Deploy to staging via docker compose over SSH
stage: deploy-staging
env: [staging]
deps: [push-all]
tags: [ci, deploy, staging]
retries: 2
retry_delay: 10
timeout: 300
cmds:
- "@fn notify Deploying to staging..."
- "@remote docker compose pull"
- "@remote docker compose up -d --remove-orphans"
- "@fn health-check"
- "@fn notify Staging deploy complete"
# ═══════════════════════════════════════════════════
# DEPLOY — PRODUCTION (Quadlet / Podman)
# ═══════════════════════════════════════════════════
quadlet-generate:
desc: Generate Quadlet .container files from docker-compose.yml
tags: [deploy, quadlet]
cmds:
- taskfile quadlet generate --compose docker-compose.yml --env-file .env.prod-eu -o deploy/quadlet
- echo "Generated Quadlet files:"
- ls -la deploy/quadlet/
quadlet-upload:
desc: Upload Quadlet files to remote host
env: [prod-eu, prod-us, prod-asia]
tags: [deploy, quadlet]
deps: [quadlet-generate]
cmds:
- taskfile quadlet upload
- "@remote systemctl --user daemon-reload"
deploy-quadlet:
desc: "Full production deploy: Quadlet generate → upload → pull → restart"
stage: deploy-prod
env: [prod-eu, prod-us, prod-asia]
deps: [push-all, quadlet-generate]
tags: [ci, deploy, prod]
retries: 2
retry_delay: 15
timeout: 600
cmds:
- "@fn notify Production deploy starting on ${DOMAIN}..."
- taskfile quadlet upload
- "@remote systemctl --user daemon-reload"
- "@remote podman pull ${IMAGE_API}:${TAG}"
- "@remote podman pull ${IMAGE_WEB}:${TAG}"
- "@remote podman pull ${IMAGE_WORKER}:${TAG}"
- "@remote systemctl --user restart ${APP_NAME}-api"
- "@remote systemctl --user restart ${APP_NAME}-web"
- "@remote systemctl --user restart ${APP_NAME}-worker"
- "@remote podman image prune -f"
- "@fn health-check"
- "@fn notify Production deploy complete on ${DOMAIN}"
- "@fn sentry-release"
deploy-quick:
desc: Quick prod deploy — pull + restart only (skip Quadlet regen)
env: [prod-eu, prod-us, prod-asia]
tags: [deploy, prod]
retries: 1
retry_delay: 10
cmds:
- "@remote podman pull ${IMAGE_API}:${TAG}"
- "@remote podman pull ${IMAGE_WEB}:${TAG}"
- "@remote podman pull ${IMAGE_WORKER}:${TAG}"
- "@remote systemctl --user restart ${APP_NAME}-api"
- "@remote systemctl --user restart ${APP_NAME}-web"
- "@remote systemctl --user restart ${APP_NAME}-worker"
- "@remote podman image prune -f"
deploy-service:
desc: Deploy single service (--var SVC=api|web|worker)
env: [prod-eu, prod-us, prod-asia]
tags: [deploy, prod]
cmds:
- "@remote podman pull ${REGISTRY}/mega-saas-${SVC}:${TAG}"
- "@remote systemctl --user restart ${APP_NAME}-${SVC}"
# ═══════════════════════════════════════════════════
# DEPLOY — EDGE CDN NODES
# ═══════════════════════════════════════════════════
deploy-edge:
desc: Deploy static assets to edge CDN nodes
env: [edge-cdn-eu, edge-cdn-us]
tags: [deploy, edge]
retries: 2
retry_delay: 5
cmds:
- "@remote mkdir -p /var/www/mega-saas/static"
- "@remote podman pull ${IMAGE_WEB}:${TAG}"
- "@remote podman cp mega-saas-web-tmp:/app/dist/static/ /var/www/mega-saas/static/"
- "@remote nginx -s reload"
# ═══════════════════════════════════════════════════
# ROLLBACK
# ═══════════════════════════════════════════════════
rollback:
desc: Rollback to previous version (--var TAG=<prev_tag>)
env: [prod-eu, prod-us, prod-asia]
tags: [deploy, rollback]
cmds:
- "@fn notify Rolling back ${DOMAIN} to ${TAG}..."
- "@remote podman pull ${IMAGE_API}:${TAG}"
- "@remote podman pull ${IMAGE_WEB}:${TAG}"
- "@remote podman pull ${IMAGE_WORKER}:${TAG}"
- "@remote systemctl --user restart ${APP_NAME}-api"
- "@remote systemctl --user restart ${APP_NAME}-web"
- "@remote systemctl --user restart ${APP_NAME}-worker"
- "@fn health-check"
- "@fn notify Rollback to ${TAG} complete on ${DOMAIN}"
# ═══════════════════════════════════════════════════
# RELEASE PIPELINE
# ═══════════════════════════════════════════════════
release:
desc: "Full release: bump version → build → push → deploy staging → manual prod"
deps: [lint, test-unit]
parallel: true
tags: [release]
cmds:
- taskfile version bump patch
- "@fn generate-manifest"
- echo "Release manifest generated — review and run deploy tasks"
release-major:
desc: Major version bump + full pipeline
deps: [lint, test-unit, test-integration]
parallel: true
tags: [release]
cmds:
- taskfile version bump major
- "@fn notify Major release started"
# ═══════════════════════════════════════════════════
# OPERATIONS & MONITORING
# ═══════════════════════════════════════════════════
status:
desc: Show service status on target environment
env: [local, staging, prod-eu, prod-us, prod-asia]
tags: [ops]
cmds:
- "@remote podman ps --format 'table {{.Names}}\\t{{.Status}}\\t{{.Ports}}'"
logs:
desc: Tail logs (--var SVC=api|web|worker)
env: [staging, prod-eu, prod-us, prod-asia]
tags: [ops]
cmds:
- "@remote journalctl --user -u ${APP_NAME}-${SVC:-api} -f --no-pager -n 200"
logs-local:
desc: Tail local docker compose logs
env: [local]
tags: [ops, dev]
cmds:
- ${COMPOSE} logs -f --tail=200 ${SVC:-}
health:
desc: Check application health endpoints
tags: [ops, health]
silent: true
retries: 3
retry_delay: 5
cmds:
- curl -sf https://${DOMAIN}/health && echo "API OK" || echo "API FAIL"
- curl -sf https://${DOMAIN}/api/v1/status && echo "Status OK" || echo "Status FAIL"
- "@fn check-port ${PORT:-3000}"
ram:
desc: Show memory usage on remote host
env: [staging, prod-eu, prod-us, prod-asia]
tags: [ops]
cmds:
- "@remote free -h"
- "@remote podman stats --no-stream --format 'table {{.Name}}\\t{{.MemUsage}}\\t{{.MemPerc}}'"
disk:
desc: Show disk usage on remote host
env: [staging, prod-eu, prod-us, prod-asia]
tags: [ops]
cmds:
- "@remote df -h / | tail -1"
- "@remote du -sh /var/lib/containers/ 2>/dev/null || true"
uptime-check:
desc: Check uptime of all production nodes
env: [prod-eu, prod-us, prod-asia]
tags: [ops]
silent: true
cmds:
- "@remote uptime"
- "@remote cat /proc/loadavg"
# ═══════════════════════════════════════════════════
# MAINTENANCE
# ═══════════════════════════════════════════════════
cleanup:
desc: Prune unused images, volumes, and logs on remote
env: [staging, prod-eu, prod-us, prod-asia]
tags: [ops, maintenance]
cmds:
- "@remote podman image prune -af"
- "@remote podman volume prune -f"
- "@remote sudo journalctl --vacuum-size=50M"
- echo "Cleanup complete"
update-os:
desc: Update OS packages on remote hosts
env: [prod-eu, prod-us, prod-asia]
tags: [maintenance]
timeout: 600
cmds:
- "@remote sudo apt-get update -qq"
- "@remote sudo apt-get upgrade -y -qq"
- "@remote sudo apt-get autoremove -y -qq"
reboot:
desc: Reboot remote host (use with caution)
env: [prod-eu, prod-us, prod-asia]
tags: [maintenance]
cmds:
- "@fn notify Rebooting ${DOMAIN}..."
- "@remote sudo reboot"
rotate-logs:
desc: Force log rotation on remote hosts
env: [staging, prod-eu, prod-us, prod-asia]
tags: [maintenance]
cmds:
- "@remote sudo logrotate -f /etc/logrotate.conf"
# ═══════════════════════════════════════════════════
# PROVISIONING — FIRST-TIME SERVER SETUP
# ═══════════════════════════════════════════════════
provision:
desc: First-time server provisioning (Podman + systemd + firewall)
env: [prod-eu, prod-us, prod-asia]
tags: [setup, provision]
timeout: 900
cmds:
- "@remote sudo apt-get update && sudo apt-get install -y podman podman-compose"
- "@remote sudo loginctl enable-linger deploy"
- "@remote mkdir -p ~/.config/containers/systemd"
- "@remote podman network create proxy 2>/dev/null || true"
- "@remote podman network create ${APP_NAME}-backend 2>/dev/null || true"
- "@remote sudo ufw allow 22/tcp comment 'SSH'"
- "@remote sudo ufw allow 80/tcp comment 'HTTP'"
- "@remote sudo ufw allow 443/tcp comment 'HTTPS'"
- "@remote sudo ufw --force enable"
- "@fn notify Server provisioned: ${DOMAIN}"
provision-edge:
desc: Provision edge CDN nodes (nginx + Podman)
env: [edge-cdn-eu, edge-cdn-us]
tags: [setup, provision, edge]
timeout: 600
cmds:
- "@remote sudo apt-get update && sudo apt-get install -y nginx podman"
- "@remote sudo loginctl enable-linger edge"
- "@remote mkdir -p /var/www/mega-saas/static"
- "@remote sudo ufw allow 80/tcp"
- "@remote sudo ufw allow 443/tcp"
# ═══════════════════════════════════════════════════
# DATABASE
# ═══════════════════════════════════════════════════
db-migrate:
desc: Run database migrations
tags: [db, deploy]
condition: "test -d migrations/"
cmds:
- alembic upgrade head
- "@python import datetime; print(f'Migration completed at {datetime.datetime.utcnow()}')"
db-seed:
desc: Seed database with initial data
tags: [db, setup]
condition: "test -f seeds/seed.sql"
cmds:
- psql ${DATABASE_URL} -f seeds/seed.sql
- echo "Database seeded"
db-backup:
desc: Backup production database
env: [prod-eu, prod-us, prod-asia]
tags: [db, ops, backup]
register: BACKUP_FILE
cmds:
- >-
@remote pg_dump -Fc ${DB_NAME}
> /tmp/${DB_NAME}_$(date +%Y%m%d_%H%M%S).dump
- echo "/tmp/${DB_NAME}_$(date +%Y%m%d_%H%M%S).dump"
db-restore:
desc: Restore database from backup (--var BACKUP_FILE=path)
env: [staging]
tags: [db, ops]
cmds:
- "@remote pg_restore -d ${DB_NAME} --clean --if-exists ${BACKUP_FILE}"
- echo "Database restored from ${BACKUP_FILE}"
# ═══════════════════════════════════════════════════
# STATIC ASSETS & CDN
# ═══════════════════════════════════════════════════
assets-build:
desc: Build and optimize static assets
tags: [build, assets]
platform: [web]
dir: services/web
cmds:
- npm run build
- npx imagemin dist/static/img/* --out-dir=dist/static/img/
assets-upload:
desc: Upload assets to S3
tags: [deploy, assets]
cmds:
- aws s3 sync dist/web/static/ s3://${S3_BUCKET}/static/ --delete --cache-control "max-age=31536000"
cdn-invalidate:
desc: Invalidate CloudFront CDN cache
tags: [deploy, cdn]
condition: "test -n \"${CDN_DISTRIBUTION}\""
cmds:
- >-
aws cloudfront create-invalidation
--distribution-id ${CDN_DISTRIBUTION}
--paths "/*"
# ═══════════════════════════════════════════════════
# CI HELPERS
# ═══════════════════════════════════════════════════
ci-generate:
desc: Generate CI configs for all platforms
tags: [ci]
cmds:
- taskfile ci generate --target github
- taskfile ci generate --target gitlab
- echo "CI configs generated in .github/ and .gitlab-ci.yml"
ci-run-local:
desc: Run full CI pipeline locally
tags: [ci]
cmds:
- taskfile ci run
ci-preview:
desc: Preview generated GitHub Actions YAML
tags: [ci]
cmds:
- taskfile ci preview --target github
# ═══════════════════════════════════════════════════
# SMOKE / POST-DEPLOY
# ═══════════════════════════════════════════════════
smoke-test:
desc: Post-deploy smoke test suite
stage: post-deploy
tags: [ci, test, smoke]
retries: 3
retry_delay: 10
timeout: 120
cmds:
- curl -sf https://${DOMAIN}/health || exit 1
- curl -sf https://${DOMAIN}/api/v1/status || exit 1
- "@fn check-port 443"
- "@fn health-check"
notify-release:
desc: Send release notification (Slack + Sentry)
stage: post-deploy
tags: [ci, notify]
cmds:
- "@fn notify Release ${TAG} deployed to ${DOMAIN}"
- "@fn sentry-release"
- "@fn generate-report"
# ═══════════════════════════════════════════════════
# META / INFO
# ═══════════════════════════════════════════════════
info:
desc: Show project info and current config
tags: [meta]
cmds:
- taskfile info build-api
- taskfile info deploy-quadlet
- taskfile list
validate:
desc: Validate this Taskfile
tags: [meta]
cmds:
- taskfile validate
manifest:
desc: Generate and display deployment manifest
tags: [meta]
cmds:
- "@fn generate-manifest"
version-show:
desc: Show current application version
tags: [meta]
register: CURRENT_VERSION
cmds:
- taskfile version show
dry-run-prod:
desc: Preview full production deploy without executing
tags: [meta]
cmds:
- taskfile --env prod-eu --dry-run run deploy-quadlet
clean:
desc: Remove all build artifacts and generated files
tags: [maintenance]
cmds:
- rm -rf dist/ coverage/ deploy/quadlet/ .next/
- docker rmi ${IMAGE_API}:${TAG} ${IMAGE_WEB}:${TAG} ${IMAGE_WORKER}:${TAG} 2>/dev/null || true
- echo "All artifacts cleaned"