-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
106 lines (85 loc) · 3.86 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
# Image URL to use all building/pushing image targets
VERSION ?= dev
COMMIT ?= $(shell git rev-parse HEAD)
REPO ?= ghcr.io/solo-io/kdiag
IMG ?= $(REPO):$(VERSION)
LDFLAGS := "-X github.com/solo-io/kdiag/pkg/version.Version=$(VERSION) -X github.com/solo-io/kdiag/pkg/version.ImageRepo=$(REPO) -X github.com/solo-io/kdiag/pkg/version.Commit=$(COMMIT)"
SHELL_VERSION ?= $(shell cd scratch-shell; cat $$(ls -AS .)| sha256sum |cut -c1-8)
SHELL_IMG ?= $(REPO)-shell:$(SHELL_VERSION)
.PHONY: all
all: docker-build
.PHONY: echo-shell-img
echo-shell-img:
@echo $(SHELL_IMG)
.PHONY: ginkgo-test
test: ginkgo generate fmt vet
$(GINKGO) -r --coverprofile cover.out --race
.PHONY: generate
generate: protoc-gen-go protoc-gen-go-grpc
PATH=$(shell pwd)/bin:$$PATH go generate ./...
go run pkg/cmd/scripts/docs.go
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY:
scratch-shell/built/enter: scratch-shell/enter.c
gcc $< -o $@
.PHONY: docker-build
docker-build:
DOCKER_BUILDKIT=1 docker build -f Dockerfile --tag ${IMG} --build-arg=VERSION=$(VERSION) --build-arg=COMMIT=$(COMMIT) .
# for this to work on multiarch, you may need to registry the relevant qemu-user-static in binfmt; see ci/qemu.sh
.PHONY: docker-shell-build-push
docker-shell-build-push:
DOCKER_BUILDKIT=1 docker buildx build --platform linux/amd64,linux/arm64 --tag ${SHELL_IMG} --build-arg=VERSION=$(SHELL_VERSION) --build-arg=COMMIT=$(SHELL_VERSION) --push ./scratch-shell
.PHONY: docker-shell-build
docker-shell-build:
DOCKER_BUILDKIT=1 docker buildx build --platform linux/amd64,linux/arm64 --tag ${SHELL_IMG} --build-arg=VERSION=$(SHELL_VERSION) --build-arg=COMMIT=$(SHELL_VERSION) ./scratch-shell
build-manager:
CGO_ENABLED=0 go build -a -o manager -ldflags=$(LDFLAGS) cmd/srv/srv.go
GINKGO = $(shell pwd)/bin/ginkgo
.PHONY: ginkgo
ginkgo: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/[email protected])
PROTOC_GEN_GO = $(shell pwd)/bin/protoc-gen-go
.PHONY: protoc-gen-go
protoc-gen-go: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(PROTOC_GEN_GO),google.golang.org/protobuf/cmd/[email protected])
PROTOC_GEN_GRPC_GO = $(shell pwd)/bin/protoc-gen-go-grpc
.PHONY: protoc-gen-go-grpc
protoc-gen-go-grpc: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(PROTOC_GEN_GRPC_GO),google.golang.org/grpc/cmd/[email protected])
GORELEASER = $(shell pwd)/bin/goreleaser
.PHONY: goreleaser
goreleaser: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(GORELEASER),github.com/goreleaser/[email protected])
.PHONY: deploy-test-wokrloads
deploy-test-wokrloads:
kubectl create deployment nginx --image=docker.io/library/nginx:1.19@sha256:2275af0f20d71b293916f1958f8497f987b8d8fd8113df54635f2a5915002bf1 || true
kubectl expose deploy nginx --port 80 --target-port 80 --type=NodePort || true
kubectl create deployment curl --image=curlimages/curl@sha256:aa45e9d93122a3cfdf8d7de272e2798ea63733eeee6d06bd2ee4f2f8c4027d7c -- /bin/sh -c "while true; do curl --max-time 2 --head http://nginx; sleep 1; done"|| true
.PHONY: create-test-cluster
create-test-cluster:
kind create cluster --image=docker.io/kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac || true
$(MAKE) deploy-test-wokrloads
.PHONY: reload-test-env
reload-test-env: docker-build
kubectl delete pod -lapp=nginx || true
kind load docker-image ${IMG}
.PHONY: create-test-env
create-test-env: create-test-cluster reload-test-env
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef