-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
84 lines (66 loc) · 2.6 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
IMAGE ?= volsync-addon-controller
IMAGE_REGISTRY ?= quay.io/tflower
IMAGE_TAG ?= latest
IMG ?= $(IMAGE_REGISTRY)/$(IMAGE):$(IMAGE_TAG)
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
# Helper software versions
GOLANGCI_VERSION := v1.60.3
ENVTEST_K8S_VERSION = 1.30
GO_LD_EXTRAFLAGS ?=
SOURCE_GIT_TAG ?=$(shell git describe --long --tags --abbrev=7 --match 'v[0-9]*' || echo 'v0.0.0-unknown')
SOURCE_GIT_COMMIT ?=$(shell git rev-parse --short "HEAD^{commit}" 2>/dev/null)
DIRTY ?= $(shell git diff --quiet || echo '-dirty')
ifndef GIT_VERSION
GIT_VERSION = $(SOURCE_GIT_TAG)$(DIRTY)
endif
ifndef GIT_COMMIT
GIT_COMMIT = $(SOURCE_GIT_COMMIT)$(DIRTY)
endif
define version-ldflags
-X main.versionFromGit=$(GIT_VERSION) \
-X main.commitFromGit=$(GIT_COMMIT)
endef
GO_LD_FLAGS ?="$(call version-ldflags) $(GO_LD_EXTRAFLAGS)"
.PHONY: docker-build
docker-build: test ## Build docker image
docker build --build-arg "versionFromGit_arg=$(GIT_VERSION)" --build-arg "commitFromGit_arg=$(GIT_COMMIT)" -t ${IMG} .
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
## Location to install dependencies to
LOCALBIN ?= $(PROJECT_DIR)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
.PHONY: test
TEST_ARGS ?= -show-node-events -randomize-all -randomize-suites -poll-progress-after=30s -cover -coverprofile=cover.out -output-dir=.
TEST_PACKAGES ?= ./...
test: goversion lint envtest ginkgo ## Run tests.
-rm -f cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GINKGO) $(TEST_ARGS) $(TEST_PACKAGES)
.PHONY: goversion
goversion: ## Just print out go version being used
go version
.PHONY: lint
lint: goversion golangci-lint ## Lint source code
$(GOLANGCILINT) run --timeout 4m0s ./...
.PHONY: golangci-lint
GOLANGCILINT := $(LOCALBIN)/golangci-lint
GOLANGCI_URL := https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
golangci-lint: $(GOLANGCILINT) ## Download golangci-lint
$(GOLANGCILINT): $(LOCALBIN)
curl -sSfL $(GOLANGCI_URL) | sh -s -- -b $(LOCALBIN) $(GOLANGCI_VERSION)
.PHONY: envtest
ENVTEST = $(LOCALBIN)/setup-envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
.PHONY: ginkgo
GINKGO := $(LOCALBIN)/ginkgo
ginkgo: $(GINKGO) ## Download ginkgo
$(GINKGO): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo@latest
.PHONY: build
build:
GO111MODULE=on go build -a -o bin/controller -ldflags $(GO_LD_FLAGS) main.go