forked from opendatahub-io/odh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
137 lines (116 loc) · 4.07 KB
/
Makefile
File metadata and controls
137 lines (116 loc) · 4.07 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
# kubectl-odh CLI Makefile
# Binary name
BINARY_NAME=bin/kubectl-odh
# 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 = -X 'github.com/lburgazzoli/odh-cli/internal/version.Version=$(VERSION)' \
-X 'github.com/lburgazzoli/odh-cli/internal/version.Commit=$(COMMIT)' \
-X 'github.com/lburgazzoli/odh-cli/internal/version.Date=$(DATE)'
# Linter configuration
LINT_TIMEOUT := 10m
# Container registry configuration
CONTAINER_REGISTRY ?= quay.io
CONTAINER_REPO ?= $(CONTAINER_REGISTRY)/lburgazzoli/odh-cli
CONTAINER_PLATFORMS ?= linux/amd64,linux/arm64
CONTAINER_TAGS ?= $(VERSION)
# Platform for cross-compilation (defaults to current platform)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
## Tools
GOLANGCI_VERSION ?= v2.8.0
GOLANGCI ?= go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_VERSION)
GOVULNCHECK_VERSION ?= latest
GOVULNCHECK ?= go run golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION)
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
# Build the binary
.PHONY: build
build:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) \
go build -ldflags "$(LDFLAGS)" -o $(BINARY_NAME) cmd/main.go
# Run the doctor command
.PHONY: run
run:
go run -ldflags "$(LDFLAGS)" cmd/main.go doctor
# Tidy up dependencies
.PHONY: tidy
tidy:
go mod tidy
# Clean build artifacts
.PHONY: clean
clean:
rm -f $(BINARY_NAME)
go clean -x
go clean -x -testcache
# Format code
.PHONY: fmt
fmt:
@$(GOLANGCI) fmt --config .golangci.yml
go fmt ./...
# Run linter
.PHONY: lint
lint:
@$(GOLANGCI) run --config .golangci.yml --timeout $(LINT_TIMEOUT)
# Run linter with auto-fix
.PHONY: lint/fix
lint/fix:
@$(GOLANGCI) run --config .golangci.yml --timeout $(LINT_TIMEOUT) --fix
# Run vulnerability check
.PHONY: vulncheck
vulncheck:
@$(GOVULNCHECK) ./...
# Run all checks
.PHONY: check
check: lint vulncheck
# Run tests
.PHONY: test
test:
go test ./...
# Build container image without pushing (creates local manifest)
.PHONY: build-image
build-image:
@echo "Building container image for platforms: $(CONTAINER_PLATFORMS)"
@MANIFEST_NAME="localhost/odh-cli:$(VERSION)"; \
podman build \
--platform=$(CONTAINER_PLATFORMS) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(COMMIT) \
--build-arg DATE=$(DATE) \
--manifest=$$MANIFEST_NAME \
.
@echo "Container image built successfully: localhost/odh-cli:$(VERSION)"
@echo "To inspect the manifest: podman manifest inspect localhost/odh-cli:$(VERSION)"
@echo "To run: podman run --rm localhost/odh-cli:$(VERSION) version"
# Build and push container image using Podman manifest
.PHONY: publish
publish: build-image
@echo "Pushing container image to $(CONTAINER_REPO):$(CONTAINER_TAGS)"
@MANIFEST_NAME="localhost/odh-cli:$(VERSION)"; \
TAGS="$(CONTAINER_TAGS)"; \
for tag in $${TAGS//,/ }; do \
podman manifest push $$MANIFEST_NAME docker://$(CONTAINER_REPO):$$tag; \
done; \
podman manifest rm $$MANIFEST_NAME 2>/dev/null || true
@echo "Container image published successfully"
# Help target
.PHONY: help
help:
@echo "Available targets:"
@echo " build - Build the kubectl-odh binary"
@echo " build-image - Build container image without pushing (creates local manifest)"
@echo " publish - Build and push container image using Podman manifest"
@echo " run - Run the doctor command"
@echo " tidy - Tidy up Go module dependencies"
@echo " clean - Remove build artifacts and test cache"
@echo " fmt - Format Go code"
@echo " lint - Run golangci-lint"
@echo " lint/fix - Run golangci-lint with auto-fix"
@echo " vulncheck - Run vulnerability scanner"
@echo " check - Run all checks (lint + vulncheck)"
@echo " test - Run tests"
@echo " help - Show this help message"