forked from apalia/cloudstack-csi-driver
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
88 lines (66 loc) · 2.62 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
85
86
87
88
CMDS=cloudstack-csi-driver cloudstack-csi-sc-syncer
PKG=github.com/leaseweb/cloudstack-csi-driver
# Revision that gets built into each binary via the main.version
# string. Uses the `git describe` output based on the most recent
# version tag with a short revision suffix or, if nothing has been
# tagged yet, just the revision.
#
# Beware that tags may also be missing in shallow clones as done by
# some CI systems (like TravisCI, which pulls only 50 commits).
REV=$(shell git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
GIT_COMMIT?=$(shell git rev-parse HEAD)
BUILD_DATE?=$(shell date -u -Iseconds)
DOCKER?=docker
IMPORTPATH_LDFLAGS = -X ${PKG}/pkg/driver.driverVersion=$(REV) -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}
LDFLAGS = -s -w
FULL_LDFLAGS = $(LDFLAGS) $(IMPORTPATH_LDFLAGS)
export REPO_ROOT := $(shell git rev-parse --show-toplevel)
# Directories
TOOLS_DIR := $(REPO_ROOT)/hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
BIN_DIR ?= bin
GO_INSTALL := ./hack/go_install.sh
MOCKGEN_BIN := mockgen
MOCKGEN_VER := v0.5.0
MOCKGEN := $(abspath $(TOOLS_BIN_DIR)/$(MOCKGEN_BIN)-$(MOCKGEN_VER))
MOCKGEN_PKG := go.uber.org/mock/mockgen
.PHONY: all
all: build
.PHONY: build
build: $(CMDS:%=build-%)
.PHONY: container
container: $(CMDS:%=container-%)
.PHONY: clean
clean:
rm -rf bin test/e2e/e2e.test test/e2e/ginkgo
.PHONY: build-%
$(CMDS:%=build-%): build-%:
mkdir -p bin
CGO_ENABLED=0 go build -ldflags '$(FULL_LDFLAGS)' -o "./bin/$*" ./cmd/$*
.PHONY: container-%
$(CMDS:%=container-%): container-%: build-%
$(DOCKER) build -f ./cmd/$*/Dockerfile -t $*:latest \
--label org.opencontainers.image.revision=$(REV) .
.PHONY: generate-mocks
generate-mocks: $(MOCKGEN) pkg/cloud/mock_cloud.go ## Generate mocks needed for testing. Primarily mocks of the cloud package.
pkg/cloud/mock%.go: $(shell find ./pkg/cloud -type f -name "*test*" -prune -o -print)
go generate ./...
.PHONY: test
test:
go test ./...
.PHONY: test-sanity
test-sanity:
go test --tags=sanity ./test/sanity
.PHONY: setup-external-e2e
setup-external-e2e: test/e2e/e2e.test test/e2e/ginkgo
test/e2e/e2e.test test/e2e/ginkgo:
curl --location https://dl.k8s.io/v1.30.5/kubernetes-test-linux-amd64.tar.gz | \
tar --strip-components=3 -C test/e2e -zxf - kubernetes/test/bin/e2e.test kubernetes/test/bin/ginkgo
.PHONY: test-e2e
test-e2e: setup-external-e2e
bash ./test/e2e/run.sh
##@ hack/tools:
.PHONY: $(MOCKGEN_BIN)
$(MOCKGEN_BIN): $(MOCKGEN) ## Build a local copy of mockgen.
$(MOCKGEN): # Build mockgen from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(MOCKGEN_PKG) $(MOCKGEN_BIN) $(MOCKGEN_VER)