-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
127 lines (96 loc) · 2.93 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
## --------------------------------------
## 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
## --------------------------------------
# Default target is to build and run the app
.PHONY: all
all: npm-install build run
.PHONY: build
build: build-web build-go
.PHONY: clean
clean:
rm -rf $(DIST_FOLDER) $(NODE_MODULES) $(GO_BIN_OUT) tmp
## --------------------------------------
## Vue and Node
## --------------------------------------
.PHONY: npm-install
npm-install: $(VUE_DIR)/package.json
npm install --prefix ./$(VUE_DIR)
.PHONY: build-web
build-web: $(NODE_MODULES)
npm run --prefix ./$(VUE_DIR) build
.PHONY: npm-serve
serve: $(VUE_DIR)/package.json $(NODE_MODULES)
npm run --prefix ./$(VUE_DIR) serve
.PHONY: clean-dist
clean-dist:
rm -rf $(DIST_FOLDER)
## --------------------------------------
## Go
## --------------------------------------
.PHONY: build-go
build-go:
go build -ldflags "$(LDFLAGS)" -o $(GO_BIN_OUT)
.PHONY: run
run: $(GO_BIN_OUT) $(DIST_FOLDER)
./$(GO_BIN_OUT)
.PHONY: go-run
go-run: $(DIST_FOLDER)
go run -ldflags "$(LDFLAGS)" main.go
.PHONY: air
air: .air.toml
air
.PHONY: go-mod-tidy
go-mod-tidy:
go mod tidy
.PHONY: go-vet
go-vet:
go vet ./...
.PHONY: go-fmt
go-fmt:
go fmt ./...
## --------------------------------------
## Docker
## --------------------------------------
.PHONY: docker-build-all
docker-build-all: $(addprefix docker-build-,$(ALL_ARCH))
docker-build-%:
$(MAKE) ARCH=$* docker-build
.PHONY: docker-build
docker-build:
docker build --no-cache --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" -t $(DOCKER_IMAGE)-$(ARCH):$(TAG) .
.PHONY: docker-push
docker-push:
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-%:
$(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
## --------------------------------------
.PHONY: update-helm
update-helm:
./hack/update-helm-repo.sh