-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
216 lines (188 loc) · 6.75 KB
/
Makefile
File metadata and controls
216 lines (188 loc) · 6.75 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
.PHONY: help build up down restart logs logs-follow status clean rebuild validate env-check
.PHONY: backend-run backend-build backend-test backend-test-coverage migrate-create
.PHONY: lint lint-backend lint-ui format format-backend check setup-tools
# Default target
help:
@echo "Available commands:"
@echo ""
@echo "Docker:"
@echo " make build - Build the Waygates Docker image"
@echo " make up - Start containers in detached mode"
@echo " make down - Stop and remove containers"
@echo " make restart - Restart containers"
@echo " make logs - Show recent logs"
@echo " make logs-follow - Follow logs in real-time"
@echo " make status - Show container status"
@echo " make clean - Remove containers, volumes, and images"
@echo " make rebuild - Clean build and restart everything"
@echo " make validate - Validate Caddy JSON config"
@echo " make deploy - Full deployment (env-check, build, up)"
@echo ""
@echo "Backend (Go):"
@echo " make backend-run - Run the Go backend server locally"
@echo " make backend-build - Build the Go backend binary"
@echo " make backend-test - Run backend tests"
@echo " make backend-test-coverage - Run tests with coverage report"
@echo ""
@echo "Linting & Formatting:"
@echo " make lint - Run linters on both backend and UI"
@echo " make lint-backend - Run golangci-lint on backend"
@echo " make lint-ui - Lint and format UI with Biome"
@echo " make format - Format both backend and UI code"
@echo " make format-backend - Format Go code with gofmt/goimports"
@echo " make check - Run all checks (lint + tests)"
@echo ""
@echo "Database Migrations:"
@echo " make migrate-create NAME=name - Create new migration files"
@echo " Note: Migrations run automatically when backend starts"
@echo ""
@echo "Other:"
@echo " make env-check - Check if .env file exists"
@echo " make setup-tools - Install development tools (golangci-lint, goimports)"
# Check if .env file exists
env-check:
@if [ ! -f .env ]; then \
echo "❌ Error: .env file not found!"; \
echo "Please copy .env.example to .env and configure it:"; \
echo " cp .env.example .env"; \
exit 1; \
fi
@echo "✓ Environment file exists"
# Build the Docker image
build:
@echo "Building Waygates Docker image..."
docker compose build
# Start containers
up:
@echo "Starting containers..."
docker compose up -d
@echo "✓ Containers started"
@echo "Run 'make logs-follow' to watch logs"
# Stop containers
down:
@echo "Stopping containers..."
docker compose down
@echo "✓ Containers stopped"
# Restart containers
restart:
@echo "Restarting containers..."
docker compose restart
@echo "✓ Containers restarted"
# Show logs
logs:
docker compose logs --tail=100
# Follow logs in real-time
logs-follow:
docker compose logs -f
# Show container status
status:
@echo "Container status:"
@docker compose ps
@echo ""
@echo "Backend API: http://localhost:8080"
@echo "Caddy Admin: http://localhost:2019/config/"
# Clean everything (containers, volumes, images)
clean:
@echo "Cleaning up..."
docker compose down -v
docker rmi waygates 2>/dev/null || true
@echo "✓ Cleanup complete"
# Rebuild everything from scratch
rebuild: clean build up
# Validate Caddy JSON config (requires running container)
validate:
@echo "Validating Caddy JSON config..."
docker compose exec waygates caddy validate --config /etc/caddy/caddy.json
@echo "✓ Caddy config is valid"
# Full deployment pipeline
deploy: env-check build up
@echo ""
@echo "✓ Deployment complete!"
@echo ""
@echo "Services:"
@echo " Backend API: http://localhost:8080"
@echo " HTTP: http://localhost:80"
@echo " HTTPS: https://localhost:443"
@echo ""
@echo "View logs with: make logs-follow"
# ============================================
# Backend Commands
# ============================================
# Run the Go backend server locally
backend-run: env-check
@echo "Starting Go backend server..."
@go run backend/cmd/server/main.go
# Build the Go backend binary
backend-build:
@echo "Building Go backend..."
@go build -o bin/waygates backend/cmd/server/main.go
@echo "✓ Binary created at: bin/waygates"
# Run backend tests
backend-test:
@echo "Running backend tests..."
@go test -v ./backend/...
# Run backend tests with coverage (includes cross-package coverage from integration tests)
backend-test-coverage:
@echo "Running backend tests with coverage..."
@cd backend && go test -count=1 -coverprofile=coverage.out -covermode=atomic -coverpkg=./... ./...
@cd backend && go tool cover -func=coverage.out | grep total
@echo "✓ Coverage report generated at backend/coverage.out"
@echo "Run 'go tool cover -html=backend/coverage.out' to view in browser"
# ============================================
# Database Migration Commands
# ============================================
# Note: Migrations run automatically when the backend starts
# Create new migration files
migrate-create:
@if [ -z "$(NAME)" ]; then \
echo "❌ Error: NAME is required"; \
echo "Usage: make migrate-create NAME=create_users_table"; \
exit 1; \
fi
@echo "Creating migration: $(NAME)"
@bash -c 'NEXT=$$(ls backend/migrations/*.up.sql 2>/dev/null | wc -l | tr -d " "); \
NEXT=$$((NEXT + 1)); \
NUM=$$(printf "%06d" $$NEXT); \
touch backend/migrations/$${NUM}_$(NAME).up.sql; \
touch backend/migrations/$${NUM}_$(NAME).down.sql; \
echo "✓ Created:"; \
echo " backend/migrations/$${NUM}_$(NAME).up.sql"; \
echo " backend/migrations/$${NUM}_$(NAME).down.sql"'
# ============================================
# Linting & Formatting Commands
# ============================================
# Run all linters
lint: lint-backend lint-ui
# Lint backend with golangci-lint
lint-backend:
@echo "Linting Go backend..."
@golangci-lint run ./backend/...
@echo "✓ Backend lint complete"
# Lint and format UI with Biome
lint-ui:
@echo "Linting and formatting UI..."
@cd ui && pnpm check:fix
@echo "✓ UI check complete"
# Format all code
format: format-backend lint-ui
# Format backend with gofmt and goimports
format-backend:
@echo "Formatting Go backend..."
@gofmt -w -s backend/
@goimports -w -local github.com/aloks98/waygates backend/
@echo "✓ Backend formatted"
# Run all checks (lint + tests)
check: lint backend-test
@echo "✓ All checks passed"
# Install development tools
setup-tools:
@echo "Installing development tools..."
@echo "Installing golangci-lint..."
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@echo "Installing goimports..."
@go install golang.org/x/tools/cmd/goimports@latest
@echo "Installing UI dependencies..."
@cd ui && pnpm install
@echo "✓ Development tools installed"
@echo ""
@echo "Make sure $$GOPATH/bin is in your PATH"