-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
153 lines (122 loc) · 4.85 KB
/
Makefile
File metadata and controls
153 lines (122 loc) · 4.85 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
# Spotter - Kubernetes Security Scanner
# Simple OSS-standard Makefile
.DEFAULT_GOAL := help
# Variables
APP_NAME := spotter
REGISTRY := ghcr.io
NAMESPACE := madhuakula
IMAGE := $(REGISTRY)/$(NAMESPACE)/$(APP_NAME)
# Version information
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Build flags
LDFLAGS := -s -w \
-X github.com/$(NAMESPACE)/$(APP_NAME)/pkg/version.Version=$(VERSION) \
-X github.com/$(NAMESPACE)/$(APP_NAME)/pkg/version.Commit=$(COMMIT) \
-X github.com/$(NAMESPACE)/$(APP_NAME)/pkg/version.Date=$(DATE)
# Build environment
CGO_ENABLED := 0
GOOS := linux
GOARCH := amd64
.PHONY: help build test clean lint fmt vet deps image push run install uninstall
help: ## Show this help message
@echo "Spotter - Kubernetes Security Scanner"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
build: ## Build the binary
@echo "Building $(APP_NAME)..."
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \
go build -ldflags="$(LDFLAGS)" -o bin/$(APP_NAME) .
test: ## Run tests
@echo "Running tests..."
go test -v -race -coverprofile=coverage.out ./...
test-coverage: test ## Run tests and show coverage
@echo "Coverage report:"
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
clean: ## Clean build artifacts
@echo "Cleaning..."
rm -rf bin/ dist/ coverage.out coverage.html
lint: ## Run golangci-lint
@echo "Running linter..."
$(shell go env GOPATH)/bin/golangci-lint run ./...
fmt: ## Format code
@echo "Formatting code..."
go fmt ./...
vet: ## Run go vet
@echo "Running go vet..."
go vet ./...
deps: ## Download dependencies
@echo "Downloading dependencies..."
go mod download
go mod tidy
image: ## Build container image
@echo "Building container image $(IMAGE):$(VERSION)..."
docker build \
--build-arg ENABLE_VERSIONING=true \
-t $(IMAGE):$(VERSION) \
-t $(IMAGE):latest \
.
push: image ## Build and push container image
@echo "Pushing container image..."
docker push $(IMAGE):$(VERSION)
docker push $(IMAGE):latest
run: build ## Build and run the application
@echo "Running $(APP_NAME)..."
./bin/$(APP_NAME)
install: build ## Install binary to GOPATH/bin
@echo "Installing $(APP_NAME)..."
cp bin/$(APP_NAME) $(GOPATH)/bin/$(APP_NAME)
uninstall: ## Remove binary from GOPATH/bin
@echo "Uninstalling $(APP_NAME)..."
rm -f $(GOPATH)/bin/$(APP_NAME)
# Development targets
dev-setup: deps ## Setup development environment
@echo "Setting up development environment..."
@which golangci-lint >/dev/null || (echo "Installing golangci-lint..." && \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin)
@which goreleaser >/dev/null || (echo "Installing goreleaser..." && \
go install github.com/goreleaser/goreleaser@latest)
check: fmt vet lint test ## Run all checks (format, vet, lint, test)
release: check ## Run checks and build release artifacts
@echo "Creating release..."
$(shell go env GOPATH)/bin/goreleaser release --clean
release-snapshot: check ## Create snapshot release
@echo "Creating snapshot release..."
$(shell go env GOPATH)/bin/goreleaser release --snapshot --clean
# Local development with kind
kind-setup: ## Setup local kind cluster for testing
@echo "Setting up kind cluster..."
@if ! kind get clusters | grep -q spotter-test; then \
kind create cluster --name spotter-test; \
fi
kind-load: image ## Load image into kind cluster
@echo "Loading image into kind cluster..."
docker tag $(IMAGE):$(VERSION) spotter:latest
docker save spotter:latest | kind load image-archive --name spotter-test /dev/stdin
kind-deploy: kind-load ## Deploy to kind cluster
@echo "Deploying to kind cluster..."
cd deployments/admission-controller && \
./generate-local-certs.sh && \
kubectl apply -f local-webhook.yaml && \
kubectl apply -f local-deployment.yaml && \
kubectl rollout restart deployment spotter-admission-controller -n spotter-system && \
kubectl wait --for=condition=ready pod -l app=spotter-admission-controller -n spotter-system --timeout=15s
kind-test: kind-deploy ## Run tests in kind cluster
@echo "Running tests in kind cluster..."
kubectl create namespace test-spotter --dry-run=client -o yaml | kubectl apply -f -
@echo "Testing complete. Check with: kubectl get pods -n test-spotter"
kind-clean: ## Clean up kind cluster
@echo "Cleaning up kind cluster..."
kind delete cluster --name spotter-test
# Print build info
info: ## Show build information
@echo "Application: $(APP_NAME)"
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Date: $(DATE)"
@echo "Image: $(IMAGE):$(VERSION)"