-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMakefile
146 lines (107 loc) · 4.08 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
## --------------------------------------
## Variables
## --------------------------------------
VUE_DIR := web
NODE_MODULES := ./$(VUE_DIR)/node_modules
DIST_FOLDER := ./$(VUE_DIR)/dist
GO_BIN_OUT := main
TAG ?= latest
REGISTRY ?= ghcr.io/jont828
IMAGE_NAME ?= cluster-api-visualizer
DOCKER_IMAGE ?= $(REGISTRY)/$(IMAGE_NAME)
ARCH ?= $(shell go env GOARCH)
# ALL_ARCH = amd64 arm64
ALL_ARCH = amd64 arm arm64 ppc64le s390x
# Build time versioning details.
LDFLAGS := $(shell hack/version.sh)
## --------------------------------------
## All
## --------------------------------------
##@ All:
# Default target is to build and run the app
.PHONY: all
all: npm-install build run ## Install the npm dependencies, build the Vue app, build the Go binary and run the app.
.PHONY: build
build: build-web build-go ## Build the Vue app and the Go binary.
.PHONY: clean
clean: ## Remove the dist folder, node_modules, the Go binary and the tmp folder.
rm -rf $(DIST_FOLDER) $(NODE_MODULES) $(GO_BIN_OUT) tmp
## --------------------------------------
## JavaScript
## --------------------------------------
##@ JavaScript:
.PHONY: npm-install
npm-install: $(VUE_DIR)/package.json ## Install the npm dependencies.
npm install --prefix ./$(VUE_DIR)
.PHONY: build-web
build-web: $(NODE_MODULES) ## Build the Vue app.
npm run --prefix ./$(VUE_DIR) build
.PHONY: npm-serve
serve: $(VUE_DIR)/package.json $(NODE_MODULES) ## Run the Vue app.
npm run --prefix ./$(VUE_DIR) serve
.PHONY: clean-dist
clean-dist: ## Remove the dist folder.
rm -rf $(DIST_FOLDER)
## --------------------------------------
## Go
## --------------------------------------
##@ Go:
.PHONY: build-go
build-go: ## Build the Go binary.
go build -ldflags "$(LDFLAGS)" -o $(GO_BIN_OUT)
.PHONY: run
run: $(GO_BIN_OUT) $(DIST_FOLDER) ## Run the Go app using a binary.
./$(GO_BIN_OUT)
.PHONY: go-run
go-run: $(DIST_FOLDER) ## Run the Go app.
go run -ldflags "$(LDFLAGS)" main.go
.PHONY: air
air: .air.toml ## Start `air`.
air
.PHONY: go-mod-tidy
go-mod-tidy: ## Run `go mod tidy`.
go mod tidy
.PHONY: go-vet
go-vet: ## Run `go vet`.
go vet ./...
.PHONY: go-fmt
go-fmt: ## Run `go fmt`.
go fmt ./...
## --------------------------------------
## Docker
## --------------------------------------
##@ Docker:
.PHONY: docker-build-all
docker-build-all: $(addprefix docker-build-,$(ALL_ARCH)) ## Build all the architecture docker images.
docker-build-%: ## Build the docker image for the specified architecture.
$(MAKE) ARCH=$* docker-build
.PHONY: docker-build
docker-build: ## Build the docker image for the current architecture.
docker build --no-cache --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" -t $(DOCKER_IMAGE)-$(ARCH):$(TAG) .
.PHONY: docker-push
docker-push: ## Push the docker image for the current architecture.
docker push $(DOCKER_IMAGE)-$(ARCH):$(TAG)
.PHONY: docker-push-all
docker-push-all: $(addprefix docker-push-,$(ALL_ARCH)) ## Push all the architecture docker images.
$(MAKE) docker-push-manifest
docker-push-%: ## Push the docker image for the specified architecture.
$(MAKE) ARCH=$* docker-push
.PHONY: docker-push-manifest
docker-push-manifest: ## Push the fat manifest docker image.
## Minimum docker version 18.06.0 is required for creating and pushing manifest images.
docker manifest create --amend $(DOCKER_IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(DOCKER_IMAGE)\-&:$(TAG)~g")
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${DOCKER_IMAGE}:${TAG} ${DOCKER_IMAGE}-$${arch}:${TAG}; done
docker manifest push --purge ${DOCKER_IMAGE}:${TAG}
## --------------------------------------
## Helm
## --------------------------------------
##@ Helm:
.PHONY: update-helm
update-helm: ## Update the helm repo.
./hack/update-helm-repo.sh
## --------------------------------------
## Help
## --------------------------------------
##@ Help:
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)