-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
69 lines (52 loc) · 1.68 KB
/
Makefile
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
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
BIN := contour-admission-webhook
VERSION := $(shell git describe --exact-match 2>/dev/null || basename $$(git describe --all --long 2>/dev/null))
GO_BUILD_LDFLAGS := \
-s \
-w
# Image URL to use all building/pushing image targets
IMG ?= $(BIN):$(VERSION)
## Tool Binaries
ENVTEST ?= $(LOCALBIN)/setup-envtest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.0
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
all: build
test: check
.PHONY: check
check: fmt vet lint envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
.PHONY: build
build: fmt vet lint
go build -mod=readonly -ldflags "$(GO_BUILD_LDFLAGS)" -a -o bin/$(BIN) cmd/main.go
.PHONY: fmt
fmt:
go fmt -mod=readonly ./...
.PHONY: vet
vet:
go vet -mod=readonly -ldflags "$(GO_BUILD_LDFLAGS)" ./...
.PHONY: lint
lint:
go run github.com/golangci/golangci-lint/cmd/[email protected] run -v --exclude-use-default=false
.PHONY: docker-build
docker-build:
docker build -t ${IMG} -f Dockerfile .
.PHONY: docker-push
docker-push:
docker push ${IMG}
.PHONY: clean
clean:
@rm -rf cover.out
@rm -rf bin