-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
150 lines (121 loc) · 5.06 KB
/
Makefile
File metadata and controls
150 lines (121 loc) · 5.06 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
# Vichara AI — Makefile
#
# Default build (`make` or `make build`) compiles the Next.js frontend and
# embeds it into the single Go binary so API + dashboard run on the same port.
BINARY := vichara
MODULE := github.com/vikukumar/vichara-ai
VERSION := v1.0.0
BUILD_DIR := dist
CMD_DIR := ./cmd/vichara
LDFLAGS := -ldflags "-X main.Version=$(VERSION) -X main.BuildDate=$(shell date -u +%Y-%m-%dT%H:%M:%SZ) -s -w"
# ── OS detection ─────────────────────────────────────────────────────────────
# On Windows (native make / WSL2), append .exe to the local binary name.
ifeq ($(OS),Windows_NT)
EXT := .exe
else
EXT :=
endif
LOCAL_BINARY := $(BUILD_DIR)/$(BINARY)$(EXT)
# ── Package manager auto-detection ───────────────────────────────────────────
# Prefer pnpm when pnpm-lock.yaml is present, fall back to npm.
ifneq (,$(wildcard web/pnpm-lock.yaml))
PKG_MGR := pnpm
PKG_INSTALL := pnpm install --frozen-lockfile
PKG_RUN := pnpm run
else ifneq (,$(wildcard web/yarn.lock))
PKG_MGR := yarn
PKG_INSTALL := yarn install --frozen-lockfile
PKG_RUN := yarn
else
PKG_MGR := npm
PKG_INSTALL := npm install --prefer-offline
PKG_RUN := npm run
endif
.PHONY: all build build-go build-all clean test test-integration cover lint fmt vet tidy \
docker-build docker-up docker-down docker-logs migrate \
web-install web-dev web-build help
all: build
## build: Build web dashboard and compile binary with embedded UI (default)
build: web-build
@echo ">> Building $(BINARY) $(VERSION) [embedded UI] -> $(LOCAL_BINARY)"
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 go build $(LDFLAGS) -tags embed_ui -o $(LOCAL_BINARY) $(CMD_DIR)
## build-go: Compile Go binary only — UI served from ./web/out/ on disk (fast iteration)
build-go:
@echo ">> Building $(BINARY) $(VERSION) [dev, UI from disk] -> $(LOCAL_BINARY)"
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 go build $(LDFLAGS) -o $(LOCAL_BINARY) $(CMD_DIR)
## build-all: Cross-compile for all platforms with embedded UI
build-all: web-build
@echo ">> Cross-compiling $(BINARY) with embedded UI (pkg manager: $(PKG_MGR))..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -tags embed_ui -o $(BUILD_DIR)/$(BINARY)-linux-amd64 $(CMD_DIR)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -tags embed_ui -o $(BUILD_DIR)/$(BINARY)-linux-arm64 $(CMD_DIR)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -tags embed_ui -o $(BUILD_DIR)/$(BINARY)-darwin-amd64 $(CMD_DIR)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -tags embed_ui -o $(BUILD_DIR)/$(BINARY)-darwin-arm64 $(CMD_DIR)
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -tags embed_ui -o $(BUILD_DIR)/$(BINARY)-windows-amd64.exe $(CMD_DIR)
## run: Build (embedded UI) and start API + workers + scheduler + dashboard on :8080
run: build
$(LOCAL_BINARY) --mode=all
## run-dev: Fast dev loop — Go-only build, UI served from ./web/out/ on disk
run-dev: build-go
$(LOCAL_BINARY) --mode=all
## run-server: Run only the API server
run-server: build
$(LOCAL_BINARY) --mode=server
## run-worker: Run only the worker pool
run-worker: build-go
$(LOCAL_BINARY) --mode=worker
## test: Run all tests
test:
go test -v -race -coverprofile=coverage.out ./...
## test-integration: Run integration tests (requires running dependencies)
test-integration:
go test -v -tags integration ./tests/...
## cover: Open coverage report
cover: test
go tool cover -html=coverage.out
## lint: Lint the code
lint:
golangci-lint run ./...
## fmt: Format code
fmt:
gofmt -s -w .
goimports -w .
## vet: Run go vet
vet:
go vet ./...
## tidy: Tidy modules
tidy:
go mod tidy
## docker-build: Build Docker image (includes web build + embedded UI)
docker-build:
docker build -t vichara-ai/vichara:$(VERSION) -t vichara-ai/vichara:latest .
## docker-up: Start all services with Docker Compose
docker-up:
docker compose -f deployments/docker-compose.yml up -d
## docker-down: Stop all services
docker-down:
docker compose -f deployments/docker-compose.yml down
## docker-logs: Follow service logs
docker-logs:
docker compose -f deployments/docker-compose.yml logs -f
## migrate: Run database migrations
migrate: build
$(LOCAL_BINARY) migrate
## web-install: Install web dashboard dependencies using $(PKG_MGR)
web-install:
cd web && $(PKG_INSTALL)
## web-dev: Start Next.js dev server — points at API on :8080 (run `make run-dev` first)
web-dev:
cd web && NEXT_PUBLIC_API_URL=http://localhost:8080 $(PKG_RUN) dev
## web-build: Build Next.js static export into web/out/ — called automatically by `make build`
web-build:
@echo ">> Building web dashboard using $(PKG_MGR)"
cd web && $(PKG_INSTALL) && $(PKG_RUN) build
## clean: Remove build artifacts
clean:
rm -rf $(BUILD_DIR) coverage.out web/out web/.next
## help: Show this help
help:
@sed -n 's/^##//p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /'