-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
98 lines (83 loc) · 2.44 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
92
93
94
95
96
97
98
# COLORS
TARGET_MAX_CHAR_NUM := 10
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
# The binary to build (just the basename).
PWD := $(shell pwd)
NOW := $(shell date +%s)
APPNAME := nfs-client-provisioner
BIN ?= $(APPNAME)
ORG ?= registry.aegir.bouchaud.org
PKG := bouchaud.org/legion/kubernetes/${BIN}
PLATFORM ?= "linux/arm/v7,linux/arm64/v8,linux/amd64"
GO ?= go
GOFMT ?= gofmt -s
GOFILES := $(shell find . -name "*.go" -type f)
GOVERSION := $(shell go version | sed -r 's/go version go(.+)\s.+/\1/')
PACKAGES ?= $(shell $(GO) list ./...)
# This version-strategy uses git tags to set the version string
GIT_TAG := $(shell git describe --tags --always --dirty || echo unsupported)
GIT_COMMIT := $(shell git rev-parse --short HEAD || echo unsupported)
BUILDTIME := $(shell date -u +"%FT%TZ%:z")
TAG ?= $(GIT_TAG)
VERSION ?= $(GIT_TAG)
.PHONY: fmt fmt-check vet test test-coverage cover install docker help
default: help
## Format go source code
fmt:
$(GOFMT) -w $(GOFILES)
## Check if source code is formatted correctly
fmt-check:
@diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
## Check source code for common errors
vet:
$(GO) vet ${PACKAGES}
## Execute unit tests
test:
$(GO) test ${PACKAGES}
## Execute unit tests & compute coverage
test-coverage:
$(GO) test -coverprofile=coverage.out ${PACKAGES}
## Compute coverage
cover: test-coverage
$(GO) tool cover -html=coverage.out
## Install dependencies used for development
install: tidy
$(GO) mod download
## Build the docker images
docker:
@docker buildx build \
--push \
--platform $(PLATFORM) \
--tag $(ORG)/$(BIN):$(TAG) \
--tag $(ORG)/$(BIN):latest \
.
## Dev build outside of docker, not stripped
dev:
$(GO) build \
-o $(BIN)
## Same as manifest-push
all: manifest-push
## Print this help message
help:
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)