forked from caoyingjunz/csi-driver-localstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
79 lines (69 loc) · 1.79 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
.PHONY: run build image push vendor client-gen clean
dockerhubUser = harbor.cloud.pixiuio.com/pixiuio
tag = latest
app ?=
ifeq ($(app),)
apps = $(shell ls cmd)
else
apps = $(app)
endif
targetDir ?= dist
buildx ?= false
dualPlatform ?= linux/amd64,linux/arm64
# check if app name is valid
check:
@$(foreach app, $(apps), \
if [ ! -d "cmd/$(app)" ]; then \
echo "cmd/$(app) does not exist"; \
echo "Please check your app name"; \
exit 1; \
fi;)
# build all apps
build: check
@$(foreach app, $(apps), \
echo "Building $(app)"; \
CGO_ENABLED=0 go build -ldflags "-s -w" -o $(targetDir)/$(app) ./cmd/$(app);)
# build all images
image: check
ifeq ($(buildx), false)
@$(foreach app, $(apps), \
echo "Building $(app) image"; \
docker build -t $(dockerhubUser)/$(app):$(tag) --no-cache --build-arg APP=$(app) \
.;)
else ifeq ($(buildx), true)
@$(foreach app, $(apps), \
echo "Building $(app) multi-arch image"; \
docker buildx build -t $(dockerhubUser)/$(app):$(tag) --no-cache --platform $(dualPlatform) --push --build-arg APP=$(app) \
.;)
endif
# push all images
push: image
@$(foreach app, $(apps), \
echo "Pushing $(app) image"; \
docker push $(dockerhubUser)/$(app):$(tag);)
# install vendor
vendor:
go mod vendor
# generate client
client-gen: vendor
./hack/update-codegen.sh
# rm vendor and github.com
clean:
rm -rf vendor && rm -rf github.com
# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@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 + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help