-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
101 lines (80 loc) · 3.51 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
SHELL ?= /bin/bash
BUILD_OS ?= linux
BUILD_ARCH ?= amd64
VERSION = $(shell git describe --abbrev=0)
GIT_COMMIT=$(shell git rev-parse --short HEAD)
BASE_DIR = $(shell pwd)
TARGET_DIR = $(BASE_DIR)/target
TARGET_BIN_DIR = $(TARGET_DIR)/bin
TARGET_RELEASE_DIR = $(TARGET_DIR)/releases/$(VERSION)
TARGET_PLUGINS_DIR = $(TARGET_RELEASE_DIR)/plugins
IMAGE_REPO ?= ghcr.io/ihcsim/krew-promdump
all: test lint build
build: prebuild core cli
prebuild:
rm -rf $(TARGET_BIN_DIR)
mkdir -p $(TARGET_BIN_DIR)
.PHONY: test
test: test-core test-cli
go test ./...
test-%:
go test ./$*/...
lint-%:
cd ./$* && golangci-lint run --timeout 5m
lint: lint-core lint-cli
golangci-lint run
tidy: tidy-core tidy-cli test
tidy-%:
cd ./$* && go mod tidy
.PHONY: core
core:
CGO_ENABLED=0 GOOS="$(BUILD_OS)" GOARCH="$(BUILD_ARCH)" go build -o "$(TARGET_BIN_DIR)/promdump" ./core/cmd
shasum -a256 "$(TARGET_BIN_DIR)/promdump" | awk '{print $$1}' > "$(TARGET_BIN_DIR)/promdump.sha256"
tar -C "$(TARGET_BIN_DIR)" -czvf "$(TARGET_BIN_DIR)/promdump.tar.gz" promdump
cp "$(TARGET_BIN_DIR)/promdump.tar.gz" ./cli/cmd/
.PHONY: cli
cli:
if [ "$(BUILD_OS)" = "windows" ]; then \
extension=".exe" ;\
fi && \
CGO_ENABLED=0 GOOS="$(BUILD_OS)" GOARCH="$(BUILD_ARCH)" go build -ldflags="-X 'main.Version=$(VERSION)' -X 'main.Commit=$(GIT_COMMIT)'" -o "$(TARGET_BIN_DIR)/cli-$(BUILD_OS)-$(BUILD_ARCH)-$(VERSION)$${extension}" ./cli/cmd &&\
shasum -a256 "$(TARGET_BIN_DIR)/cli-$(BUILD_OS)-$(BUILD_ARCH)-$(VERSION)"$${extension} | awk '{print $$1}' > "$(TARGET_BIN_DIR)/cli-$(BUILD_OS)-$(BUILD_ARCH)-$(VERSION).sha256"
.PHONY: release
release:
rm -rf "$(TARGET_RELEASE_DIR)" && \
mkdir -p "$(TARGET_RELEASE_DIR)" && \
for os in linux darwin windows ; do \
$(MAKE) BUILD_OS="$${os}" BUILD_ARCH="amd64" TARGET_BIN_DIR="$(TARGET_RELEASE_DIR)" cli plugin ;\
done && \
$(MAKE) BUILD_OS="darwin" BUILD_ARCH="arm64" TARGET_BIN_DIR="$(TARGET_RELEASE_DIR)" cli plugin && \
$(MAKE) TARGET_BIN_DIR="$(TARGET_RELEASE_DIR)" core
.PHONY: plugin
plugin:
mkdir -p "$(TARGET_PLUGINS_DIR)" && \
if [ "$(BUILD_OS)" = "windows" ]; then \
extension=".exe" ;\
fi && \
cp LICENSE "$(TARGET_PLUGINS_DIR)" && \
cp "$(TARGET_RELEASE_DIR)/cli-$(BUILD_OS)-$(BUILD_ARCH)-$(VERSION)$${extension}" "$(TARGET_PLUGINS_DIR)/kubectl-promdump$${extension}" && \
tar -C "$(TARGET_PLUGINS_DIR)" -czvf "$(TARGET_PLUGINS_DIR)/kubectl-promdump-$(BUILD_OS)-$(BUILD_ARCH)-$(VERSION).tar.gz" kubectl-promdump$${extension} LICENSE && \
rm "$(TARGET_PLUGINS_DIR)/kubectl-promdump$${extension}" && \
shasum -a256 $(TARGET_PLUGINS_DIR)/kubectl-promdump-$(BUILD_OS)-$(BUILD_ARCH)-$(VERSION).tar.gz | awk '{print $$1}' > $(TARGET_PLUGINS_DIR)/kubectl-promdump-$(BUILD_OS)-$(BUILD_ARCH)-$(VERSION).tar.gz.sha256
image:
docker build --rm -t $(IMAGE_REPO):$(VERSION) .
if [ $${IMAGE_PUSH} ]; then \
docker push $(IMAGE_REPO):$(VERSION) ;\
fi
.PHONY: hack/prometheus-repos
hack/prometheus-repos:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add kube-state-metrics https://kubernetes.github.io/kube-state-metrics
helm repo update
.PHONY: hack/prometheus
hack/prometheus: hack/prometheus-repos
helm install prometheus prometheus-community/prometheus
HACK_NAMESPACE ?= default
HACK_DATA_DIR ?= /data
.PHONY: hack/deploy
hack/deploy:
pod="$$(kubectl get pods --namespace $(HACK_NAMESPACE) -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")" ;\
kubectl -n "$(HACK_NAMESPACE)" cp -c prometheus-server "$(TARGET_BIN_DIR)/promdump" "$${pod}:$(HACK_DATA_DIR)" ;\