-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMakefile
More file actions
212 lines (184 loc) · 7.03 KB
/
Makefile
File metadata and controls
212 lines (184 loc) · 7.03 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
.PHONY: dev prod clean build build-frontend run deps test fmt lint check help kill-dev image dev-docker dev-auth modules proto proto-clean proto-lint proto-format proto-breaking gen dev-docs
DATA_DIR := ./data
DOCKER_DATA_DIR := /tmp/discopanel
DB_FILE := $(DATA_DIR)/discopanel.db
FRONTEND_DIR := web/discopanel
DISCOPANEL_BIN := build/discopanel
BUF_IMAGE := bufbuild/buf:latest
BUF_RUN := docker run --rm \
--volume "$(shell pwd):/workspace" \
--workdir /workspace \
--user "$(shell id -u):$(shell id -g)" \
--env HOME=/tmp \
$(BUF_IMAGE)
#DISCOSUPPORT_URL := http://localhost:8911
# Development mode - runs backend and frontend concurrently
run:
@echo "Starting development environment..."
@mkdir -p $(DATA_DIR)
@echo "Starting backend server with frontend dev server..."
@trap 'echo "Stopping all processes..."; kill $$(jobs -p) 2>/dev/null; wait; exit' INT TERM; \
cd $(FRONTEND_DIR) && npm run dev & \
FRONTEND_PID=$$!; \
go run cmd/discopanel/main.go & \
BACKEND_PID=$$!; \
wait $$BACKEND_PID $$FRONTEND_PID
restore:
@echo "Restoring seeded db for dev"
@mkdir -p $(DATA_DIR)
cp dev/discopanel.db data/discopanel.db || echo "No saved dev state, starting new db"
dev: clean restore run
# Build and run with OIDC provider (Keycloak)
dev-auth-%: clean
docker compose -f oidc/$*/docker-compose.yaml down -v --remove-orphans
@docker run --rm -v /tmp:/tmp alpine rm -rf /tmp/discopanel
@echo "Building and running with OIDC provider..."
docker compose -f oidc/$*/docker-compose.yaml build --no-cache
docker compose -f oidc/$*/docker-compose.yaml up
dev-docs:
cd docs/discopanel && npm run dev
# Production build and run
prod: build-frontend
@echo "Building for production..."
@mkdir -p $(DATA_DIR)
go build -o $(DISCOPANEL_BIN) cmd/discopanel/main.go
# Build frontend for production
build-frontend:
@echo "Building frontend..."
cd $(FRONTEND_DIR) && npm run build
# Build backend with embedded frontend
build: build-frontend
@echo "Building backend with embedded frontend..."
go build -o $(DISCOPANEL_BIN) cmd/discopanel/main.go
# Build and push Docker image to :dev tag
image:
@echo "Building and pushing Docker image..."
@bash scripts/build.sh
# Build and push all module Docker images
modules: gen
@echo "Building and pushing module images..."
@for dockerfile in docker/Dockerfile.*; do \
name=$$(basename $$dockerfile | sed 's/Dockerfile\.//'); \
if [ "$$name" != "discopanel" ]; then \
echo "Building nickheyer/discopanel-$$name:latest..."; \
docker build -t "nickheyer/discopanel-$$name:latest" -f "$$dockerfile" . && \
echo "Pushing nickheyer/discopanel-$$name:latest..." && \
docker push "nickheyer/discopanel-$$name:latest"; \
fi \
done
@echo "Module builds complete!"
# Build and push a specific module (e.g., make module-status, make module-geyser)
module-%: gen
@if [ ! -f "docker/Dockerfile.$*" ]; then \
echo "Error: docker/Dockerfile.$* not found"; \
echo "Available modules:"; \
ls docker/Dockerfile.* 2>/dev/null | sed 's/docker\/Dockerfile\./ /g' | grep -v discopanel; \
exit 1; \
fi
@echo "Building nickheyer/discopanel-$*:latest..."
@docker build -t "nickheyer/discopanel-$*:latest" -f "docker/Dockerfile.$*" .
@echo "Pushing nickheyer/discopanel-$*:latest..."
@docker push "nickheyer/discopanel-$*:latest"
@echo "Module $* build complete!"
# Clean development data
clean:
@echo "Cleaning development data..."
@if [ -d "$(DATA_DIR)" ]; then \
echo "Removing data directory..."; \
rm -rf $(DATA_DIR); \
fi
@if [ -d "$(DOCKER_DATA_DIR)" ]; then \
echo "Removing docker data directory..."; \
docker run --rm -v $(DOCKER_DATA_DIR):/tmp alpine sh -c 'rm -rf /tmp/*'; \
fi
@if [ -f "$(DISCOPANEL_BIN)" ]; then \
echo "Removing backend binary..."; \
rm -f $(DISCOPANEL_BIN); \
fi
@if [ -f "discopanel.db" ]; then \
echo "Removing old database file..."; \
rm -f discopanel.db; \
fi
@echo "Clean complete!"
# Kill any orphaned dev processes
kill-dev:
@echo "Killing orphaned development processes..."
@pkill -f "npm run dev" || true
@pkill -f "vite" || true
@pkill -f "go run cmd/discopanel/main.go" || true
@pkill -f "discopanel" || true
@echo "Cleanup complete!"
# Install dependencies
deps:
@echo "Installing Go dependencies..."
go mod download
@echo "Updating buf dependencies (using Docker)..."
$(BUF_RUN) dep update
@echo "Installing frontend dependencies..."
cd $(FRONTEND_DIR) && npm install
# Run tests
test:
@echo "Running Go tests..."
go test ./...
# Format code
fmt:
@echo "Formatting Go code..."
go fmt ./...
@echo "Formatting frontend code..."
cd $(FRONTEND_DIR) && npm run format
# Lint code
lint: proto-lint
@echo "Linting frontend code..."
cd $(FRONTEND_DIR) && npm run lint
# Type check frontend
check:
@echo "Type checking frontend..."
cd $(FRONTEND_DIR) && npm run check
proto:
@echo "Generating protocol buffer code (using Docker)..."
$(BUF_RUN) generate
@echo "Proto generation complete!"
proto-clean:
@echo "Cleaning generated proto files..."
rm -rf pkg/proto
rm -rf web/discopanel/src/lib/proto
@echo "Proto files cleaned!"
proto-lint:
@echo "Linting proto files (using Docker)..."
$(BUF_RUN) lint || echo "Buf linting failed, but it's probably just missing comment documentation. Ignore it."
@echo "Proto linting complete!"
gen: proto-clean proto
proto-format:
@echo "Formatting proto files (using Docker)..."
$(BUF_RUN) format -w
@echo "Proto files formatted!"
proto-breaking:
@echo "Checking for breaking changes (using Docker)..."
$(BUF_RUN) breaking --against '.git#branch=main'
@echo "Breaking change check complete!"
# proto-install:
# go install github.com/sudorandom/protoc-gen-connect-openapi@latest
# Help
help:
@echo "Available commands:"
@echo " make dev - Run in development mode (frontend + backend)"
@echo " make build - Build standalone binary with embedded frontend"
@echo " make prod - Build and run in production mode"
@echo " make image - Build and push Docker image to :dev tag"
@echo " make dev-docker - Build and run Docker container locally (no cache)"
@echo " make dev-auth - Build and run with OIDC provider (Keycloak)"
@echo " make modules - Build and push all module Docker images"
@echo " make clean - Remove data directory and build artifacts"
@echo " make kill-dev - Kill any orphaned dev processes"
@echo " make deps - Install all dependencies"
@echo " make test - Run tests"
@echo " make fmt - Format code"
@echo " make lint - Lint code"
@echo " make check - Type check frontend"
@echo " make gen - Clean and regenerate proto code (via Docker)"
@echo " make proto - Generate Go and TypeScript code from proto files (via Docker)"
@echo " make proto-clean - Remove all generated proto files"
@echo " make proto-lint - Lint proto files for style and correctness (via Docker)"
@echo " make proto-format - Format proto files (via Docker)"
@echo " make proto-breaking - Check for breaking changes against main (via Docker)"
@echo " make help - Show this help message"