-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJustfile
More file actions
676 lines (566 loc) Β· 24.2 KB
/
Justfile
File metadata and controls
676 lines (566 loc) Β· 24.2 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
# =============================================================================
# AstraDraw Development Commands
# =============================================================================
# Run `just` to see all available commands
#
# QUICK REFERENCE:
# just dev - Start everything with hot-reload
# just dev-stop - Stop everything
# just check - Run all code checks before commit
# just up - Start with Docker (production images)
# just up-local - Start with Docker (local builds)
# =============================================================================
# Default: show help
default:
@just --list
# =============================================================================
# DAILY DEVELOPMENT (most used commands)
# =============================================================================
# Use these for day-to-day development with hot-reload.
# Native services (frontend/backend/room) + Docker infrastructure.
# Start everything for development (infrastructure + native services with hot-reload)
dev:
#!/usr/bin/env bash
set -e
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β AstraDraw Development Mode β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Check if draw.local is in /etc/hosts
if ! grep -q "draw.local" /etc/hosts 2>/dev/null; then
echo "β οΈ WARNING: 'draw.local' is not in /etc/hosts!"
echo ""
echo " Add it with:"
echo " sudo sh -c 'echo \"127.0.0.1 draw.local\" >> /etc/hosts'"
echo ""
read -p " Press Enter to continue anyway, or Ctrl+C to abort..."
echo ""
fi
# Clean up any existing processes
echo "π§Ή Cleaning up existing processes..."
pkill -f "vite" 2>/dev/null || true
pkill -f "nest start" 2>/dev/null || true
pkill -f "ts-node-dev" 2>/dev/null || true
sleep 1
# Start infrastructure
echo ""
echo "π³ Starting Docker infrastructure..."
just _up-infra-oidc
# Wait for infrastructure
echo ""
echo "β³ Waiting for infrastructure to be ready..."
for i in {1..30}; do
if docker compose -f deploy/docker-compose.infra.yml ps 2>/dev/null | grep -q "healthy"; then
echo " β
Infrastructure is healthy"
break
fi
if [ $i -eq 30 ]; then
echo " β οΈ Timeout waiting for infrastructure (continuing anyway)"
fi
sleep 1
done
# Configure MinIO thumbnails
echo ""
echo "πΌοΈ Configuring MinIO thumbnails public access..."
just _configure-minio-thumbnails
# Generate frontend env
echo ""
echo "π Generating frontend env-config.js..."
just _generate-frontend-env
# Run migrations
echo ""
echo "ποΈ Running database migrations..."
cd backend && npx prisma migrate deploy 2>&1 | sed 's/^/ /' || echo " β οΈ Migration warning (may be OK if already applied)"
cd ..
# Start services
echo ""
echo "π Starting native services..."
echo ""
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β Service β Port β URL β"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€"
echo "β Frontend β 3000 β http://localhost:3000 β"
echo "β Backend β 8080 β http://localhost:8080 β"
echo "β Room β 3002 β http://localhost:3002 β"
echo "β Traefik β 443 β https://draw.local β"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
echo "π Access the app at: https://draw.local"
echo ""
echo "Press Ctrl+C to stop all services"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Start all services in background
just _dev-frontend &
FRONTEND_PID=$!
just _dev-backend &
BACKEND_PID=$!
just _dev-room &
ROOM_PID=$!
# Trap Ctrl+C
trap 'echo ""; echo "π Stopping services..."; kill $FRONTEND_PID $BACKEND_PID $ROOM_PID 2>/dev/null; just _down-infra; echo "β
All services stopped."; exit 0' INT TERM
wait
# Stop all development services
dev-stop:
#!/usr/bin/env bash
echo "π Stopping AstraDraw development environment..."
echo ""
echo "Stopping native services..."
if pgrep -f "vite" > /dev/null 2>&1; then
pkill -f "vite" && echo " β
Frontend stopped"
else
echo " βͺ Frontend was not running"
fi
if pgrep -f "nest start" > /dev/null 2>&1; then
pkill -f "nest start" && echo " β
Backend stopped"
else
echo " βͺ Backend was not running"
fi
if pgrep -f "ts-node-dev" > /dev/null 2>&1; then
pkill -f "ts-node-dev" && echo " β
Room service stopped"
else
echo " βͺ Room service was not running"
fi
echo ""
echo "Stopping Docker infrastructure..."
just _down-infra
echo ""
echo "β
All services stopped."
# Restart backend service only (useful after schema/module changes)
dev-restart-backend:
#!/usr/bin/env bash
echo "π Restarting backend service..."
if pgrep -f "nest start" > /dev/null 2>&1; then
pkill -f "nest start"
echo " β
Backend stopped"
fi
sleep 1
echo " π Starting backend..."
cd backend && npm run start:dev 2>&1 | sed 's/^/[backend] /' &
sleep 3
if curl -s http://localhost:8080/api/v2/auth/status > /dev/null 2>&1; then
echo " β
Backend restarted successfully"
else
echo " π‘ Backend starting... (may take a few seconds)"
fi
# Restart frontend service only
dev-restart-frontend:
#!/usr/bin/env bash
echo "π Restarting frontend service..."
if pgrep -f "vite" > /dev/null 2>&1; then
pkill -f "vite"
echo " β
Frontend stopped"
fi
sleep 1
echo " π Starting frontend..."
cd frontend && yarn start 2>&1 | sed 's/^/[frontend] /' &
sleep 3
if curl -s http://localhost:3000 > /dev/null 2>&1; then
echo " β
Frontend restarted successfully"
else
echo " π‘ Frontend starting... (may take a few seconds)"
fi
# Restart room service only
dev-restart-room:
#!/usr/bin/env bash
echo "π Restarting room service..."
if pgrep -f "ts-node-dev" > /dev/null 2>&1; then
pkill -f "ts-node-dev"
echo " β
Room service stopped"
fi
sleep 1
echo " π Starting room service..."
cd room-service && yarn start:dev 2>&1 | sed 's/^/[room] /' &
sleep 3
if curl -s http://localhost:3002 > /dev/null 2>&1; then
echo " β
Room service restarted successfully"
else
echo " π‘ Room service starting... (may take a few seconds)"
fi
# Check status of all services
dev-status:
#!/usr/bin/env bash
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β AstraDraw Service Status β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
echo "π³ Docker Infrastructure:"
echo "βββββββββββββββββββββββββ"
docker ps --filter "name=deploy" --format "table {{ "{{" }}.Names{{ "}}" }}\t{{ "{{" }}.Status{{ "}}" }}" 2>/dev/null | tail -n +2 | sed 's/^/ /' || echo " No containers running"
echo ""
echo "π» Native Services:"
echo "βββββββββββββββββββ"
if pgrep -f "vite" > /dev/null 2>&1; then
if curl -s http://localhost:3000 > /dev/null 2>&1; then
echo " β
Frontend: running on http://localhost:3000"
else
echo " π‘ Frontend: process running, port not responding"
fi
else
echo " β Frontend: not running"
fi
if pgrep -f "nest start" > /dev/null 2>&1; then
if curl -s http://localhost:8080/api/v2/auth/status > /dev/null 2>&1; then
echo " β
Backend: running on http://localhost:8080"
else
echo " π‘ Backend: process running, port not responding"
fi
else
echo " β Backend: not running"
fi
if pgrep -f "ts-node-dev" > /dev/null 2>&1; then
if curl -s http://localhost:3002 > /dev/null 2>&1; then
echo " β
Room: running on http://localhost:3002"
else
echo " π‘ Room: process running, port not responding"
fi
else
echo " β Room: not running"
fi
echo ""
echo "π Traefik Routing:"
echo "βββββββββββββββββββ"
if curl -sk https://draw.local > /dev/null 2>&1; then
echo " β
https://draw.local is accessible"
else
echo " β https://draw.local is not accessible"
fi
# =============================================================================
# CODE QUALITY (run before commits)
# =============================================================================
# Run all checks (frontend + backend + room)
check: check-frontend check-backend check-room
# Run frontend checks (TypeScript + Prettier + ESLint)
check-frontend:
cd frontend && yarn test:typecheck && yarn test:other && yarn test:code
# Run backend checks (Build + Prettier + ESLint)
check-backend:
cd backend && npm run build && npm run format && npm run lint
# Run room service checks
check-room:
cd room-service && yarn build && yarn test
# Fix all formatting issues
fix:
cd frontend && yarn fix
cd backend && npm run format
cd room-service && yarn fix
# =============================================================================
# DOCKER DEPLOYMENT
# =============================================================================
# Use these when you want to run everything in Docker containers.
# For daily development, use `just dev` instead (hot-reload, no Docker rebuilds).
# Start with production images (from GHCR)
up:
cd deploy && docker compose up -d
# Start with local builds (builds from ../frontend, ../backend)
up-local:
cd deploy && docker compose -f docker-compose.yml -f docker-compose.local.yml up -d --build
# Start with OIDC testing (Dex)
up-oidc:
cd deploy && docker compose --profile oidc up -d
# Start with admin tools (pgAdmin, MinIO Console)
up-admin:
cd deploy && docker compose --profile admin up -d
# Stop all Docker containers
down:
cd deploy && docker compose --profile oidc --profile admin down
# View logs (all services)
logs:
cd deploy && docker compose logs -f
# View API logs only
logs-api:
cd deploy && docker compose logs -f api
# View frontend logs only
logs-app:
cd deploy && docker compose logs -f app
# Restart all services
restart:
cd deploy && docker compose restart
# Fresh start with production images (removes all data)
fresh:
cd deploy && docker compose --profile oidc --profile admin down -v
docker volume rm astradraw_postgres_data astradraw_minio_data 2>/dev/null || true
cd deploy && docker compose up -d
# Fresh start with local builds (removes all data)
fresh-local:
cd deploy && docker compose --profile oidc --profile admin down -v
docker volume rm astradraw_postgres_data astradraw_minio_data 2>/dev/null || true
cd deploy && docker compose -f docker-compose.yml -f docker-compose.local.yml up -d --build
# Build local images without starting
build:
cd deploy && docker compose -f docker-compose.yml -f docker-compose.local.yml build
# Build without cache (use when changes aren't being picked up)
build-no-cache:
cd deploy && docker compose -f docker-compose.yml -f docker-compose.local.yml build --no-cache
# Pull latest production images
pull:
cd deploy && docker compose pull
# Clean up Docker resources (old images, build cache, etc.)
clean:
#!/usr/bin/env bash
set -e
echo "π§Ή Cleaning up Docker resources..."
echo ""
# Remove dangling images (untagged)
echo "Removing dangling images..."
docker image prune -f
# Remove unused build cache
echo ""
echo "Removing build cache..."
docker builder prune -f
echo ""
echo "β
Cleanup complete!"
echo ""
echo "π Current disk usage:"
docker system df
# Deep clean - removes ALL unused data (images, containers, volumes, networks)
clean-all:
#!/usr/bin/env bash
set -e
echo "π§Ή Deep cleaning Docker resources..."
echo "β οΈ This will remove ALL unused images, containers, volumes, and networks!"
echo ""
read -p "Are you sure? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
docker system prune -a --volumes -f
echo ""
echo "β
Deep cleanup complete!"
else
echo "Cancelled."
fi
# =============================================================================
# DATABASE
# =============================================================================
# Run Prisma migrations
db-migrate:
cd backend && npx prisma migrate deploy
# Generate Prisma client
db-generate:
cd backend && npx prisma generate
# Open Prisma Studio (database GUI)
db-studio:
cd backend && npx prisma studio
# Reset database (development only!)
db-reset:
cd backend && npx prisma migrate reset
# Seed database with test data (users, workspaces, teams, collections, scenes)
db-seed:
cd backend && npx prisma db seed
# Fresh development start with seed data (reset + seed + dev)
dev-fresh:
#!/usr/bin/env bash
set -e
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β AstraDraw Fresh Development Start β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Stop any running services
echo "π Stopping existing services..."
just dev-stop 2>/dev/null || true
# Start infrastructure (needed for database)
echo ""
echo "π³ Starting infrastructure..."
just _up-infra-oidc
# Wait for database
echo ""
echo "β³ Waiting for database..."
for i in {1..30}; do
if docker exec deploy-postgres-1 pg_isready -U excalidraw > /dev/null 2>&1; then
echo " β
Database is ready"
break
fi
if [ $i -eq 30 ]; then
echo " β Timeout waiting for database"
exit 1
fi
sleep 1
done
# Reset and seed database
echo ""
echo "ποΈ Resetting database..."
cd backend && npx prisma migrate reset --force --skip-seed
echo ""
echo "π± Seeding database with test data..."
cd backend && npx prisma db seed
echo ""
echo "β
Fresh database ready! Starting dev environment..."
echo ""
# Continue with normal dev startup
cd .. && just dev
# =============================================================================
# GIT
# =============================================================================
# Show git status for all repos
status:
@echo "=== Main Repo ===" && git status -s
@echo "\n=== Frontend ===" && cd frontend && git status -s
@echo "\n=== Backend ===" && cd backend && git status -s
@echo "\n=== Room Service ===" && cd room-service && git status -s
# Pull latest from all repos
pull-all:
git pull origin main
cd frontend && git pull origin main
cd backend && git pull origin main
cd room-service && git pull origin main
# =============================================================================
# SETUP (one-time)
# =============================================================================
# Initial setup for new developers
setup:
#!/usr/bin/env bash
set -e
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β AstraDraw Development Setup β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Step 1: Check /etc/hosts
echo "π Step 1: Checking /etc/hosts..."
if grep -q "draw.local" /etc/hosts 2>/dev/null; then
echo " β
draw.local is in /etc/hosts"
else
echo " β οΈ draw.local is NOT in /etc/hosts"
echo ""
echo " Please add it with:"
echo " sudo sh -c 'echo \"127.0.0.1 draw.local\" >> /etc/hosts'"
echo ""
read -p " Press Enter after adding, or Ctrl+C to abort..."
fi
echo ""
# Step 2: Clone repos
echo "π Step 2: Cloning repositories..."
test -d frontend || (echo " Cloning frontend..." && git clone https://github.com/AstraDraw/astradraw-app.git frontend)
test -d backend || (echo " Cloning backend..." && git clone https://github.com/AstraDraw/astradraw-api.git backend)
test -d room-service || (echo " Cloning room service..." && git clone https://github.com/AstraDraw/astradraw-room.git room-service)
echo " β
Repositories ready"
echo ""
# Step 3: Environment file
echo "π Step 3: Setting up environment..."
test -f deploy/.env || cp deploy/env.example deploy/.env
echo " β
deploy/.env ready"
echo ""
# Step 4: Secrets
echo "π Step 4: Generating secrets..."
mkdir -p deploy/secrets
test -f deploy/secrets/minio_access_key || echo "minioadmin" > deploy/secrets/minio_access_key
test -f deploy/secrets/minio_secret_key || openssl rand -base64 32 > deploy/secrets/minio_secret_key
echo " β
Secrets ready"
echo ""
# Step 5: SSL Certificate
echo "π Step 5: Generating SSL certificate..."
if [ ! -f deploy/certs/server.crt ]; then
just setup-certs
else
echo " β
Certificate already exists"
fi
echo ""
# Step 6: Install dependencies
echo "π Step 6: Installing dependencies..."
just install
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β Setup Complete! π β"
echo "β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£"
echo "β To start development: β"
echo "β just dev β"
echo "β β"
echo "β Then open: https://draw.local β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
# Generate self-signed SSL certificate for draw.local
setup-certs:
#!/usr/bin/env bash
set -e
echo "π Generating SSL certificate for draw.local..."
mkdir -p deploy/certs
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout deploy/certs/server.key \
-out deploy/certs/server.crt \
-subj "/CN=draw.local" \
-addext "subjectAltName=DNS:draw.local,DNS:localhost,IP:127.0.0.1"
echo "β
Certificate generated at deploy/certs/"
echo ""
echo "π Note: Your browser will show a security warning."
echo " Click 'Advanced' β 'Proceed to draw.local' to accept it."
# Install all dependencies
install:
cd frontend && yarn install
cd backend && npm install
cd room-service && yarn install
# =============================================================================
# TESTING
# =============================================================================
# Run backend API tests (requires running services)
test-api url="https://draw.local":
chmod +x deploy/tests/test-backend-api.sh
deploy/tests/test-backend-api.sh {{url}}
# Run interactive scene navigation test
test-navigation:
@cd deploy/tests && node test-scene-navigation.js
# Setup test data for collaboration testing
test-setup-collab url="https://draw.local":
chmod +x deploy/tests/setup-collab-test.sh
deploy/tests/setup-collab-test.sh {{url}}
# =============================================================================
# GIT PUSH COMMANDS
# =============================================================================
# Push all repositories (main, frontend, backend, room-service)
push-all:
#!/usr/bin/env bash
echo "π Pushing all repositories..."
echo ""
echo "=== Main Repo ===" && git push && echo ""
echo "=== Frontend ===" && cd frontend && git push && cd .. && echo ""
echo "=== Backend ===" && cd backend && git push && cd .. && echo ""
echo "=== Room Service ===" && cd room-service && git push && cd .. && echo ""
echo "β
All repositories pushed!"
# Push main repository only
push-main:
git push
# Push frontend repository only
push-frontend:
cd frontend && git push
# Push backend repository only
push-backend:
cd backend && git push
# Push room-service repository only
push-room:
cd room-service && git push
# =============================================================================
# RELEASE (use with caution)
# =============================================================================
# Tag and push frontend release
release-frontend version:
cd frontend && git tag v{{version}} && git push origin main --tags
# Tag and push backend release
release-backend version:
cd backend && git tag v{{version}} && git push origin main --tags
# Tag and push room service release
release-room version:
cd room-service && git tag v{{version}} && git push origin main --tags
# =============================================================================
# INTERNAL HELPERS (prefixed with _ to hide from list)
# =============================================================================
# Start frontend dev server
_dev-frontend:
cd frontend && yarn start 2>&1 | sed 's/^/[frontend] /'
# Start backend dev server
_dev-backend:
cd backend && rm -f tsconfig.build.tsbuildinfo && npm run start:dev 2>&1 | sed 's/^/[backend] /'
# Start room service dev server
_dev-room:
cd room-service && yarn start:dev 2>&1 | sed 's/^/[room] /'
# Start infrastructure only
_up-infra:
cd deploy && docker compose -f docker-compose.infra.yml up -d
# Start infrastructure with OIDC
_up-infra-oidc:
cd deploy && docker compose -f docker-compose.infra.yml --profile oidc up -d
# Stop infrastructure
_down-infra:
cd deploy && docker compose -f docker-compose.infra.yml --profile oidc --profile admin down
# Generate frontend env-config.js
_generate-frontend-env:
./deploy/generate-frontend-env.sh
# Configure MinIO thumbnails for public access
_configure-minio-thumbnails:
./deploy/configure-minio-thumbnails.sh