-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
171 lines (137 loc) · 5.67 KB
/
Makefile
File metadata and controls
171 lines (137 loc) · 5.67 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
SHELL := /usr/bin/env bash
# Build variables
BINARY_NAME := kaptn-server
BUILD_DIR := bin
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.1.0-dev")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GO_VERSION := $(shell go version | cut -d ' ' -f 3)
# Go build flags
LDFLAGS := -X github.com/aaronlmathis/kaptn/internal/version.Version=$(VERSION) \
-X github.com/aaronlmathis/kaptn/internal/version.GitCommit=$(GIT_COMMIT) \
-X github.com/aaronlmathis/kaptn/internal/version.BuildDate=$(BUILD_DATE)
.PHONY: all dev fmt lint lint-go test frontend backend build docker docker-debug kind-up kind-down clean help push push-debug run
all: build ## Build everything
dev: ## Run backend in development mode with hot reload
@echo "Starting development server..."
@go run -race -ldflags "$(LDFLAGS)" ./cmd/server --config=config.authdev.yaml &
@echo "Backend PID: $$!"
@echo "Starting frontend development server..."
@cd frontend && npm run dev
fmt: ## Format code
@echo "Formatting Go code..."
@go fmt ./...
@echo "Formatting frontend code..."
@cd frontend && npm run format 2>/dev/null || echo "No format script found"
lint: ## Lint code
@echo "Linting Go code..."
@go vet ./...
@echo "Linting frontend code..."
@cd frontend && npm run lint 2>/dev/null || echo "No lint script found"
lint-go: ## Lint Go code
@echo "Linting Go code..."
@go vet ./...
lint-fix: ## Fix linting issues
@echo "Fixing Go formatting..."
@go fmt ./...
@echo "Fixing frontend linting issues..."
@cd frontend && npm run lint:fix 2>/dev/null || echo "No lint:fix script found"
type-check: ## Check TypeScript types
@echo "Checking TypeScript types..."
@cd frontend && npm run type-check
test: ## Run tests
@echo "Running Go tests..."
@go test ./... -race -count=1 -v
@echo "Running frontend tests..."
@cd frontend && npm run test:run 2>/dev/null || echo "No test script found"
test-go: ## Run only Go tests
@echo "Running Go tests..."
@go test ./... -race -count=1 -v
test-frontend: ## Run only frontend tests
@echo "Running frontend unit tests..."
@cd frontend && npm run test:run
test-e2e: ## Run end-to-end tests
@echo "Running E2E tests..."
@cd frontend && npm run test:e2e
test-coverage: ## Run tests with coverage
@echo "Running Go tests with coverage..."
@go test ./... -race -count=1 -coverprofile=coverage.out
@go tool cover -html=coverage.out -o coverage.html
@echo "Running frontend tests with coverage..."
@cd frontend && npm run test:coverage
test-watch: ## Run frontend tests in watch mode
@echo "Running frontend tests in watch mode..."
@cd frontend && npm run test:watch
frontend: ## Build frontend
@echo "Building frontend..."
@cd frontend && npm ci && KAPTN_BUILD_AUTH_MODE=none npm run build
@echo "Frontend built successfully"
backend: ## Build backend binary
@echo "Building backend..."
@mkdir -p $(BUILD_DIR)
@CGO_ENABLED=1 go build -race -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/server
@echo "Backend binary built: $(BUILD_DIR)/$(BINARY_NAME)"
build: frontend ## Build backend binary (embeds frontend)
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
@CGO_ENABLED=1 go build -race -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/server
@echo "Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
run: build ## Run the built binary
@echo "Running $(BINARY_NAME)..."
@$(BUILD_DIR)/$(BINARY_NAME) --config=config.dev.yaml
.PHONY: start stop restart
start: ## Start server via kaptn-ctl.sh (CONFIG=<file> overrides)
@BIN=$(BUILD_DIR)/$(BINARY_NAME) CONFIG=$(CONFIG) ./scripts/kaptn-ctl.sh start
stop: ## Stop server via kaptn-ctl.sh
@./scripts/kaptn-ctl.sh stop
restart: ## Restart server via kaptn-ctl.sh (CONFIG=<file> overrides)
@CONFIG=$(CONFIG) ./scripts/kaptn-ctl.sh restart
IMAGE_NAME := aaronlmathis/kaptn
docker: frontend ## Build Docker image
@echo "Building Docker image..."
@docker build \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
-t $(IMAGE_NAME):$(VERSION) .
@docker tag $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):latest
@echo "Docker image built: $(IMAGE_NAME):$(VERSION)"
docker-debug: frontend
@echo "Building Docker debug image (with shell)..."
@docker build \
--target debug \
--no-cache \
--build-arg VERSION=debug \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
-t $(IMAGE_NAME):debug .
@echo "Docker debug image built: $(IMAGE_NAME):debug"
push: docker ## Push Docker image to registry
@echo "Pushing Docker image..."
@docker push $(IMAGE_NAME):$(VERSION)
@docker push $(IMAGE_NAME):latest
push-debug: docker-debug ## Push Docker debug image to registry
@echo "Pushing Docker debug image..."
@docker push $(IMAGE_NAME):debug
kind-up: ## Create Kind cluster for development
@echo "Creating Kind cluster..."
@kind create cluster --name kaptn-dev --wait 300s
@echo "Kind cluster 'kaptn-dev' created"
kind-down: ## Delete Kind cluster
@echo "Deleting Kind cluster..."
@kind delete cluster --name kaptn-dev
@echo "Kind cluster 'kaptn-dev' deleted"
install-deps: ## Install all dependencies
@echo "Installing Go dependencies..."
@go mod download
@echo "Installing frontend dependencies..."
@cd frontend && npm install
@echo "Dependencies installed"
help: ## Show this help
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-15s %s\n", $$1, $$2}'
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@cd frontend && rm -rf dist node_modules/.vite 2>/dev/null || true
@echo "Clean complete"