-
Notifications
You must be signed in to change notification settings - Fork 270
/
Makefile
81 lines (68 loc) · 2.5 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
.PHONY: default
default: build
GOOS=linux
GOARCH?=$(shell go env GOARCH)
GIT_REPO=$(shell git config --get remote.origin.url)
GIT_COMMIT=git-$(shell git rev-parse --short HEAD)
VERSION_PKG=github.com/jcmoraisjr/haproxy-ingress/pkg/version
CONTROLLER_FLAGS=-X $(VERSION_PKG).RELEASE=local -X $(VERSION_PKG).COMMIT=$(GIT_COMMIT) -X $(VERSION_PKG).REPO=$(GIT_REPO)
CONTROLLER_TAG?=localhost/haproxy-ingress:latest
LOCAL_FS_PREFIX?=/tmp/haproxy-ingress
KUBECONFIG?=$(HOME)/.kube/config
CONTROLLER_CONFIGMAP?=
CONTROLLER_ARGS?=
LOCALBIN?=$(shell pwd)/bin
LOCAL_GOTESTSUM=$(LOCALBIN)/gotestsum
LOCAL_GOLANGCI_LINT=$(LOCALBIN)/golangci-lint
LOCAL_SETUP_ENVTEST=$(LOCALBIN)/setup-envtest
.PHONY: build
build:
CGO_ENABLED=0 go build \
-v -installsuffix cgo \
-ldflags "-s -w $(CONTROLLER_FLAGS)" \
-o bin/controller pkg/main.go
.PHONY: run
run: build
@rm -rf $(LOCAL_FS_PREFIX)/var/run/haproxy/
@mkdir -p $(LOCAL_FS_PREFIX)/etc/haproxy/lua/
@cp rootfs/etc/lua/* $(LOCAL_FS_PREFIX)/etc/haproxy/lua/
./bin/controller \
--kubeconfig=$(KUBECONFIG)\
--local-filesystem-prefix=$(LOCAL_FS_PREFIX)\
--update-status=false\
--configmap=$(CONTROLLER_CONFIGMAP)\
$(CONTROLLER_ARGS)
.PHONY: gotestsum
gotestsum:
test -x $(LOCAL_GOTESTSUM) || GOBIN=$(LOCALBIN) go install gotest.tools/gotestsum@latest
.PHONY: test
test: gotestsum
## fix race and add -race param
$(LOCAL_GOTESTSUM) --format=testname -- -tags=cgo ./pkg/...
.PHONY: golangci-lint
golangci-lint:
test -x $(LOCAL_GOLANGCI_LINT) || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
.PHONY: lint
lint: golangci-lint
$(LOCAL_GOLANGCI_LINT) run --verbose
.PHONY: setup-envtest
setup-envtest:
test -x $(LOCAL_SETUP_ENVTEST) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
$(LOCAL_SETUP_ENVTEST) use 1.30.0 --bin-dir $(LOCALBIN)
.PHONY: test-integration
test-integration: gotestsum setup-envtest
KUBEBUILDER_ASSETS="$(shell $(LOCAL_SETUP_ENVTEST) use 1.30.0 --bin-dir $(LOCALBIN) -i -p path)"\
$(LOCAL_GOTESTSUM) --format=testname -- -count=1 -tags=cgo ./tests/integration/...
.PHONY: linux-build
linux-build:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-v -installsuffix cgo \
-ldflags "-s -w $(CONTROLLER_FLAGS)" \
-o rootfs/haproxy-ingress-controller pkg/main.go
.PHONY: image
image: linux-build
docker build -t $(CONTROLLER_TAG) rootfs
.PHONY: docker-build
docker-build:
@rm -f rootfs/haproxy-ingress-controller
docker build -t $(CONTROLLER_TAG) . -f builder/Dockerfile