-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (104 loc) · 4.05 KB
/
Makefile
File metadata and controls
130 lines (104 loc) · 4.05 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
.PHONY: dev dev-backend dev-frontend mysql mysql-start mysql-stop mysql-logs mysql-shell build clean test install docs fmt lint
# MySQL service management
mysql-start:
@echo "Starting MySQL container..."
GO_ENV=development docker compose up -d db
@echo "Waiting for MySQL to be ready..."
@until docker compose exec db mysqladmin ping -h localhost -u$${MYSQL_USER:-appuser} -p$${MYSQL_PASSWORD:-apppass} --silent; do \
echo "Waiting for MySQL..."; \
sleep 2; \
done
@echo "MySQL is ready!"
mysql-stop:
@echo "Stopping MySQL container..."
docker compose stop db
mysql-logs:
docker compose logs -f db
mysql-shell:
docker compose exec db mysql -u$${MYSQL_USER:-appuser} -p$${MYSQL_PASSWORD:-apppass} $${MYSQL_DATABASE:-app}
# Development mode for both services
dev:
NODE_ENV=development PORT=3000 BACKEND_PORT=8081 GIN_MODE=debug docker compose up --build
# Development mode for backend only
dev-backend:
NODE_ENV=development BACKEND_PORT=8081 GIN_MODE=debug docker compose up --build backend
# Development mode for frontend only
dev-frontend:
NODE_ENV=development PORT=3000 docker compose up --build frontend
# Production mode for both services
prod:
NODE_ENV=production PORT=80 BACKEND_PORT=8080 GIN_MODE=release docker compose up --build
# Production mode for backend only
prod-backend:
NODE_ENV=production BACKEND_PORT=8080 GIN_MODE=release docker compose up --build backend
# Production mode for frontend only
prod-frontend:
NODE_ENV=production PORT=80 docker compose up --build frontend
# Stop and remove all containers, networks, and volumes
clean:
docker compose down -v
# Remove all unused Docker resources
prune:
docker system prune -f
# Run all tests
test: test-backend test-frontend
# Run backend unit tests only (no external dependencies needed)
test-backend:
cd backend && go test ./... -v
# Start infrastructure for integration tests
integration-infra-start:
@echo "Starting integration test infrastructure..."
GO_ENV=test docker compose up -d db azurite
@echo "Waiting for MySQL to be ready..."
@until docker compose exec db mysqladmin ping -h localhost -u$${MYSQL_USER:-appuser} -p$${MYSQL_PASSWORD:-apppass} --silent 2>/dev/null; do \
echo "Waiting for MySQL..."; \
sleep 2; \
done
@echo "Waiting for Azurite to be ready..."
@until curl -s -o /dev/null http://localhost:10002/ 2>/dev/null; do \
echo "Waiting for Azurite..."; \
sleep 2; \
done
@echo "Integration infrastructure is ready!"
# Stop infrastructure for integration tests
integration-infra-stop:
@echo "Stopping integration test infrastructure..."
GO_ENV=test docker compose stop db azurite
# Run backend integration tests (starts/stops infra automatically)
test-backend-integration: integration-infra-start
cd backend && go test -tags integration ./... -v
$(MAKE) integration-infra-stop
# Run all backend tests (unit + integration)
test-backend-all: integration-infra-start
cd backend && go test -tags integration ./... -v
$(MAKE) integration-infra-stop
test-frontend:
cd frontend && npm test
# Run frontend e2e tests (requires MySQL running, starts backend natively)
test-e2e: integration-infra-start
@echo "Building and starting backend..."
@cd backend && go build -o tmp/main ./api/main.go
@cd backend && DB_HOST=localhost DB_PORT=3306 DB_NAME=$${MYSQL_DATABASE:-app} DB_USER=$${MYSQL_USER:-appuser} DB_PASSWORD=$${MYSQL_PASSWORD:-apppass} PORT=8081 ./tmp/main &
@echo "Waiting for backend to be healthy..."
@until curl -sf http://localhost:8081/health/live >/dev/null 2>&1; do \
sleep 1; \
done
@echo "Backend is ready, running Playwright tests..."
cd frontend && npx playwright test || (kill $$(lsof -ti:8081) 2>/dev/null; $(MAKE) integration-infra-stop; exit 1)
@echo "Stopping backend..."
@kill $$(lsof -ti:8081) 2>/dev/null || true
$(MAKE) integration-infra-stop
# Install dependencies
install:
cd backend && go mod download
cd frontend && npm install
# Generate API documentation
docs:
cd backend && swag init -g api/main.go
# Format and lint code
fmt:
cd backend && go fmt ./...
cd frontend && npm run format
lint:
cd backend && go vet ./...
cd frontend && npm run lint