-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
753 lines (678 loc) Β· 37 KB
/
Makefile
File metadata and controls
753 lines (678 loc) Β· 37 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
# Makefile for eceee_v4
# Global help request check
HELP_REQUESTED := $(filter --help -h help,$(MAKECMDGOALS))
# Port validation helper
define check_port
@if [ -n "$(1)" ]; then \
if nc -z localhost $(1) 2>/dev/null; then \
echo "β Error: Port $(1) is already in use."; \
exit 1; \
fi \
fi
endef
# Help print helper
define print_help
@grep -E '^$(1):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36mUsage:\033[0m make %s %s\n", $$1, $$2}'
endef
# Help check helper
define check_help
@if [ -n "$(HELP_REQUESTED)" ]; then \
$(call print_help,$(1)); \
exit 0; \
fi
endef
.PHONY: help help-% install backend frontend playwright-service theme-sync migrate createsuperuser sample-content sample-pages sample-data sample-clean migrate-to-camelcase-dry migrate-to-camelcase migrate-schemas-only migrate-pagedata-only migrate-widgets-only migrate-widget-images-dry migrate-widget-images import-schemas import-schemas-dry import-schemas-force import-schema test lint docker-up docker-down infra-up infra-down infra-restart restart clean playwright-test playwright-down playwright-logs sync-from sync-to clear-layout-cache clear-layout-cache-all tailwind-build tailwind-watch create-api-token get-jwt-token list-api-tokens test-api-auth create-tenant list-tenants show-tenant activate-tenant deactivate-tenant tenant-themes delete-tenant --help -h check-servers check-conf check-db use-external-infra change-ports replicate-db list-dbs switch-db
# Dummy targets for help flags
--help:
@:
-h:
@:
# Default target - show help
.DEFAULT_GOAL := help
help-%: ## Show help for a specific target
$(call print_help,$*)
help: ## Show this help message (use: make help [target])
@if [ -n "$(filter-out help,$(MAKECMDGOALS))" ]; then \
for target in $(filter-out help,$(MAKECMDGOALS)); do \
grep -E "^$$target:.*?## " $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36mUsage for %s:\033[0m make %s %s\n", $$1, $$1, $$2}'; \
done; \
else \
echo "Available make targets:"; \
echo ""; \
echo "Development Environment:"; \
echo " install Install backend and frontend dependencies"; \
echo " servers Start database, Redis, MinIO, and ImgProxy services"; \
echo " backend Start Django backend server"; \
echo " frontend Start React frontend dev server"; \
echo " playwright-service Start Playwright website rendering service"; \
echo " theme-sync Start theme file sync service"; \
echo " shell Open bash shell in backend container"; \
echo " tailwind-build Build Tailwind CSS for backend templates"; \
echo " tailwind-watch Watch and rebuild Tailwind CSS on changes"; \
echo ""; \
echo "Database Management:"; \
echo " migrations Create Django migrations"; \
echo " migrate Run Django migrations"; \
echo " requirements Install backend requirements in container"; \
echo ""; \
echo "User Management:"; \
echo " createsuperuser Create Django superuser"; \
echo " changepassword Change admin password"; \
echo ""; \
echo "Tenant Management:"; \
echo " create-tenant NAME=\"Name\" IDENTIFIER=id Create a new tenant"; \
echo " list-tenants List all tenants"; \
echo " show-tenant ID=uuid|IDENTIFIER=id Show tenant details"; \
echo " activate-tenant ID=uuid|IDENTIFIER=id Activate a tenant"; \
echo " deactivate-tenant ID=uuid|IDENTIFIER=id Deactivate a tenant"; \
echo " tenant-themes ID=uuid|IDENTIFIER=id List themes for a tenant"; \
echo " delete-tenant ID=uuid|IDENTIFIER=id Delete a tenant (with confirmation)"; \
echo ""; \
echo "API Authentication:"; \
echo " create-api-token USER=username [SERVER=url] Create DRF token for user (long-lived)"; \
echo " get-jwt-token USER=username [SERVER=url] Get JWT token for user (expires in 60min)"; \
echo " list-api-tokens [SERVER=url] List all API tokens"; \
echo " test-api-auth TOKEN=token [SERVER=url] Test API token authentication"; \
echo " Note: SERVER defaults to http://localhost:8000"; \
echo ""; \
echo "Sample Data:"; \
echo " sample-content Create sample content (10 items)"; \
echo " sample-pages Create sample pages"; \
echo " sample-data Create both sample content and pages"; \
echo " sample-clean Clean and recreate sample data"; \
echo ""; \
echo "Data Migration:"; \
echo " migrate-to-camelcase-dry Dry run camelCase migration"; \
echo " migrate-to-camelcase Run camelCase migration with backup"; \
echo " migrate-schemas-only Migrate schemas only"; \
echo " migrate-pagedata-only Migrate page data only"; \
echo " migrate-widgets-only Migrate widgets only"; \
echo " migrate-widget-images-dry Dry run widget image migration (preview)"; \
echo " migrate-widget-images Migrate widget images to full MediaFile objects"; \
echo ""; \
echo "Object Type Schemas:"; \
echo " import-schemas Import all JSON schemas to ObjectTypes"; \
echo " import-schemas-dry Preview schema import (dry run)"; \
echo " import-schemas-force Import/update schemas without prompts"; \
echo " import-schema FILE=x NAME=y Import single schema file"; \
echo ""; \
echo "Testing & Quality:"; \
echo " backend-test Run backend tests"; \
echo " playwright-test Test Playwright service endpoints"; \
echo " lint Lint frontend code"; \
echo ""; \
echo "Docker Management:"; \
echo " docker-up Start all services with Docker Compose"; \
echo " docker-down Stop all Docker Compose services"; \
echo " restart Restart all Docker Compose services"; \
echo " playwright-down Stop Playwright service"; \
echo " playwright-logs View Playwright service logs"; \
echo " clean Clean Python, Node, and Docker artifacts"; \
echo ""; \
echo "ECEEE Components Sync:"; \
echo " sync-to Sync components FROM eceee_v4 TO eceee-components"; \
echo ""; \
echo "Environment & Health Checks:"; \
echo " infra-up Run infrastructure services"; \
echo " infra-down Stop infrastructure services"; \
echo " infra-restart Restart infrastructure services"; \
echo " clear-layout-cache Clear layout-related caches to force refresh"; \
echo " clear-layout-cache-all Clear ALL caches (nuclear option)"; \
echo " check-servers Check if backend and frontend servers are up"; \
echo " check-conf Check database and server configuration"; \
echo " use-external-infra Setup .env to use shared infrastructure"; \
echo " change-ports Change backend and frontend ports"; \
echo " list-dbs List all database clones"; \
echo " switch-db DB=name Switch current database in .env"; \
echo " replicate-db Clone current DB to branch-specific DB"; \
echo ""; \
echo "Usage:"; \
echo " make <target> Run a specific target"; \
echo " make help <target> Show help for a specific target"; \
echo " make help-<target> Show help for a specific target"; \
fi
# Install backend and frontend dependencies
install:
cd backend && pip install -r requirements.txt
cd frontend && npm install
servers: infra-up
# Run Django backend server
backend:
@BP=$$(grep "^BACKEND_PORT=" .env | cut -d= -f2 || echo "8000"); \
echo "π Starting Backend on http://localhost:$$BP (internal: 8000)"; \
docker-compose -f docker-compose.dev.yml up backend
# Run React frontend dev server
frontend:
@FP=$$(grep "^FRONTEND_PORT=" .env | cut -d= -f2 || echo "3000"); \
echo "π Starting Frontend on http://localhost:$$FP (internal: 3000)"; \
docker-compose -f docker-compose.dev.yml up frontend
# Run Playwright website rendering service
playwright-service:
cd playwright-service && docker-compose up -d
# Run theme sync service
theme-sync:
docker-compose -f docker-compose.dev.yml up theme-sync
# Run Django migrations
migrations:
docker-compose -f docker-compose.dev.yml exec backend python manage.py makemigrations
migrate:
docker-compose -f docker-compose.dev.yml exec backend python manage.py migrate
requirements:
docker-compose -f docker-compose.dev.yml exec backend pip install -r requirements.txt
# Create Django superuser
createsuperuser:
docker-compose -f docker-compose.dev.yml exec backend python manage.py createsuperuser
changepassword:
docker-compose -f docker-compose.dev.yml exec backend python manage.py changepassword admin
# API Token Management
SERVER ?= http://localhost:8000
create-api-token: ## Create DRF token for user (use: make create-api-token USER=username [SERVER=url])
$(call check_help,create-api-token)
@if [ -z "$(USER)" ]; then \
echo "β Error: USER is required"; \
$(call print_help,create-api-token); \
exit 1; \
fi
@if echo "$(SERVER)" | grep -q "^http://localhost\|^http://127.0.0.1"; then \
echo "Creating DRF token for user: $(USER) on local server"; \
echo ""; \
TOKEN=$$(docker-compose -f docker-compose.dev.yml exec -T backend python manage.py drf_create_token $(USER) 2>/dev/null | grep -o '[a-f0-9]\{40\}' | head -1 || \
docker-compose -f docker-compose.dev.yml exec backend python manage.py drf_create_token $(USER) 2>/dev/null | grep -o '[a-f0-9]\{40\}' | head -1); \
if [ -n "$$TOKEN" ]; then \
echo ""; \
echo "β Token created successfully!"; \
echo ""; \
echo "Token: $$TOKEN"; \
echo ""; \
echo "To use this token, add it to docker-compose.dev.yml:"; \
echo " theme-sync:"; \
echo " environment:"; \
echo " - API_TOKEN=$$TOKEN"; \
echo ""; \
echo "Or test it with:"; \
echo " make test-api-auth TOKEN=$$TOKEN"; \
echo ""; \
else \
echo "Error: Failed to create or extract token"; \
exit 1; \
fi \
else \
echo "Error: DRF tokens can only be created on local server via Docker"; \
echo "For production, use: make get-jwt-token USER=$(USER) SERVER=$(SERVER)"; \
exit 1; \
fi
get-jwt-token: ## Get JWT token for user (use: make get-jwt-token USER=username [SERVER=url])
$(call check_help,get-jwt-token)
@if [ -z "$(USER)" ]; then \
echo "β Error: USER is required"; \
$(call print_help,get-jwt-token); \
exit 1; \
fi
@if [ -z "$(PASSWORD)" ]; then \
echo "Getting JWT token for user: $(USER) from $(SERVER)"; \
echo "Enter password:"; \
read -s PASSWORD; \
fi
@echo "Requesting JWT token from $(SERVER)..."
@curl -s -X POST $(SERVER)/api/auth/token/ \
-H "Content-Type: application/json" \
-d "{\"username\": \"$(USER)\", \"password\": \"$(PASSWORD)\"}" | \
python3 -m json.tool || \
(echo "Error: Failed to get token. Check username/password and ensure server is accessible." && exit 1)
list-api-tokens: ## List all API tokens (use: make list-api-tokens [SERVER=url])
@if echo "$(SERVER)" | grep -q "^http://localhost\|^http://127.0.0.1"; then \
echo "Listing all API tokens from local server..."; \
docker-compose -f docker-compose.dev.yml exec -T backend python manage.py shell -c "from rest_framework.authtoken.models import Token; from django.contrib.auth.models import User; print('\nAPI Tokens:'); print('=' * 80); [print(f'{user.username:20} | {Token.objects.get_or_create(user=user)[0].key:40} | EXISTS') for user in User.objects.all().order_by('username')]; print('=' * 80); print(f'\nTotal users: {User.objects.count()}')" || \
docker-compose -f docker-compose.dev.yml exec backend python manage.py shell -c "from rest_framework.authtoken.models import Token; from django.contrib.auth.models import User; print('\nAPI Tokens:'); print('=' * 80); [print(f'{user.username:20} | {Token.objects.get_or_create(user=user)[0].key:40} | EXISTS') for user in User.objects.all().order_by('username')]; print('=' * 80); print(f'\nTotal users: {User.objects.count()}')"; \
else \
echo "Error: Token listing only available on local server via Docker"; \
echo "For production, tokens must be managed through Django admin or API"; \
exit 1; \
fi
create-tenant: ## Create a new tenant (use: make create-tenant NAME="Tenant Name" IDENTIFIER=tenant_id)
$(call check_help,create-tenant)
@if [ -z "$(NAME)" ] || [ -z "$(IDENTIFIER)" ]; then \
echo "β Error: NAME and IDENTIFIER are required"; \
$(call print_help,create-tenant); \
exit 1; \
fi
@echo "Creating tenant: $(NAME) with identifier: $(IDENTIFIER)"
@docker-compose -f docker-compose.dev.yml exec backend python manage.py create_tenant --name "$(NAME)" --identifier "$(IDENTIFIER)" || \
(echo "Error: Failed to create tenant." && exit 1)
list-tenants: ## List all tenants
@echo "Listing all tenants..."
@docker-compose -f docker-compose.dev.yml exec -T backend python manage.py shell -c "from core.models import Tenant; tenants = Tenant.objects.all().order_by('name'); print('\nTenants:'); print('=' * 100); print('UUID | Name | Identifier | Status'); print('-' * 100); [print(f'{str(t.id):36} | {t.name:30} | {t.identifier:20} | {\"Active\" if t.is_active else \"Inactive\"}') for t in tenants]; print('=' * 100); print(f'\nTotal tenants: {Tenant.objects.count()}')" || (echo "Error: Failed to list tenants." && exit 1)
show-tenant: ## Show tenant details (use: make show-tenant ID=uuid or IDENTIFIER=identifier)
$(call check_help,show-tenant)
@if [ -z "$(ID)" ] && [ -z "$(IDENTIFIER)" ]; then \
echo "β Error: ID or IDENTIFIER is required"; \
$(call print_help,show-tenant); \
exit 1; \
fi
@docker-compose -f docker-compose.dev.yml exec -T backend python manage.py shell -c "from core.models import Tenant; import json; import uuid; tenant = Tenant.objects.get(id=uuid.UUID('$(ID)')) if '$(ID)' else Tenant.objects.get(identifier='$(IDENTIFIER)'); print(f'\nTenant Details:'); print('=' * 80); print(f'ID: {tenant.id}'); print(f'Name: {tenant.name}'); print(f'Identifier: {tenant.identifier}'); print(f'Active: {tenant.is_active}'); print(f'Created: {tenant.created_at}'); print(f'Updated: {tenant.updated_at}'); print(f'Created by: {tenant.created_by.username if tenant.created_by else \"N/A\"}'); print(f'\nSettings:'); print(json.dumps(tenant.settings, indent=2) if tenant.settings else ' (empty)'); print(f'\nThemes: {tenant.themes.count()}'); [print(f' - {theme.name} (v{theme.sync_version})') for theme in tenant.themes.all()[:10]]; print(f' ... and {tenant.themes.count() - 10} more' if tenant.themes.count() > 10 else ''); print('=' * 80)" || (echo "Error: Failed to show tenant." && exit 1)
activate-tenant: ## Activate a tenant (use: make activate-tenant ID=uuid or IDENTIFIER=identifier)
$(call check_help,activate-tenant)
@if [ -z "$(ID)" ] && [ -z "$(IDENTIFIER)" ]; then \
echo "β Error: ID or IDENTIFIER is required"; \
$(call print_help,activate-tenant); \
exit 1; \
fi
@docker-compose -f docker-compose.dev.yml exec -T backend python manage.py shell -c "from core.models import Tenant; import uuid; tenant = Tenant.objects.get(id=uuid.UUID('$(ID)')) if '$(ID)' else Tenant.objects.get(identifier='$(IDENTIFIER)'); tenant.is_active = True; tenant.save(); print(f'β Tenant \"{tenant.name}\" (identifier: {tenant.identifier}) activated')" || (echo "Error: Failed to activate tenant." && exit 1)
deactivate-tenant: ## Deactivate a tenant (use: make deactivate-tenant ID=uuid or IDENTIFIER=identifier)
$(call check_help,deactivate-tenant)
@if [ -z "$(ID)" ] && [ -z "$(IDENTIFIER)" ]; then \
echo "β Error: ID or IDENTIFIER is required"; \
$(call print_help,deactivate-tenant); \
exit 1; \
fi
@docker-compose -f docker-compose.dev.yml exec -T backend python manage.py shell -c "from core.models import Tenant; import uuid; tenant = Tenant.objects.get(id=uuid.UUID('$(ID)')) if '$(ID)' else Tenant.objects.get(identifier='$(IDENTIFIER)'); tenant.is_active = False; tenant.save(); print(f'β Tenant \"{tenant.name}\" (identifier: {tenant.identifier}) deactivated')" || (echo "Error: Failed to deactivate tenant." && exit 1)
tenant-themes: ## List themes for a tenant (use: make tenant-themes ID=uuid or IDENTIFIER=identifier)
$(call check_help,tenant-themes)
@if [ -z "$(ID)" ] && [ -z "$(IDENTIFIER)" ]; then \
echo "β Error: ID or IDENTIFIER is required"; \
$(call print_help,tenant-themes); \
exit 1; \
fi
@docker-compose -f docker-compose.dev.yml exec -T backend python manage.py shell -c "from core.models import Tenant; import uuid; tenant = Tenant.objects.get(id=uuid.UUID('$(ID)')) if '$(ID)' else Tenant.objects.get(identifier='$(IDENTIFIER)'); print(f'\nThemes for tenant: {tenant.name} (identifier: {tenant.identifier})'); print('=' * 80); themes = tenant.themes.all().order_by('name'); [print(f'{t.id:5} | {t.name:30} | v{t.sync_version:5} | {\"Active\" if t.is_active else \"Inactive\"}{\" (Default)\" if t.is_default else \"\"}') for t in themes] if themes.exists() else print(' (no themes)'); print('=' * 80); print(f'\nTotal themes: {themes.count()}')" || (echo "Error: Failed to list tenant themes." && exit 1)
delete-tenant: ## Delete a tenant (use: make delete-tenant ID=uuid or IDENTIFIER=identifier [FORCE=yes])
$(call check_help,delete-tenant)
@if [ -z "$(ID)" ] && [ -z "$(IDENTIFIER)" ]; then \
echo "β Error: ID or IDENTIFIER is required"; \
$(call print_help,delete-tenant); \
exit 1; \
fi
@if [ "$(FORCE)" != "yes" ]; then \
echo "WARNING: This will delete the tenant and all associated themes!"; \
echo "Press Ctrl+C to cancel, or Enter to continue..."; \
read confirm; \
fi
@docker-compose -f docker-compose.dev.yml exec -T backend python manage.py shell -c "from core.models import Tenant; import uuid; tenant = Tenant.objects.get(id=uuid.UUID('$(ID)')) if '$(ID)' else Tenant.objects.get(identifier='$(IDENTIFIER)'); theme_count = tenant.themes.count(); tenant_name = tenant.name; tenant_identifier = tenant.identifier; tenant.delete(); print(f'β Tenant \"{tenant_name}\" (identifier: {tenant_identifier}) deleted'); print(f' Deleted {theme_count} associated theme(s)')" || (echo "Error: Failed to delete tenant." && exit 1)
test-api-auth: ## Test API token authentication (use: make test-api-auth TOKEN=token [SERVER=url])
$(call check_help,test-api-auth)
@if [ -z "$(TOKEN)" ]; then \
echo "β Error: TOKEN is required"; \
$(call print_help,test-api-auth); \
exit 1; \
fi
@echo "Testing API authentication on $(SERVER)..."
@if echo "$(TOKEN)" | grep -q "^eyJ"; then \
AUTH_HEADER="Bearer $(TOKEN)"; \
else \
AUTH_HEADER="Token $(TOKEN)"; \
echo "Detected DRF token, using Token authentication..."; \
fi
@RESPONSE=$$(curl -s -w "\nHTTP_CODE:%{http_code}" -X GET $(SERVER)/api/v1/webpages/themes/sync/status/ \
-H "Authorization: $$AUTH_HEADER" -H "Content-Type: application/json"); \
HTTP_CODE=$$(echo "$$RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2); \
BODY=$$(echo "$$RESPONSE" | sed '/HTTP_CODE:/d'); \
if [ "$$HTTP_CODE" = "200" ]; then \
echo "β Authentication successful!"; \
echo "$$BODY" | python3 -m json.tool 2>/dev/null || echo "$$BODY"; \
elif [ "$$HTTP_CODE" = "403" ]; then \
if echo "$$BODY" | grep -q "THEME_SYNC_ENABLED"; then \
echo "β Error: Theme sync is disabled on server"; \
echo "Set THEME_SYNC_ENABLED=True in backend environment"; \
else \
echo "β Error: Access forbidden (403)"; \
echo "Response: $$BODY" | head -5; \
fi; \
exit 1; \
elif [ "$$HTTP_CODE" = "401" ]; then \
echo "β Error: Authentication failed (401)"; \
echo "Token is invalid or expired"; \
exit 1; \
elif [ "$$HTTP_CODE" = "404" ]; then \
echo "β Error: Endpoint not found (404)"; \
echo "Check that the server URL is correct: $(SERVER)"; \
exit 1; \
else \
echo "β Error: Unexpected response (HTTP $$HTTP_CODE)"; \
echo "Response: $$BODY" | head -10; \
exit 1; \
fi
# Create sample data
sample-content:
docker-compose -f docker-compose.dev.yml exec backend python manage.py create_sample_content --count 10 --verbose
sample-pages:
docker-compose -f docker-compose.dev.yml exec backend python manage.py create_sample_pages --verbose
sample-data: sample-content sample-pages
sample-clean:
docker-compose -f docker-compose.dev.yml exec backend python manage.py create_sample_content --clean --count 10 --verbose
docker-compose -f docker-compose.dev.yml exec backend python manage.py create_sample_pages --clear --verbose
# Migration commands for camelCase conversion
migrate-to-camelcase-dry:
docker-compose -f docker-compose.dev.yml exec backend python manage.py migrate_to_camelcase --dry-run --backup
migrate-to-camelcase:
docker-compose -f docker-compose.dev.yml exec backend python manage.py migrate_to_camelcase --backup
migrate-schemas-only:
docker-compose -f docker-compose.dev.yml exec backend python manage.py migrate_to_camelcase --schemas-only --backup
migrate-pagedata-only:
docker-compose -f docker-compose.dev.yml exec backend python manage.py migrate_to_camelcase --pagedata-only --backup
migrate-widgets-only:
docker-compose -f docker-compose.dev.yml exec backend python manage.py migrate_to_camelcase --widgets-only --backup
# Widget Image Migration
migrate-widget-images-dry:
docker-compose -f docker-compose.dev.yml exec backend python manage.py migrate_widget_images --dry-run --verbose
migrate-widget-images:
docker-compose -f docker-compose.dev.yml exec backend python manage.py migrate_widget_images --backup
# Object Type Schema Management
import-schemas: ## Import all JSON schemas to ObjectTypeDefinitions
docker-compose -f docker-compose.dev.yml exec backend python manage.py import_schemas
import-schemas-dry: ## Preview schema import without saving (dry run)
docker-compose -f docker-compose.dev.yml exec backend python manage.py import_schemas --dry-run
import-schemas-force: ## Import/update all schemas without confirmation prompts
docker-compose -f docker-compose.dev.yml exec backend python manage.py import_schemas --force
import-schema: ## Import single schema file (use: make import-schema FILE=news.json NAME=news)
$(call check_help,import-schema)
@if [ -z "$(FILE)" ] || [ -z "$(NAME)" ]; then \
echo "β Error: Both FILE and NAME are required"; \
$(call print_help,import-schema); \
exit 1; \
fi
docker-compose -f docker-compose.dev.yml exec backend python manage.py import_schemas \
--file scripts/migration/schemas/$(FILE) \
--name $(NAME)
shell:
docker-compose -f docker-compose.dev.yml exec backend bash
# Run backend tests
backend-test:
docker-compose -f docker-compose.dev.yml exec backend python manage.py test
# Test Playwright service endpoints
playwright-test:
cd playwright-service && python test_service.py
# Lint frontend code
lint:
cd frontend && npm run lint
# Start all services with Docker Compose
docker-up: infra-up
docker-compose -f docker-compose.dev.yml up --build
# Stop all Docker Compose services
docker-down:
docker-compose -f docker-compose.dev.yml down
docker-compose -f docker-compose.infra.yml down
# Restart all Docker Compose services
restart:
docker-compose -f docker-compose.dev.yml restart
docker-compose -f docker-compose.infra.yml restart
# Stop Playwright service
playwright-down:
cd playwright-service && docker-compose down
# View Playwright service logs
playwright-logs:
cd playwright-service && docker-compose logs -f
# Clean Python, Node, and Docker artifacts
clean:
find backend -type d -name '__pycache__' -exec rm -rf {} +
rm -rf backend/*.pyc backend/*.pyo backend/.pytest_cache
rm -rf frontend/node_modules frontend/dist
docker-compose -f docker-compose.dev.yml down -v
docker-compose -f docker-compose.infra.yml down -v
cd playwright-service && docker-compose down -v
# ECEEE Components Sync Commands
#sync-from: ## Sync components FROM eceee-components TO eceee_v4
# @echo "π Syncing components FROM eceee-components TO eceee_v4..."
# @./sync-from-eceee-components.sh
# sync-to: ## Sync components FROM eceee_v4 TO eceee-components
# @echo "π Syncing components FROM eceee_v4 TO eceee-components..."
# @./sync-to-eceee-components.sh
# Environment & Health Checks
infra-up: ## Run infrastructure services
docker-compose -f docker-compose.infra.yml up -d
infra-down: ## Stop infrastructure services
docker-compose -f docker-compose.infra.yml down
infra-restart: ## Restart infrastructure services
docker-compose -f docker-compose.infra.yml restart
clear-layout-cache: ## Clear layout-related caches to force refresh
@echo "π§Ή Clearing layout caches..."
docker-compose -f docker-compose.dev.yml exec backend python manage.py clear_layout_cache
clear-layout-cache-all: ## Clear all caches (nuclear option)
@echo "π§Ή Clearing ALL caches..."
docker-compose -f docker-compose.dev.yml exec backend python manage.py clear_layout_cache --all
check-servers: ## Check if backend and frontend servers are up
@echo "π Checking status of services..."
@echo ""
@# Load ports from .env if it exists
@BP=$$(grep "^BACKEND_PORT=" .env | cut -d= -f2 || echo "8000"); \
FP=$$(grep "^FRONTEND_PORT=" .env | cut -d= -f2 || echo "3000"); \
check_http() { \
name=$$1; url=$$2; \
status=$$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 2 $$url 2>/dev/null); \
if [ "$$status" = "200" ]; then \
printf "%-25s [\033[0;32mUP\033[0m] at $$url\n" "$$name"; \
elif [ "$$status" = "000" ] || [ -z "$$status" ]; then \
printf "%-25s [\033[0;33mNOT STARTED\033[0m] at $$url\n" "$$name"; \
else \
printf "%-25s [\033[0;31mBROKEN (HTTP $$status)\033[0m] at $$url\n" "$$name"; \
fi; \
}; \
echo "--- Local Apps (this repo) ---"; \
check_http "Backend (Django)" "http://localhost:$$BP/health/"; \
check_http "Frontend (Vite)" "http://localhost:$$FP/"; \
echo ""; \
echo "--- External Infra (main repo) ---"; \
status=$$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 2 http://localhost:9000/minio/health/live 2>/dev/null); \
if [ "$$status" = "200" ]; then printf "%-25s [\033[0;32mUP\033[0m]\n" "MinIO"; else printf "%-25s [\033[0;33mOFFLINE\033[0m]\n" "MinIO"; fi; \
status=$$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 2 http://localhost:8080/health 2>/dev/null); \
if [ "$$status" = "200" ]; then printf "%-25s [\033[0;32mUP\033[0m]\n" "ImgProxy"; else printf "%-25s [\033[0;33mOFFLINE\033[0m]\n" "ImgProxy"; fi; \
if nc -z localhost 6379 2>/dev/null; then printf "%-25s [\033[0;32mUP\033[0m]\n" "Redis"; else printf "%-25s [\033[0;33mOFFLINE\033[0m]\n" "Redis"; fi; \
if nc -z localhost 5432 2>/dev/null; then printf "%-25s [\033[0;32mUP\033[0m]\n" "Postgres"; else printf "%-25s [\033[0;33mOFFLINE\033[0m]\n" "Postgres"; fi; \
echo ""
use-external-infra: ## Update .env to use the shared infrastructure from the other repo (use: make use-external-infra [BP=8001] [FP=3001])
$(call check_help,use-external-infra)
@echo "π Preparing .env file..."
@if [ ! -f .env ]; then \
if [ -f .env.template ]; then \
cp .env.template .env; \
echo "β
Created .env from .env.template"; \
else \
echo "POSTGRES_DB=eceee_v4" > .env; \
echo "POSTGRES_HOST=db" >> .env; \
echo "DATABASE_URL=postgresql://postgres:postgres@db:5432/eceee_v4" >> .env; \
echo "REDIS_URL=redis://redis:6379/0" >> .env; \
echo "β
Created minimal .env"; \
fi \
fi
@# Validate requested ports if provided
$(call check_port,$(BP))
$(call check_port,$(FP))
@echo "π Configuring unique project name and ports for this instance..."
@BP_VAL=$${BP:-8001}; \
FP_VAL=$${FP:-3001}; \
if ! grep -q "COMPOSE_PROJECT_NAME" .env; then \
DIR_NAME=$$(basename $$(pwd) | tr '[:upper:]' '[:lower:]' | tr '_' '-'); \
echo "\n# Multi-instance Configuration" >> .env; \
echo "COMPOSE_PROJECT_NAME=eceee-v4-$$DIR_NAME" >> .env; \
echo "BACKEND_PORT=$$BP_VAL" >> .env; \
echo "FRONTEND_PORT=$$FP_VAL" >> .env; \
else \
if [ -n "$(BP)" ]; then sed -i '' "s/^BACKEND_PORT=.*/BACKEND_PORT=$(BP)/" .env 2>/dev/null || sed -i "s/^BACKEND_PORT=.*/BACKEND_PORT=$(BP)/" .env; fi; \
if [ -n "$(FP)" ]; then sed -i '' "s/^FRONTEND_PORT=.*/FRONTEND_PORT=$(FP)/" .env 2>/dev/null || sed -i "s/^FRONTEND_PORT=.*/FRONTEND_PORT=$(FP)/" .env; fi; \
fi
@BP_OLD=$$(grep "^BACKEND_PORT=" .env | cut -d= -f2 || echo "8000"); \
FP_OLD=$$(grep "^FRONTEND_PORT=" .env | cut -d= -f2 || echo "3000"); \
BP_NEW=$${BP:-$$BP_OLD}; \
FP_NEW=$${FP:-$$FP_OLD}; \
if [ "$$BP_NEW" != "$$BP_OLD" ]; then \
echo "π Updating Backend port: $$BP_OLD -> $$BP_NEW"; \
if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' "s/^BACKEND_PORT=.*/BACKEND_PORT=$$BP_NEW/" .env; \
sed -i '' "s/:$$BP_OLD/:$$BP_NEW/g" .env; \
else \
sed -i "s/^BACKEND_PORT=.*/BACKEND_PORT=$$BP_NEW/" .env; \
sed -i "s/:$$BP_OLD/:$$BP_NEW/g" .env; \
fi \
fi; \
if [ "$$FP_NEW" != "$$FP_OLD" ]; then \
echo "π Updating Frontend port: $$FP_OLD -> $$FP_NEW"; \
if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' "s/^FRONTEND_PORT=.*/FRONTEND_PORT=$$FP_NEW/" .env; \
sed -i '' "s/:$$FP_OLD/:$$FP_NEW/g" .env; \
else \
sed -i "s/^FRONTEND_PORT=.*/FRONTEND_PORT=$$FP_NEW/" .env; \
sed -i "s/:$$FP_OLD/:$$FP_NEW/g" .env; \
fi \
fi
@echo "π Updating .env to use hyphenated shared infrastructure names..."
@if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' 's/^POSTGRES_HOST=db/POSTGRES_HOST=eceee-v4-db/' .env; \
sed -i '' 's/@db:5432/@eceee-v4-db:5432/' .env; \
sed -i '' 's/^REDIS_URL=redis:\/\/redis:6379/REDIS_URL=redis:\/\/eceee-v4-redis:6379/' .env; \
sed -i '' 's/eceee_v4_minio/eceee-v4-minio/g' .env; \
sed -i '' 's/eceee_v4_db/eceee-v4-db/g' .env; \
sed -i '' 's/eceee_v4_redis/eceee-v4-redis/g' .env; \
sed -i '' 's/eceee_v4_imgproxy/eceee-v4-imgproxy/g' .env; \
sed -i '' 's/AWS_S3_ENDPOINT_URL=http:\/\/minio:9000/AWS_S3_ENDPOINT_URL=http:\/\/eceee-v4-minio:9000/' .env; \
else \
sed -i 's/^POSTGRES_HOST=db/POSTGRES_HOST=eceee-v4-db/' .env; \
sed -i 's/@db:5432/@eceee-v4-db:5432/' .env; \
sed -i 's/^REDIS_URL=redis:\/\/redis:6379/REDIS_URL=redis:\/\/eceee-v4-redis:6379/' .env; \
sed -i 's/eceee_v4_minio/eceee-v4-minio/g' .env; \
sed -i 's/eceee_v4_db/eceee-v4-db/g' .env; \
sed -i 's/eceee_v4_redis/eceee-v4-redis/g' .env; \
sed -i 's/eceee_v4_imgproxy/eceee-v4-imgproxy/g' .env; \
sed -i 's/AWS_S3_ENDPOINT_URL=http:\/\/minio:9000/AWS_S3_ENDPOINT_URL=http:\/\/eceee-v4-minio:9000/' .env; \
fi
@# Check if summerstudy is in /etc/hosts and update if so
@if grep -q "summerstudy" /etc/hosts; then \
echo "π Detected 'summerstudy' in hosts, ensuring URLs use it..."; \
if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' 's/localhost:/summerstudy:/g' .env; \
else \
sed -i 's/localhost:/summerstudy:/g' .env; \
fi \
fi
@echo "β
.env updated. Checking configuration..."
@make check-conf
@echo "π Normalizing database hostnames (stripping ports)..."
@docker-compose -f docker-compose.dev.yml exec -T backend python manage.py shell -c "from webpages.models import WebPage; [p.save() for p in WebPage.objects.filter(parent__isnull=True)]"
change-ports: ## Change backend and frontend ports (use: make change-ports BP=8002 FP=3002)
$(call check_help,change-ports)
@if [ ! -f .env ]; then echo "β Error: .env file not found. Run make use-external-infra first."; exit 1; fi
@if [ -z "$(BP)" ] && [ -z "$(FP)" ]; then \
echo "β Error: Either BP (Backend Port) or FP (Frontend Port) is required."; \
$(call print_help,change-ports); \
exit 1; \
fi
$(call check_port,$(BP))
$(call check_port,$(FP))
@BP_OLD=$$(grep "^BACKEND_PORT=" .env | cut -d= -f2 || echo "8000"); \
FP_OLD=$$(grep "^FRONTEND_PORT=" .env | cut -d= -f2 || echo "3000"); \
BP_NEW=$${BP:-$$BP_OLD}; \
FP_NEW=$${FP:-$$FP_OLD}; \
if [ "$$BP_NEW" = "$$BP_OLD" ] && [ "$$FP_NEW" = "$$FP_OLD" ]; then \
echo "βΉοΈ No port changes requested."; \
else \
echo "π Changing ports in .env..."; \
if [ "$$BP_NEW" != "$$BP_OLD" ]; then \
echo " Backend: $$BP_OLD -> $$BP_NEW"; \
if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' "s/^BACKEND_PORT=.*/BACKEND_PORT=$$BP_NEW/" .env; \
sed -i '' "s/:$$BP_OLD/:$$BP_NEW/g" .env; \
else \
sed -i "s/^BACKEND_PORT=.*/BACKEND_PORT=$$BP_NEW/" .env; \
sed -i "s/:$$BP_OLD/:$$BP_NEW/g" .env; \
fi \
fi; \
if [ "$$FP_NEW" != "$$FP_OLD" ]; then \
echo " Frontend: $$FP_OLD -> $$FP_NEW"; \
if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' "s/^FRONTEND_PORT=.*/FRONTEND_PORT=$$FP_NEW/" .env; \
sed -i '' "s/:$$FP_OLD/:$$FP_NEW/g" .env; \
else \
sed -i "s/^FRONTEND_PORT=.*/FRONTEND_PORT=$$FP_NEW/" .env; \
sed -i "s/:$$FP_OLD/:$$FP_NEW/g" .env; \
fi \
fi; \
echo "β
Ports updated. Please restart your containers:"; \
echo " docker-compose -f docker-compose.dev.yml up -d backend frontend"; \
fi
check-conf: ## Check current database and server configuration
@echo "π Checking configuration..."
@echo ""
@echo "--- Database Configuration ---"
@if [ -f .env ]; then \
DB_ENV=$$(grep '^POSTGRES_DB=' .env | cut -d= -f2); \
if [ -n "$$DB_ENV" ]; then \
printf "%-25s \033[0;34m$$DB_ENV\033[0m\n" ".env POSTGRES_DB:"; \
else \
printf "%-25s \033[0;33mDEFAULT (eceee_v4)\033[0m\n" ".env POSTGRES_DB:"; \
fi; \
DB_HOST=$$(grep '^POSTGRES_HOST=' .env | cut -d= -f2); \
printf "%-25s \033[0;34m$${DB_HOST:-eceee-v4-db}\033[0m\n" "Postgres Host:"; \
else \
printf "%-25s \033[0;33mNONE (using defaults)\033[0m\n" ".env configuration:"; \
fi
@printf "%-25s " "Backend actual DB:"
@docker-compose -f docker-compose.dev.yml run --rm -T backend python manage.py shell -c "from django.conf import settings; print(settings.DATABASES['default']['NAME'])" 2>/dev/null || echo "\033[0;31mERROR: Could not query backend\033[0m"
@if [ -f .env ]; then \
DB_HOST=$$(grep '^POSTGRES_HOST=' .env | cut -d= -f2); \
if [ "$$DB_HOST" = "db" ]; then \
echo ""; \
echo "\033[0;33mβ οΈ Warning: POSTGRES_HOST is still set to 'db' in .env.\033[0m"; \
echo "Run \033[0;36mmake use-external-infra\033[0m to fix this."; \
fi; \
fi
@echo ""
@echo "--- Service Connectivity (from Backend) ---"
@check_conn() { \
name=$$1; host=$$2; port=$$3; \
if docker-compose -f docker-compose.dev.yml run --rm -T backend python -c "import socket; s = socket.socket(); s.settimeout(2); s.connect(('$$host', int('$$port'))); s.close()" >/dev/null 2>&1; then \
printf "%-25s [\033[0;32mCONNECTED\033[0m] to $$host:$$port\n" "$$name:"; \
else \
printf "%-25s [\033[0;31mFAILED\033[0m] to $$host:$$port\n" "$$name:"; \
fi; \
}; \
DB_HOST=$$(grep '^POSTGRES_HOST=' .env | cut -d= -f2 || echo "eceee-v4-db"); \
REDIS_URL=$$(grep '^REDIS_URL=' .env | cut -d= -f2 || echo "redis://eceee-v4-redis:6379/0"); \
REDIS_HOST=$$(echo $$REDIS_URL | sed -e 's/redis:\/\///' -e 's/[:\/].*//'); \
REDIS_PORT=$$(echo $$REDIS_URL | sed -e 's/.*://' -e 's/\/.*//' | grep -E '^[0-9]+$$' || echo "6379"); \
check_conn "Postgres" "$$DB_HOST" "5432"; \
check_conn "Redis" "$$REDIS_HOST" "$$REDIS_PORT"; \
check_conn "MinIO" "eceee-v4-minio" "9000"; \
check_conn "ImgProxy" "eceee-v4-imgproxy" "8080"; \
echo ""
@echo "--- Server Network Configuration ---"
@if docker network inspect eceee_shared_network >/dev/null 2>&1; then \
printf "%-25s [\033[0;32mCONNECTED\033[0m] (eceee_shared_network)\n" "Shared Network:"; \
else \
printf "%-25s [\033[0;31mMISSING\033[0m] (eceee_shared_network)\n" "Shared Network:"; \
fi
@echo ""
check-db: check-conf ## Alias for check-conf
replicate-db: ## Clone current DB to branch-specific DB and update .env
$(call check_help,replicate-db)
@echo "π Replicating database to branch-specific version..."
docker-compose -f docker-compose.dev.yml run --rm -e GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) backend python manage.py replicate_db
@echo ""
@echo "β
Database replicated. Please start the backend to apply changes:"
@echo " make backend"
@ echo ""
list-dbs: ## List all database clones
$(call check_help,list-dbs)
docker-compose -f docker-compose.dev.yml run --rm -T backend python manage.py list_dbs
switch-db: ## Switch current database in .env (use: make switch-db DB=dbname)
$(call check_help,switch-db)
@if [ -z "$(DB)" ]; then \
echo "β Error: DB name is required"; \
$(call print_help,switch-db); \
exit 1; \
fi
@# Check if DB exists first
@docker-compose -f docker-compose.dev.yml run --rm -T backend python manage.py shell -c "import psycopg2; from django.conf import settings; s=settings.DATABASES['default']; conn=psycopg2.connect(dbname='postgres', user=s['USER'], password=s['PASSWORD'], host=s['HOST'], port=s['PORT']); cur=conn.cursor(); cur.execute('SELECT 1 FROM pg_database WHERE datname = %s', ('$(DB)',)); exists=cur.fetchone(); conn.close(); exit(0 if exists else 1)" >/dev/null 2>&1 || (echo "β Error: Database '$(DB)' does not exist."; exit 1)
@echo "π Switching database to '$(DB)' in .env..."
@if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' "s/^POSTGRES_DB=.*/POSTGRES_DB=$(DB)/" .env; \
sed -i '' "s|DATABASE_URL=\(.*\)/[^/]*$$|DATABASE_URL=\1/$(DB)|" .env; \
else \
sed -i "s/^POSTGRES_DB=.*/POSTGRES_DB=$(DB)/" .env; \
sed -i "s|DATABASE_URL=\(.*\)/[^/]*$$|DATABASE_URL=\1/$(DB)|" .env; \
fi
@echo "β
Successfully switched to database '$(DB)'."
@echo "Restart your docker containers to apply changes: make restart"
# Tailwind CSS build commands
tailwind-build: ## Build Tailwind CSS for backend templates
@echo "π¨ Building Tailwind CSS..."
cd backend && npx tailwindcss -i ./static/css/tailwind.input.css -o ./static/css/tailwind.output.css --minify
tailwind-watch: ## Watch and rebuild Tailwind CSS on changes
@echo "π Watching Tailwind CSS for changes..."
cd backend && npx tailwindcss -i ./static/css/tailwind.input.css -o ./static/css/tailwind.output.css --watch