-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (117 loc) · 4.32 KB
/
Copy pathMakefile
File metadata and controls
140 lines (117 loc) · 4.32 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
.PHONY: all build install uninstall clean test eval eval-offline tidy fmt vet lint deps help release release-all
# Primary binary name (standalone CLI)
BINARY_NAME=cococtl
# kubectl plugin binary name (symlinked from BINARY_NAME during install)
KUBECTL_PLUGIN_NAME=kubectl-coco
# Installation path
INSTALL_PATH=/usr/local/bin
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Test parameters
TEST?=.
# Version from git
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
# Build flags
LDFLAGS=-ldflags "-s -w -X github.com/confidential-devhub/cococtl/cmd.version=$(VERSION)"
# Release parameters
GOOS?=$(shell go env GOOS)
GOARCH?=$(shell go env GOARCH)
RELEASE_DIR=release
RELEASE_BINARY=$(BINARY_NAME)-$(GOOS)-$(GOARCH)
# Default target
all: build
## build: Build the cococtl binary
build:
@echo "Building $(BINARY_NAME) (version: $(VERSION))..."
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) .
@echo "Build complete: $(BINARY_NAME)"
## install: Install cococtl and kubectl-coco symlink to $(INSTALL_PATH)
install: build
@echo "Installing $(BINARY_NAME) to $(INSTALL_PATH)..."
@mkdir -p $(INSTALL_PATH)
@cp $(BINARY_NAME) $(INSTALL_PATH)/
@chmod +x $(INSTALL_PATH)/$(BINARY_NAME)
@ln -sf $(INSTALL_PATH)/$(BINARY_NAME) $(INSTALL_PATH)/$(KUBECTL_PLUGIN_NAME)
@ln -sf $(INSTALL_PATH)/$(BINARY_NAME) $(INSTALL_PATH)/kubectl_complete-coco
@echo "Installation complete."
@echo " Standalone CLI : $(BINARY_NAME)"
@echo " kubectl plugin : kubectl coco (via $(KUBECTL_PLUGIN_NAME) symlink)"
## uninstall: Remove cococtl, kubectl-coco, and completion symlink from $(INSTALL_PATH)
uninstall:
@echo "Uninstalling $(BINARY_NAME)..."
@rm -f $(INSTALL_PATH)/$(BINARY_NAME)
@rm -f $(INSTALL_PATH)/$(KUBECTL_PLUGIN_NAME)
@rm -f $(INSTALL_PATH)/kubectl_complete-coco
@echo "Uninstall complete"
## clean: Remove build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
@rm -f $(BINARY_NAME)
@rm -f coverage.out coverage.html
@rm -rf $(RELEASE_DIR)
@echo "Clean complete"
## test: Run all tests (use TEST=<regex> to filter, e.g., make test TEST=TestConfig)
test:
@echo "Running tests (filter: $(TEST))..."
$(GOTEST) -v -run $(TEST) ./cmd/... ./integration_test/...
## eval-offline: Run Tier 1 eval (no cluster required)
eval-offline: build
@echo "Running offline eval..."
$(GOTEST) -v -run TestEvalOffline ./eval/...
## eval: Run full eval scorecard (Tier 1 offline + Tier 2 cluster)
eval: build
@echo "Running full eval..."
$(GOTEST) -v -run TestEval ./eval/...
## tidy: Tidy go modules
tidy:
@echo "Tidying go modules..."
$(GOMOD) tidy
## fmt: Format Go code
fmt:
@echo "Formatting code..."
$(GOCMD) fmt ./...
## vet: Run go vet
vet:
@echo "Running go vet..."
$(GOCMD) vet ./...
## lint: Run golangci-lint
lint:
@echo "Running golangci-lint..."
@which golangci-lint > /dev/null || (echo "golangci-lint not found. Install it from https://golangci-lint.run/usage/install/" && exit 1)
golangci-lint run ./...
## deps: Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOGET) -v ./...
$(GOMOD) download
## help: Show this help message
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@sed -n 's/^##//p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /'
## release: Build static binary for specific OS/ARCH (use GOOS and GOARCH env vars)
release:
@echo "Building release binary for $(GOOS)/$(GOARCH) (version: $(VERSION))..."
@mkdir -p $(RELEASE_DIR)
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -ldflags "-s -w -extldflags=-static -X github.com/confidential-devhub/cococtl/cmd.version=$(VERSION)" -o $(RELEASE_DIR)/$(RELEASE_BINARY) .
@chmod +x $(RELEASE_DIR)/$(RELEASE_BINARY)
@cd $(RELEASE_DIR) && sha256sum $(RELEASE_BINARY) > $(RELEASE_BINARY).sha256
@echo "Release binary created: $(RELEASE_DIR)/$(RELEASE_BINARY)"
@echo "Checksum: $(RELEASE_DIR)/$(RELEASE_BINARY).sha256"
## release-all: Build release binaries for all supported platforms
release-all: clean
@echo "Building release binaries for all platforms..."
@$(MAKE) release GOOS=linux GOARCH=amd64
@$(MAKE) release GOOS=linux GOARCH=ppc64le
@$(MAKE) release GOOS=linux GOARCH=s390x
@$(MAKE) release GOOS=darwin GOARCH=amd64
@$(MAKE) release GOOS=darwin GOARCH=arm64
@echo "All release binaries created in $(RELEASE_DIR)/"
@ls -lh $(RELEASE_DIR)/