-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
157 lines (134 loc) · 3.92 KB
/
Makefile
File metadata and controls
157 lines (134 loc) · 3.92 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
.PHONY: build run test test-coverage lint fmt clean tidy migrate-up migrate-down docker-build install help
# Binary name
BINARY_NAME=cortex
BINARY_DIR=bin
BINARY_PATH=$(BINARY_DIR)/$(BINARY_NAME)
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOLINT=golangci-lint
# Coverage parameters
COVERAGE_DIR=coverage
COVERAGE_FILE=$(COVERAGE_DIR)/coverage.out
COVERAGE_HTML=$(COVERAGE_DIR)/coverage.html
# Migration parameters
MIGRATIONS_DIR=migrations
# Docker parameters
DOCKER_IMAGE=cortex
DOCKER_TAG=latest
# Default target
all: build
# Display help
help:
@echo "Cortex - Memory Server for AI Coding Assistants"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " build Build the binary"
@echo " run Run the server"
@echo " test Run all tests"
@echo " test-coverage Run tests with coverage report"
@echo " lint Run golangci-lint"
@echo " fmt Format code"
@echo " clean Remove binaries and coverage"
@echo " tidy Run go mod tidy"
@echo " migrate-up Run database migrations"
@echo " migrate-down Rollback database migrations"
@echo " docker-build Build Docker image"
@echo " install Install binary to GOPATH/bin"
# Build the cortex binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BINARY_DIR)
$(GOBUILD) -o $(BINARY_PATH) ./cmd/cortex
@echo "Binary built: $(BINARY_PATH)"
# Run the cortex application
run:
$(GOCMD) run ./cmd/cortex
# Run tests without coverage
test:
@echo "Running tests..."
$(GOTEST) -v ./...
# Run tests with coverage report
test-coverage:
@echo "Running tests with coverage..."
@mkdir -p $(COVERAGE_DIR)
$(GOTEST) -v -coverprofile=$(COVERAGE_FILE) -covermode=atomic ./...
@echo "Generating coverage report..."
$(GOCMD) tool cover -html=$(COVERAGE_FILE) -o $(COVERAGE_HTML)
@echo "Coverage report generated: $(COVERAGE_HTML)"
@$(GOCMD) tool cover -func=$(COVERAGE_FILE)
# Run golangci-lint
lint:
@echo "Running golangci-lint..."
$(GOLINT) run ./...
# Format code
fmt:
@echo "Formatting code..."
$(GOFMT) -s -w .
@echo "Code formatted"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BINARY_DIR)
@rm -rf $(COVERAGE_DIR)
$(GOCLEAN)
@echo "Clean complete"
# Tidy dependencies
tidy:
@echo "Tidying dependencies..."
$(GOMOD) tidy
@echo "Dependencies tidied"
# Run database migrations up
migrate-up:
@echo "Running migrations up..."
@if [ ! -d "$(MIGRATIONS_DIR)" ]; then \
echo "Error: Migrations directory not found at $(MIGRATIONS_DIR)"; \
exit 1; \
fi
@$(GOCMD) run ./cmd/cortex migrate up
@echo "Migrations applied"
# Rollback database migrations
migrate-down:
@echo "Rolling back migrations..."
@if [ ! -d "$(MIGRATIONS_DIR)" ]; then \
echo "Error: Migrations directory not found at $(MIGRATIONS_DIR)"; \
exit 1; \
fi
@$(GOCMD) run ./cmd/cortex migrate down
@echo "Migrations rolled back"
# Build Docker image
docker-build:
@echo "Building Docker image..."
@if [ ! -f "Dockerfile" ]; then \
echo "Error: Dockerfile not found"; \
exit 1; \
fi
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
@echo "Docker image built: $(DOCKER_IMAGE):$(DOCKER_TAG)"
# Install binary to GOPATH/bin
install:
@echo "Installing $(BINARY_NAME) to GOPATH/bin..."
$(GOCMD) install ./cmd/cortex
@echo "Installation complete"
# Development targets
dev: build run
# Watch for changes and rebuild (requires: go install github.com/cosmtrek/air@latest)
watch:
@which air > /dev/null || (echo "Error: air not found. Install with: go install github.com/cosmtrek/air@latest" && exit 1)
air
# Security scan
security:
@echo "Running security scan..."
@govulncheck ./... || echo "govulncheck not installed. Run: go install golang.org/x/vuln/cmd/govulncheck@latest"
# Generate mocks for testing
generate-mocks:
@echo "Generating mocks..."
$(GOCMD) generate ./...
@echo "Mocks generated"