-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (110 loc) · 3.91 KB
/
Copy pathMakefile
File metadata and controls
133 lines (110 loc) · 3.91 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
# Copyright The Linux Foundation and each contributor to LFX.
# SPDX-License-Identifier: MIT
.PHONY: all build clean check fmt vet lint test test-coverage run help deps install-tools docker-build ko-build megalinter
# Build variables
BINARY_NAME=lfx-mcp-server
CMD_DIR=./cmd/lfx-mcp-server
BUILD_DIR=./bin
GO_FILES=$(shell find . -name "*.go" -type f)
# Version string: clean tag on a tagged commit, tag+offset+hash between tags,
# with a -dirty suffix if there are uncommitted changes.
VERSION := $(shell git describe --tags --dirty --always 2>/dev/null || echo "dev")
# Build flags
LDFLAGS=-ldflags="-s -w -X main.Version=$(VERSION)"
# Docker/ko variables
DOCKER_IMAGE=linuxfoundation/lfx-mcp/lfx-mcp-server
DOCKER_TAG=local
# Default target
all: clean check build
# Build the binary
build: $(BUILD_DIR)/$(BINARY_NAME)
$(BUILD_DIR)/$(BINARY_NAME): $(GO_FILES)
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(CMD_DIR)
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
# Run all checks
check: fmt vet lint revive
# Format Go code
fmt:
@echo "Formatting Go code..."
go fmt ./...
# Run go vet
vet:
@echo "Running go vet..."
go vet ./...
# Run golangci-lint (if available)
lint:
@echo "Running linters..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not installed, skipping..."; \
fi
# Run revive (if available)
revive:
@echo "Running revive..."
@if command -v revive >/dev/null 2>&1; then \
revive ./...; \
else \
echo "revive not installed, skipping..."; \
fi
# Run tests
test:
@echo "Running tests..."
go test -v ./...
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
# Run the server in stdio mode
run: build
@echo "Starting LFX MCP Server..."
$(BUILD_DIR)/$(BINARY_NAME) stdio
# Download dependencies
deps:
@echo "Downloading dependencies..."
go mod download
go mod tidy
# Install development tools
install-tools:
@echo "Installing development tools..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Build Docker image
docker-build:
@echo "Building Docker image..."
docker build --build-arg VERSION=$(VERSION) -t $(DOCKER_IMAGE):$(DOCKER_TAG) -f Dockerfile .
@echo "Docker image built: $(DOCKER_IMAGE):$(DOCKER_TAG)"
# Build ko image locally: loads into local Docker daemon with a :local tag, matching docker-build.
# KO_DOCKER_REPO is the parent path; ko appends the binary name to produce the full image name.
# VERSION is exported so the .ko.yaml {{.Env.VERSION}} template resolves correctly.
ko-build:
@echo "Building ko image..."
KO_DOCKER_REPO=$(DOCKER_IMAGE) VERSION=$(VERSION) ko build -L --bare --tags local ./cmd/lfx-mcp-server
# Run MegaLinter locally via Docker (matches CI Go flavor at v9).
megalinter:
docker pull oxsecurity/megalinter-go:v9
docker run --rm --platform linux/amd64 -v '$(CURDIR):/tmp/lint:rw' oxsecurity/megalinter-go:v9
# Show help
help:
@echo "Available targets:"
@echo " all - Clean, check, and build (default)"
@echo " build - Build the binary"
@echo " clean - Clean build artifacts"
@echo " check - Run all code quality checks"
@echo " fmt - Format Go code"
@echo " vet - Run go vet"
@echo " lint - Run golangci-lint"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " run - Build and run the server"
@echo " deps - Download and tidy dependencies"
@echo " install-tools - Install development tools"
@echo " docker-build - Build Docker image"
@echo " ko-build - Build ko image locally with :local tag"
@echo " megalinter - Run MegaLinter locally via Docker"
@echo " help - Show this help message"