-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (119 loc) · 4.47 KB
/
Makefile
File metadata and controls
142 lines (119 loc) · 4.47 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
.DEFAULT_GOAL := help
include .bingo/Variables.mk
CGO_ENABLED ?= 0
GO ?= go
BINARY_NAME := hyperfleet-credential-provider
BUILD_DIR := bin
MAIN_PATH := cmd/provider/main.go
GIT_SHA ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_DIRTY ?= $(shell git diff --quiet 2>/dev/null || echo "-dirty")
VERSION ?= $(GIT_SHA)$(GIT_DIRTY)
COMMIT ?= $(GIT_SHA)
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
container_tool ?= podman
IMAGE_REGISTRY ?= quay.io/openshift-hyperfleet
IMAGE_NAME ?= hyperfleet-credential-provider
IMAGE_TAG ?= latest
QUAY_USER ?=
DEV_TAG ?= dev-$(GIT_SHA)
LDFLAGS := -ldflags "-X github.com/openshift-hyperfleet/hyperfleet-credential-provider/cmd/provider/version.Version=$(VERSION) -X github.com/openshift-hyperfleet/hyperfleet-credential-provider/cmd/provider/version.Commit=$(COMMIT) -X github.com/openshift-hyperfleet/hyperfleet-credential-provider/cmd/provider/version.BuildTime=$(BUILD_TIME)"
help:
@echo ""
@echo "HyperFleet Credential Provider - Multi-cloud Kubernetes Token Provider"
@echo ""
@echo "make build compile binary to bin/"
@echo "make test run unit tests"
@echo "make test-integration run integration tests"
@echo "make lint run golangci-lint"
@echo "make fmt format code"
@echo "make clean delete build artifacts"
@echo "make image build container image"
@echo "make image-push build and push container image"
@echo "make image-dev build and push to personal Quay registry"
@echo "make scan run security vulnerability scan"
.PHONY: help
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
@echo "Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
.PHONY: build
test:
@echo "Running unit tests..."
$(GO) test -v -race -coverprofile=coverage.out ./pkg/... ./internal/... ./cmd/...
.PHONY: test
test-integration:
@echo "Running integration tests..."
$(GO) test -v -tags=integration -timeout=30m ./test/integration/...
.PHONY: test-integration
coverage: test
@echo "Generating coverage report..."
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
.PHONY: coverage
lint: $(GOLANGCI_LINT)
@echo "Running golangci-lint..."
GOLANGCI_LINT_CACHE=$${HOME}/.cache/golangci-lint GOCACHE=$${HOME}/.cache/go-build GOMODCACHE=$${HOME}/go/pkg/mod $(GOLANGCI_LINT) run
.PHONY: lint
fmt:
@echo "Formatting code..."
$(GO) fmt ./...
.PHONY: fmt
vet:
@echo "Running go vet..."
$(GO) vet ./...
.PHONY: vet
clean:
@echo "Cleaning..."
@rm -rf $(BUILD_DIR) coverage.out coverage.html
.PHONY: clean
deps:
@echo "Downloading dependencies..."
$(GO) mod download
$(GO) mod tidy
.PHONY: deps
image:
@echo "Building container image $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)..."
$(container_tool) build \
--platform linux/amd64 \
--build-arg GIT_SHA=$(GIT_SHA) \
--build-arg GIT_DIRTY=$(GIT_DIRTY) \
-t $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) .
@echo "✅ Image built: $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)"
.PHONY: image
image-push: image
@echo "Pushing image $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)..."
$(container_tool) push $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
@echo "✅ Image pushed: $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)"
.PHONY: image-push
image-dev:
ifndef QUAY_USER
@echo "❌ ERROR: QUAY_USER is not set"
@echo ""
@echo "Usage: QUAY_USER=myuser make image-dev"
@echo ""
@echo "This will build and push to: quay.io/$$QUAY_USER/$(IMAGE_NAME):$(DEV_TAG)"
@exit 1
endif
@echo "Building dev image quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG)..."
$(container_tool) build \
--platform linux/amd64 \
--build-arg BASE_IMAGE=alpine:3.21 \
--build-arg GIT_SHA=$(GIT_SHA) \
--build-arg GIT_DIRTY=$(GIT_DIRTY) \
-t quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG) .
@echo "Pushing dev image..."
$(container_tool) push quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG)
@echo ""
@echo "✅ Dev image pushed: quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG)"
.PHONY: image-dev
image-test: image
@echo "Testing container image..."
$(container_tool) run --rm $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) version
@echo "✅ Container image test passed"
.PHONY: image-test
scan:
@echo "Running security vulnerability scan..."
@which govulncheck > /dev/null || $(GO) install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
.PHONY: scan