-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
280 lines (228 loc) · 13.3 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
.PHONY: build trust
NAME := k0s
PACKAGE := github.com/btwiuse/$(NAME)
GIT := $(shell git rev-parse --short HEAD)
DATE := $(shell date +%FT%T%Z)
VERSION := $(shell cat VERSION)
IMG_NAME := btwiuse/k0s
IMAGE := ${IMG_NAME}
LDFLAGS := $(shell ./pkg/version/ldflags)
TAGS := $(TAGS)
SHELL := bash
BAZEL := $(shell ./tools/which_bazel)
default: help
docker-login:
@ docker login -u $(DOCKERHUB_USERNAME) -p $(DOCKERHUB_TOKEN)
devcontainer: docker-login
@ docker build -t btwiuse/k0s:devcontainer -f .devcontainer/Dockerfile .devcontainer
@ docker push btwiuse/k0s:devcontainer
fonts:
@ mkdir -p fonts/ pkg/fonts/; cp /usr/share/figlet/fonts/standard.flf fonts/
@ assets -d fonts/ -package fonts -o ./pkg/fonts/standard.go -map Fonts
@ rm -r fonts/
raze: ## auto generate BUILD.bazel files from Cargo.toml
@ which cargo-raze || (echo please cargo install cargo-raze | grep --color . 1>&2 && false)
@#cargo vendor --versioned-dirs cargo/vendor &>/dev/null
@ cargo raze
# @ $(BAZEL) run @cargo_raze//:raze -- --manifest-path=$(realpath /Cargo.toml)
@ git status cargo
replace: ## inject replace directives to all workspace modules based on go.work
@ ./tools/replace_all
require: ## turn replace directives for workspace modules into require
@ ./tools/require_all
work-sync:
go work sync
gazelle: work-sync ## auto generate BUILD.bazel files from go.mod
@ go mod tidy
@#go mod vendor
@ find pkg -name 'go.mod' | sed s,go.mod,,g | xargs -I% bash -vc 'pushd % && go mod tidy'
@#sed -i -e '/k0s.io.* v/d' pkg/*/go.mod go.mod
@#ls -1 pkg/*/go.mod | xargs -L1 $(BAZEL) run //:gazelle -- update-repos --from_file
@# @ $(BAZEL) run //:gazelle -- update-repos --from_file=third_party/go.mod -lang go -proto disable_global
@# https://github.com/btwiuse/baize/blob/btwiuse/hack/update-deps.sh
@ $(BAZEL) run //:gazelle -- update-repos --from_file=third_party/go.mod --build_file_generation=on --build_file_proto_mode=disable --prune --to_macro=go_repos.bzl%go_repositories
@ $(BAZEL) run //:gazelle
@#git status vendor/
cancel-actions-in-queue: ## cancel gh actions in queue
@ gh run list -L 60 | grep queued | cut -f 7 | xargs -L1 gh run cancel
cancel-actions: ## cancel gh actions
@ gh run list -L 60 | cut -f 7 | xargs -L1 gh run cancel
go-get: ## trigger update for https://pkg.go.dev
@ go work edit --json | grep ModPath | grep -o '"k0s.io/.*"' | xargs -I% bash -c 'echo go get %@$(shell git rev-parse HEAD)' | bash -v
go-install: ## install latest commit from https://pkg.go.dev
@ go install -v k0s.io/cmd/k0s@$(shell git rev-parse HEAD)
go-install-debuginfo: ## install latest commit from https://pkg.go.dev with debuginfo
@ go install -tags runtime_debug_buildinfo -v k0s.io/cmd/k0s@$(shell git rev-parse HEAD)
@ k0s hub -version
bazel-info: ## Bazel info (buildkite precheck)
$(BAZEL) --nosystem_rc --nohome_rc info
bazel-build-android: ## Build android binaries using bazel
$(BAZEL) run //:install_k0s --config=go_android_amd64 -- -g $(PWD)/bin/android/amd64
$(BAZEL) run //:install_k0s --config=go_android_386 -- -g $(PWD)/bin/android/386
$(BAZEL) run //:install_k0s --config=go_android_armv7 -- -g $(PWD)/bin/android/armv7
$(BAZEL) run //:install_k0s --config=go_android_arm64 -- -g $(PWD)/bin/android/arm64
# @ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:android_amd64 //:k0s
# @ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:android_386 //:k0s
# @ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:android_arm //:k0s
# @ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:android_arm64 //:k0s
# $(BAZEL) build //:k0s --config=go_android_amd64
# $(BAZEL) build //:k0s --config=go_android_386
# $(BAZEL) build //:k0s --config=go_android_armv7
# $(BAZEL) build //:k0s --config=go_android_arm64
bazel-build-windows: ## Build windows binaries using bazel
$(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 //:install_k0s_static -- -g $(PWD)/bin/windows/amd64
$(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:windows_386 //:install_k0s_static -- -g $(PWD)/bin/windows/386
$(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:windows_arm //:install_k0s_static -- -g $(PWD)/bin/windows/armv7
$(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:windows_arm64 //:install_k0s_static -- -g $(PWD)/bin/windows/arm64
# $(BAZEL) build //:k0s --config=go_win32
# $(BAZEL) build //:k0s --config=go_win64
bazel-build-darwin: ## Build darwin binaries using bazel
$(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //:install_k0s -- -g $(PWD)/bin/darwin/amd64
$(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:darwin_arm64 //:install_k0s -- -g $(PWD)/bin/darwin/arm64
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //:k0s
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:darwin_arm64 //:k0s
bazel-build-bsd: ## Build bsd binaries using bazel
@ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:freebsd_amd64 //:k0s
@ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:freebsd_386 //:k0s
@ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:openbsd_amd64 //:k0s
@ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:openbsd_386 //:k0s
bazel-build-bsd-arm: ## Build bsd arm binaries using bazel
@ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:freebsd_arm //:k0s
@ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:openbsd_arm //:k0s
bazel-build-linux-arm: ## Build linux arm binaries using bazel
@ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 //:k0s_static
@ $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_arm //:k0s_static
bazel-build-linux: ## Build linux binaries using bazel
$(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:install_k0s_static -- -g $(PWD)/bin/linux/amd64
$(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_386 //:install_k0s_static -- -g $(PWD)/bin/linux/386
$(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 //:install_k0s_static -- -g $(PWD)/bin/linux/arm64
$(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_arm //:install_k0s_static -- -g $(PWD)/bin/linux/arm
# $(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_mips //:install_k0s_static -- -g $(PWD)/bin/linux/mips
# $(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_mips64 //:install_k0s_static -- -g $(PWD)/bin/linux/mips64
# $(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_mipsle //:install_k0s_static -- -g $(PWD)/bin/linux/mipsle
# $(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_mips64le //:install_k0s_static -- -g $(PWD)/bin/linux/mips64le
# $(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_ppc64 //:install_k0s_static -- -g $(PWD)/bin/linux/ppc64
# $(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_ppc64le //:install_k0s_static -- -g $(PWD)/bin/linux/ppc64le
# $(BAZEL) run --platforms=@io_bazel_rules_go//go/toolchain:linux_s390x //:install_k0s_static -- -g $(PWD)/bin/linux/s390x
# $(BAZEL) build //:k0s_static # //cmd/{hub,client,agent}
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:k0s_static
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 //:k0s_static
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_386 //:k0s_static
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_mips //:k0s_static
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_mips64 //:k0s_static
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_mipsle //:k0s_static
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_mips64le //:k0s_static
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_ppc64 //:k0s_static
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_ppc64le //:k0s_static
# $(BAZEL) build --platforms=@io_bazel_rules_go//go/toolchain:linux_s390x //:k0s_static
bazel-build: ## Build binary for current platform using bazel
$(BAZEL) build //:k0s_static
# $(BAZEL) run //:install_k0s_static -- -g $(PWD)/bin
# $(BAZEL) build # //:k0s # //cmd/{hub,client,agent}
build: ## Build binary for current platform
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}"
dry: ## Build binary for every supported platform
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}" -dry \
linux/{{mips{,64},ppc64}{,le},s390x} \
{linux,android}/{armv6,armv7,arm64,amd64,386} {darwin,windows}/{386,amd64} \
freebsd/{armv7,armv6} {freebsd,openbsd}/{386,amd64}
build-all: ## Build binary for every supported platform
@ make build-android
@ make build-linux
@ make build-linux-arm
@ make build-bsd
@ make build-bsd-arm
@ make build-windows
@ make build-darwin
build-android: ## Build android binaries
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}" \
android/{armv6,armv7,arm64,amd64,386}
build-bsd-arm: ## Build bsd arm binaries
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}" \
{netbsd,openbsd,freebsd}/{armv6,armv7,arm64}
build-bsd: ## Build bsd binaries
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}" \
{netbsd,openbsd,freebsd}/{amd64,386}
build-linux: ## Build linux binaries
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}" \
linux/{amd64,386}
build-linux-arm: ## Build linux arm binaries
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}" \
linux/{armv6,armv7,arm64}
build-linux-others: ## Build linux binaries
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}" \
linux/{{mips{,64},ppc64}{,le},s390x,{riscv,loong}64}
build-windows: ## Build windows binaries
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}" \
windows/{386,amd64,armv7,arm64}
build-darwin: ## Build darwin binaries
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}" \
darwin/{amd64,arm64}
scratch-build: ## Build without using existing build cache
@ go run ./cmd/bingo -d releases/latest -ldflags="${LDFLAGS}" -- -a
scratch-build-all: ## Build binary for every supported platform ignoring build cache
@ go run ./cmd/bingo -tags "$(TAGS)" -ldflags="${LDFLAGS}" -- -a\
{linux,android}/{armv6,armv7,arm64,amd64,386} {darwin,windows}/{386,amd64} \
linux/{{mips{,64},ppc64}{,le},s390x}
release: ## Build and upload binaries for all supported platforms
# mkdir -p bin/; git -C bin/ init
# make build
# pushd bin; tree -L 1 -H '.' --noreport --charset utf-8 > index.html; popd
@ .ci/release-latest.sh
dist: ## Build and make an dist image TODO: android builder image
@ make build
@ make build-linux-arm
@ make build-windows
@ make build-darwin
@ pushd bin; test -f index.html && rm index.html; tree -H '.' --noreport --charset utf-8 | sponge index.html; popd
@ cp VERSION bin/
@ ./bin/k0s mnt https://chassis.k0s.io/btwiuse/k0s/v0.0.11/ ./bin/
install: ## install binary to system paths
install -Dvm755 bin/$(NAME) /usr/bin/$(NAME)
install -Dvm644 .systemd/[email protected] /etc/systemd/system/[email protected]
install -Dvm644 .systemd/k0s-hub.service /etc/systemd/system/k0s-hub.service
make systemd
systemd: ## Show systemd post install actions
@ echo
@ echo '# Reload systemd unit files'
@ echo 'sudo systemctl daemon-reload'
@ echo
@ echo '# Run this manually to initialize/restart the agent service'
@ echo 'sudo systemctl enable k0s-agent@$$USER'
@ echo 'sudo systemctl start k0s-agent@$$USER'
@ echo 'sudo systemctl restart k0s-agent@$$USER'
@ echo
@ echo '# Run this manually to initialize/restart the hub service'
@ echo 'sudo systemctl enable k0s-hub'
@ echo 'sudo systemctl start k0s-hub'
@ echo 'sudo systemctl restart k0s-hub'
@ echo
@ echo '# To stop those services,do the following:'
@ echo 'sudo systemctl list-units | grep k0s'
@ echo 'sudo systemctl stop k0s-agent@$$USER'
@ echo 'sudo systemctl stop k0s-hub'
clean: ## Clean build artifacts
rm -r bin
up: ## Start prometheus and grafana to scrape and display metrics
.docker-compose/up
buildkite: ## Generate buildkite pipeline yml definition
cd .buildkite && ./gen | tee /dev/stderr > pipeline.yml
test-build: ## Check all build tags will compile
@ go run ./cmd/bingo -tags raw # test tag raw
@ go run ./cmd/bingo -tags nhooyr # test tag nhooyr
@ go run ./cmd/bingo -tags gorilla # test tag gorilla
test: ## Run all tests
@go clean --testcache && go test ./...
cover: ## Run test coverage suite
@go test ./... --coverprofile=cov.out
@go tool cover --html=cov.out
img: docker-login ## Build Docker Image and push
@ docker build --rm -t ${IMAGE} -f Dockerfile .
@ docker push ${IMAGE}
bazel-img: ## Build Docker Image archive with bazel
@ ${BAZEL} build //:k0s_image.tar
bazel-docker-img: bazel-img ## Build Docker Image with bazel
@ docker load -i bazel-bin/k0s_image.tar
@ docker tag bazel:k0s_image ${IMAGE}
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":[^:]*?## "}; {printf "\033[38;5;69m%-30s\033[38;5;38m %s\033[0m\n", $$1, $$2}'