-
Notifications
You must be signed in to change notification settings - Fork 55
/
Makefile
91 lines (73 loc) · 2.41 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
89
90
91
NAME = csi-driver
ifndef REPO_NAME
REPO_NAME ?= hpestorage/csi-driver
endif
TAG = edge
ARCH ?= amd64
# unless a BUILD_NUMBER is specified
ifeq ($(IGNORE_BUILD_NUMBER),true)
VERSION = $(TAG)
else
ifneq ($(BUILD_NUMBER),)
VERSION = $(TAG)-$(BUILD_NUMBER)
else
VERSION = $(TAG)
endif
endif
# refers to dockerhub if registry is not specified
IMAGE = $(REPO_NAME):$(VERSION)
ifdef CONTAINER_REGISTRY
IMAGE = $(CONTAINER_REGISTRY)/$(REPO_NAME):$(VERSION)
endif
# golangci-lint allows us to have a single target that runs multiple linters in
# the same fashion. This variable controls which linters are used.
LINTER_FLAGS = --disable-all --enable=vet --enable=vetshadow --enable=golint --enable=ineffassign --enable=goconst --enable=deadcode --enable=dupl --enable=varcheck --enable=gocyclo --enable=misspell --deadline=240s
# Our target binary is for Linux. To build an exec for your local (non-linux)
# machine, use go build directly.
ifndef GOOS
GOOS = linux
endif
GOENV = PATH=$$PATH:$(GOPATH)/bin
build: clean compile image push
all: clean lint compile image push
.PHONY: help
help:
@echo "Targets:"
@echo " vendor - Download dependencies (go mod vendor)"
@echo " lint - Static analysis of source code. Note that this must pass in order to build."
@echo " clean - Remove build artifacts."
@echo " compile - Compiles the source code."
@echo " test - Run unit tests."
@echo " image - Build csi driver image and create a local docker image. Errors are ignored."
@echo " push - Push csi driver image to registry."
@echo " all - Clean, lint, build, test, and push image."
vendor:
@go mod vendor
.PHONY: lint
lint:
@echo "Running lint"
@go version
export $(GOENV) && golangci-lint run $(LINTER_FLAGS) --exclude vendor
.PHONY: clean
clean:
@echo "Removing build artifacts"
@rm -rf build
.PHONY: compile
compile:
@echo "Compiling the source for ${GOOS}"
@go version
@env CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${ARCH} go build -o build/${NAME} ./cmd/csi-driver/
.PHONY: test
test:
@echo "Testing all packages"
@go test -v ./...
.PHONY: image
image:
@echo "Building multiarch docker images and manifest"
docker-buildx build --platform=linux/amd64,linux/arm64 --progress=plain \
--provenance=false -t $(IMAGE) .
.PHONY: push
push:
@echo "Publishing $(IMAGE)"
docker-buildx build --platform=linux/amd64,linux/arm64 --progress=plain \
--provenance=false --push -t $(IMAGE) .