-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
238 lines (190 loc) · 9.9 KB
/
Makefile
File metadata and controls
238 lines (190 loc) · 9.9 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
.PHONY: all build clean test lint help \
release-api release-indexer release-web release-zoekt release-website \
release-helm release-helm-website release-cli
# Configuration
GOCMD := go
DOCKER_COMPOSE := docker compose
DOCKER := docker
BIN_DIR := bin
CMD_DIR := cmd
# Environment for local development
DEV_ENV := CS_DATABASE_URL=postgres://codesearch:codesearch@localhost:5432/codesearch?sslmode=disable \
CS_REDIS_ADDR=localhost:6379 \
CS_ZOEKT_URL=http://localhost:6070 \
CS_REPOS_BASE_PATH=./data/repos \
CS_INDEXER_INDEX_PATH=./data/index \
CS_INDEXER_REPOS_PATH=./data/repos \
CS_LOG_LEVEL=debug
# =============================================================================
# Build
# =============================================================================
all: build
build: ## Build all binaries
$(GOCMD) build -o $(BIN_DIR)/code-search ./$(CMD_DIR)/cli
$(GOCMD) build -o $(BIN_DIR)/api-server ./$(CMD_DIR)/api
$(GOCMD) build -o $(BIN_DIR)/indexer ./$(CMD_DIR)/indexer
$(GOCMD) build -o $(BIN_DIR)/migrate ./$(CMD_DIR)/migrate
$(GOCMD) build -o $(BIN_DIR)/zoekt-refresh ./$(CMD_DIR)/zoekt-refresh
$(GOCMD) build -o $(BIN_DIR)/mcp-server ./$(CMD_DIR)/mcp
# =============================================================================
# Development
# =============================================================================
dev-api: ## Run API server locally
$(DEV_ENV) $(GOCMD) run ./$(CMD_DIR)/api
dev-indexer: ## Run indexer locally
$(DEV_ENV) $(GOCMD) run ./$(CMD_DIR)/indexer
dev-web: ## Run web frontend locally
cd web && bun dev
dev-website: ## Run project website locally
cd website && bun run dev
dev-zoekt: ## Run zoekt-webserver locally
@mkdir -p ./data/index
zoekt-webserver -index ./data/index -listen :6070
dev-mcp: ## Run MCP server (stdio)
$(GOCMD) run ./$(CMD_DIR)/mcp --api-url http://localhost:8080
dev-mcp-http: ## Run MCP server (HTTP on :9090)
$(GOCMD) run ./$(CMD_DIR)/mcp --api-url http://localhost:8080 --transport http --http-addr :9090
dev-infra: ## Start infrastructure (postgres, redis, zoekt)
$(DOCKER_COMPOSE) up -d postgres redis zoekt
dev-setup: ## First-time setup for local development
@echo "==> Installing zoekt binaries..."
go install github.com/sourcegraph/zoekt/cmd/zoekt-webserver@latest
go install github.com/sourcegraph/zoekt/cmd/zoekt-git-index@latest
@echo "==> Installing web dependencies..."
cd web && bun install
@echo "==> Downloading Go dependencies..."
$(GOCMD) mod download
@echo "==> Starting infrastructure..."
$(DOCKER_COMPOSE) up -d postgres redis
@sleep 3
@echo "==> Running migrations..."
-$(GOCMD) run ./$(CMD_DIR)/migrate up
@echo ""
@echo "✅ Setup complete! Run in separate terminals:"
@echo " make dev-zoekt # Zoekt on :6070"
@echo " make dev-api # API on :8080"
@echo " make dev-indexer # Indexer worker"
@echo " make dev-web # Frontend on :3000"
# =============================================================================
# Testing & Linting
# =============================================================================
test: ## Run tests
$(GOCMD) test -v ./...
test-cover: ## Run tests with coverage
$(GOCMD) test -v -cover -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
lint: ## Run linters
golangci-lint run ./...
vet: ## Run go vet
$(GOCMD) vet ./...
# =============================================================================
# Database
# =============================================================================
migrate-up: ## Run migrations
$(DEV_ENV) $(GOCMD) run ./$(CMD_DIR)/migrate up
migrate-down: ## Rollback last migration
$(DEV_ENV) $(GOCMD) run ./$(CMD_DIR)/migrate down
migrate-add: ## Run new migration (usage: make migrate-add name=your_migration_name)
@echo "Creating new migration: $(name)"
@if [ -z "$(name)" ]; then \
echo "Error: Migration name is required. Usage: make migrate-add name=your_migration_name"; \
exit 1; \
fi
$(DEV_ENV) $(GOCMD) run ./$(CMD_DIR)/migrate add $(name)
migrate-status: ## Show migration status
$(DEV_ENV) $(GOCMD) run ./$(CMD_DIR)/migrate status
# =============================================================================
# Docker
# =============================================================================
docker-up: ## Start all services
$(DOCKER_COMPOSE) up -d
docker-down: ## Stop all services
$(DOCKER_COMPOSE) down
docker-logs: ## View logs (usage: make logs or make logs name=api)
$(DOCKER_COMPOSE) logs -f $(name)
docker-ps: ## Show running containers
$(DOCKER_COMPOSE) ps
docker-rebuild: ## Rebuild and restart services
$(DOCKER_COMPOSE) down
$(DOCKER_COMPOSE) up -d --build
docker-build: ## Build Docker images
$(DOCKER_COMPOSE) build
$(DOCKER) build -t code-search-zoekt-refresh:latest -f docker/zoekt-refresh.Dockerfile .
$(DOCKER) build -t code-search-indexer-scip:latest -f docker/indexer-scip.Dockerfile .
docker-push: ## Push Docker images to GitHub Container Registry
@$(DOCKER) tag code-search-api:latest ghcr.io/techquestsdev/code-search-api:latest
@$(DOCKER) tag code-search-indexer:latest ghcr.io/techquestsdev/code-search-indexer:latest
@$(DOCKER) tag code-search-web:latest ghcr.io/techquestsdev/code-search-web:latest
@$(DOCKER) tag code-search-website:latest ghcr.io/techquestsdev/code-search-website:latest
@$(DOCKER) tag code-search-zoekt:latest ghcr.io/techquestsdev/code-search-zoekt:latest
@$(DOCKER) tag code-search-zoekt-refresh:latest ghcr.io/techquestsdev/code-search-zoekt-refresh:latest
@$(DOCKER) tag code-search-indexer-scip:latest ghcr.io/techquestsdev/code-search-indexer-scip:latest
@$(DOCKER) push ghcr.io/techquestsdev/code-search-api:latest
@$(DOCKER) push ghcr.io/techquestsdev/code-search-indexer:latest
@$(DOCKER) push ghcr.io/techquestsdev/code-search-indexer-scip:latest
@$(DOCKER) push ghcr.io/techquestsdev/code-search-web:latest
@$(DOCKER) push ghcr.io/techquestsdev/code-search-website:latest
@$(DOCKER) push ghcr.io/techquestsdev/code-search-zoekt:latest
@$(DOCKER) push ghcr.io/techquestsdev/code-search-zoekt-refresh:latest
@echo "✅ Docker images pushed to GitHub Container Registry."
# =============================================================================
# Release (creates git tags that trigger CI workflows)
# =============================================================================
# Usage: make release-api version=1.0.0
release-api: ## Release API server (usage: make release-api version=x.y.z)
@if [ -z "$(version)" ]; then echo "Error: version is required. Usage: make release-api version=1.0.0"; exit 1; fi
git tag "oss-api/$(version)"
git push origin "oss-api/$(version)"
@echo "✅ Tagged oss-api/$(version) — Docker build will run in CI."
release-indexer: ## Release indexer (usage: make release-indexer version=x.y.z)
@if [ -z "$(version)" ]; then echo "Error: version is required. Usage: make release-indexer version=1.0.0"; exit 1; fi
git tag "oss-indexer/$(version)"
git push origin "oss-indexer/$(version)"
@echo "✅ Tagged oss-indexer/$(version) — Docker build will run in CI."
release-web: ## Release web frontend (usage: make release-web version=x.y.z)
@if [ -z "$(version)" ]; then echo "Error: version is required. Usage: make release-web version=1.0.0"; exit 1; fi
git tag "oss-web/$(version)"
git push origin "oss-web/$(version)"
@echo "✅ Tagged oss-web/$(version) — Docker build will run in CI."
release-zoekt: ## Release zoekt (usage: make release-zoekt version=x.y.z)
@if [ -z "$(version)" ]; then echo "Error: version is required. Usage: make release-zoekt version=1.0.0"; exit 1; fi
git tag "oss-zoekt/$(version)"
git push origin "oss-zoekt/$(version)"
@echo "✅ Tagged oss-zoekt/$(version) — Docker build will run in CI."
release-website: ## Release website (usage: make release-website version=x.y.z)
@if [ -z "$(version)" ]; then echo "Error: version is required. Usage: make release-website version=1.0.0"; exit 1; fi
git tag "website/$(version)"
git push origin "website/$(version)"
@echo "✅ Tagged website/$(version) — Docker build will run in CI."
release-helm: ## Release code-search Helm chart (usage: make release-helm version=x.y.z)
@if [ -z "$(version)" ]; then echo "Error: version is required. Usage: make release-helm version=1.0.0"; exit 1; fi
git tag "helm-code-search/$(version)"
git push origin "helm-code-search/$(version)"
@echo "✅ Tagged helm-code-search/$(version) — Helm chart release will run in CI."
release-helm-website: ## Release website Helm chart (usage: make release-helm-website version=x.y.z)
@if [ -z "$(version)" ]; then echo "Error: version is required. Usage: make release-helm-website version=1.0.0"; exit 1; fi
git tag "helm-website/$(version)"
git push origin "helm-website/$(version)"
@echo "✅ Tagged helm-website/$(version) — Helm chart release will run in CI."
release-cli: ## Release CLI via GoReleaser (usage: make release-cli version=x.y.z)
@if [ -z "$(version)" ]; then echo "Error: version is required. Usage: make release-cli version=1.0.0"; exit 1; fi
git tag "oss-cli/$(version)"
git push origin "oss-cli/$(version)"
@echo "✅ Tagged oss-cli/$(version) — GoReleaser will build and publish the CLI."
# =============================================================================
# Cleanup
# =============================================================================
clean: ## Clean build artifacts
rm -rf $(BIN_DIR) coverage.out coverage.html
docker-clean: ## Clean Docker build cache and unused images
$(DOCKER) builder prune -f
$(DOCKER) image prune -f
docker-prune: ## Full Docker cleanup (removes all unused data)
$(DOCKER_COMPOSE) down -v --remove-orphans
$(DOCKER) system prune -a -f --volumes
@echo "✅ Cleaned. Run 'make up' to rebuild."
# =============================================================================
# Help
# =============================================================================
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}'