-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
178 lines (142 loc) · 8.07 KB
/
Copy pathMakefile
File metadata and controls
178 lines (142 loc) · 8.07 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
.PHONY: all build server mcp cli deps migrate dev dev-clean clean docker-up docker-down release server-linux \
smoke-test smoke-test-full integration-test psql install-mcp update-mcp
# ── Config ───────────────────────────────────────────────────────────────────
BINDIR := ./bin
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
BUILDTIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
VERSION_LDFLAGS := -X github.com/KB-perByte/hiveshare/internal/version.Commit=$(COMMIT) \
-X github.com/KB-perByte/hiveshare/internal/version.BuildTime=$(BUILDTIME)
GOFLAGS := -ldflags="-s -w $(VERSION_LDFLAGS)"
CONTAINER_RUNTIME ?= docker
# ── Build ─────────────────────────────────────────────────────────────────────
all: deps build
# Install CLI + MCP sidecar and wire into Claude Code / Cursor.
install-mcp:
./scripts/install-client.sh
# Quick MCP binary rebuild — no prompts, keeps existing credentials.
update-mcp: mcp
@BINARY="$${HOME}/.local/bin/hiveshare-mcp"; \
rm -f "$$BINARY"; \
install -m 755 $(BINDIR)/hiveshare-mcp "$$BINARY"; \
echo " Updated $$BINARY"
build: server mcp cli
server:
go build $(GOFLAGS) -o $(BINDIR)/hiveshare-server ./cmd/server
# Cross-compile for EC2 (Ubuntu amd64)
server-linux:
GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -o $(BINDIR)/hiveshare-server-linux ./cmd/server
@echo "Built $(BINDIR)/hiveshare-server-linux commit=$(COMMIT) build_time=$(BUILDTIME)"
mcp:
go build $(GOFLAGS) -o $(BINDIR)/hiveshare-mcp ./cmd/mcp
cli:
go build $(GOFLAGS) -o $(BINDIR)/hiveshare ./cmd/hiveshare
deps:
go mod tidy
go mod download
# ── Database ─────────────────────────────────────────────────────────────────
POSTGRES_URL ?= postgres://hiveshare:hiveshare@localhost:5432/hiveshare?sslmode=disable
# Compose service name (stable across project prefixes / renamed containers).
POSTGRES_SERVICE ?= postgres
migrate:
@echo "Applying migrations..."
@if command -v psql >/dev/null 2>&1; then \
for f in migrations/*.sql; do \
echo " Running $$f..."; \
psql "$(POSTGRES_URL)" -f "$$f"; \
done; \
elif $(CONTAINER_RUNTIME) compose ps --status running $(POSTGRES_SERVICE) >/dev/null 2>&1; then \
for f in migrations/*.sql; do \
echo " Running $$f (via compose $(POSTGRES_SERVICE))..."; \
$(CONTAINER_RUNTIME) compose exec -T $(POSTGRES_SERVICE) \
psql -U hiveshare -d hiveshare -f - < "$$f"; \
done; \
else \
echo "Error: psql not found and compose service '$(POSTGRES_SERVICE)' is not running"; \
exit 1; \
fi
@echo "Migrations done."
# ── Dev ───────────────────────────────────────────────────────────────────────
dev: docker-up
@echo "Waiting for postgres to be healthy..."
@for i in $$(seq 1 30); do \
if $(CONTAINER_RUNTIME) compose exec -T $(POSTGRES_SERVICE) pg_isready -U hiveshare -q 2>/dev/null; then \
echo " postgres ready"; break; \
fi; \
if [ "$$i" -eq 30 ]; then echo " postgres did not become ready in time"; exit 1; fi; \
sleep 1; \
done
@$(MAKE) migrate
@echo "Starting server on host (no embeddings). Use ./scripts/dev-local.sh to run fully containerised."
JWT_SECRET=$${JWT_SECRET:-dev-secret-change-in-production} EMBED_PROVIDER= go run ./cmd/server
docker-up:
$(CONTAINER_RUNTIME) compose up -d
docker-down:
$(CONTAINER_RUNTIME) compose down
dev-clean:
$(CONTAINER_RUNTIME) compose down -v
psql:
@echo "**INFO**: Opening psql via '$(CONTAINER_RUNTIME) compose exec $(POSTGRES_SERVICE)'"
$(CONTAINER_RUNTIME) compose exec -it $(POSTGRES_SERVICE) psql -U hiveshare -d hiveshare
# ── Install CLI ───────────────────────────────────────────────────────────────
install: cli
@cp $(BINDIR)/hiveshare /usr/local/bin/hiveshare
@echo "hiveshare installed to /usr/local/bin/hiveshare"
install-mcp-system: mcp
@cp $(BINDIR)/hiveshare-mcp /usr/local/bin/hiveshare-mcp
@echo "hiveshare-mcp installed to /usr/local/bin/hiveshare-mcp"
# ── Release (local cross-compile) ─────────────────────────────────────────────
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
RELEASE_LDFLAGS := -ldflags="-s -w $(VERSION_LDFLAGS) -X main.version=$(VERSION)"
release:
@echo "Building release binaries for version $(VERSION) commit=$(COMMIT)..."
@mkdir -p dist
@for GOOS in linux darwin; do \
for GOARCH in amd64 arm64; do \
PLATFORM=$${GOOS}_$${GOARCH}; \
OUT=dist/$$PLATFORM; \
mkdir -p $$OUT; \
echo " Building $$PLATFORM..."; \
GOOS=$$GOOS GOARCH=$$GOARCH go build $(RELEASE_LDFLAGS) -o $$OUT/hiveshare-server ./cmd/server; \
GOOS=$$GOOS GOARCH=$$GOARCH go build $(RELEASE_LDFLAGS) -o $$OUT/hiveshare-mcp ./cmd/mcp; \
GOOS=$$GOOS GOARCH=$$GOARCH go build $(RELEASE_LDFLAGS) -o $$OUT/hiveshare ./cmd/hiveshare; \
tar -czf dist/hiveshare_$${PLATFORM}.tar.gz -C $$OUT .; \
echo " → dist/hiveshare_$${PLATFORM}.tar.gz"; \
done; \
done
@echo "Done. Tarballs in dist/"
# ── Test ──────────────────────────────────────────────────────────────────────
HIVESHARE_TEST_URL ?= $(or $(BASE_URL),http://localhost:8080)
smoke-test:
@./scripts/smoke-test.sh $(HIVESHARE_TEST_URL)
smoke-test-full:
@./scripts/smoke-test-full.sh $(HIVESHARE_TEST_URL)
integration-test:
HIVESHARE_TEST_URL=$(HIVESHARE_TEST_URL) pytest tests/ -v
# ── Clean ─────────────────────────────────────────────────────────────────────
clean:
rm -rf $(BINDIR) dist/
# ── Help ─────────────────────────────────────────────────────────────────────
help:
@echo "HiveShare Makefile targets:"
@echo ""
@echo " ./scripts/dev-local.sh One-command local dev setup (build + docker + migrate + run)"
@echo " make dev Start docker, run migrations, start server (same, less output)"
@echo " make build Build all binaries to ./bin/"
@echo " make server Build API server (embeds git commit + build time)"
@echo " make server-linux Cross-compile API for EC2 Ubuntu amd64"
@echo " make mcp Build MCP sidecar"
@echo " make cli Build hiveshare CLI"
@echo " make migrate Apply SQL migrations"
@echo " make install Install hiveshare CLI to /usr/local/bin (root)"
@echo " make install-mcp Interactive guided install: CLI + MCP to ~/.local/bin"
@echo " make install-mcp-system Install hiveshare-mcp to /usr/local/bin (root)"
@echo " make update-mcp Rebuild MCP binary and update ~/.local/bin"
@echo " make docker-up Start postgres + redis"
@echo " make docker-down Stop postgres + redis"
@echo " make dev-clean Stop containers and wipe database volume"
@echo " make psql Open psql shell in the running postgres container"
@echo " make smoke-test Basic connectivity check (no user needed)"
@echo " make smoke-test-full Full endpoint smoke test (curl + jq)"
@echo " make integration-test Pytest integration tests"
@echo " make release Cross-compile all platforms → dist/"
@echo " make clean Remove ./bin/ and dist/"