-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
174 lines (138 loc) · 5.73 KB
/
Copy pathMakefile
File metadata and controls
174 lines (138 loc) · 5.73 KB
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
IMAGE ?= mgoltzsche/khelm:latest
BUILD_DIR := $(CURDIR)/build
BIN_DIR := $(BUILD_DIR)/bin
KHELM := $(BIN_DIR)/khelm
GOLANGCI_LINT = $(BIN_DIR)/golangci-lint
GORELEASER = $(BIN_DIR)/goreleaser
KPT := $(BIN_DIR)/kpt
KUSTOMIZE := $(BIN_DIR)/kustomize
SOPS := $(BIN_DIR)/sops
export HELM_SECRETS_SOPS_BIN := $(SOPS)
export HELM_PLUGINS := $(BUILD_DIR)/helm-plugins
GORELEASER_VERSION ?= v2.16.0
GOLANGCI_LINT_VERSION ?= v2.12.2
KPT_VERSION ?= v1.0.0-beta.61
KUSTOMIZE_VERSION ?= v5.8.1
BATS_VERSION = v1.13.0
SOPS_VERSION = v3.13.1
HELM_SECRETS_VERSION = v4.6.11
BATS_DIR = $(BUILD_DIR)/tools/bats
BATS = $(BIN_DIR)/bats
REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')
VERSION ?= $(shell echo "$$(git describe --exact-match --tags $(git log -n1 --pretty='%h') 2> /dev/null || echo dev)-$(REV)" | sed 's/^v//')
HELM_VERSION := $(shell grep helm\.sh/helm/ go.mod | sed -E -e 's!helm\.sh/helm/v3|\s+|\+.*!!g; s!^v!!' | cut -d " " -f2 | grep -E .+)
GO_LDFLAGS := -X main.khelmVersion=$(VERSION) -X main.helmVersion=$(HELM_VERSION) -s -w -extldflags '-static'
BUILDTAGS ?=
CGO_ENABLED ?= 0
DOCKER ?= docker
all: clean khelm test image check
khelm: ## Build the khelm binary.
CGO_ENABLED=$(CGO_ENABLED) go build -o $(BUILD_DIR)/bin/khelm -ldflags "$(GO_LDFLAGS)" -tags "$(BUILDTAGS)" ./cmd/khelm
install: ## Install the khelm binary on your host.
cp $(BUILD_DIR)/bin/khelm /usr/local/bin/khelm
chmod +x /usr/local/bin/khelm
install-kustomize-plugin: ## Install the kustomize plugin on your host.
mkdir -p $${XDG_CONFIG_HOME:-$$HOME/.config}/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer
cp $(BUILD_DIR)/bin/khelm $${XDG_CONFIG_HOME:-$$HOME/.config}/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer/ChartRenderer
image: khelm ## Build the khelm container image.
$(DOCKER) build --force-rm -t $(IMAGE) -f ./Dockerfile --build-arg=TARGETPLATFORM=. $(BIN_DIR)
test: $(BUILD_DIR) sops helm-plugins ## Run the unit tests.
go test -coverprofile $(BUILD_DIR)/coverage.out -cover ./...
coverage: test ## Run unit tests and generate coverage HTML report.
go tool cover -html=$(BUILD_DIR)/coverage.out -o $(BUILD_DIR)/coverage.html
e2e-test: kpt kustomize | $(BATS) ## Run the e2e tests.
@echo 'Running e2e tests (PATH=$(BUILD_DIR)/bin)'
@{ \
export PATH="$(BIN_DIR):$$PATH" IMAGE=$(IMAGE); \
$(BATS) -T ./e2e; \
}
fmt: ## Format the Go code.
go fmt ./...
clean: ## Remove all build/test artifacts.
rm -f $(BUILD_DIR)/bin/khelm
rm -f $(BUILD_DIR)/bin/khelm-static
rm -rf example/localrefref/charts
rm -rf example/kpt/linkerd/dep
# TODO: fix "invalid trailing UTF-8 octet" yaml parser error
rm -f example/kpt/test-cases/output-remote.yaml
rm -f example/kpt/output-mapping/output-filtered.yaml
clean-all: clean ## Remove all build/test artifacts and downloaded tools.
rm -rf $(BUILD_DIR)
find . -name charts -type d -exec rm -rf {} \;
check: $(GOLANGCI_LINT) ## Run linters.
$(GOLANGCI_LINT) run ./...
snapshot: $(GORELEASER) ## Build a snapshot release without publishing it.
HELM_VERSION="$(HELM_VERSION)" $(GORELEASER) release --snapshot --clean --fail-fast
register-qemu-binfmt: ## Enable multiarch support on the host.
$(DOCKER) run --rm --privileged multiarch/qemu-user-static:7.0.0-7 --reset -p yes
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
kpt: $(KPT)
sops: $(SOPS)
helm-plugins: $(HELM_PLUGINS)
kustomize: $(KUSTOMIZE)
golangci-lint: $(GOLANGCI_LINT)
goreleaser: $(GORELEASER)
$(GOLANGCI_LINT):
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION))
$(KPT):
$(call download-bin,$(KPT),"https://github.com/GoogleContainerTools/kpt/releases/download/$(KPT_VERSION)/kpt_$$(uname | tr '[:upper:]' '[:lower:]')_amd64")
$(KUSTOMIZE):
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION))
$(GORELEASER):
$(call go-get-tool,$(GORELEASER),github.com/goreleaser/goreleaser/v2@$(GORELEASER_VERSION))
$(SOPS):
$(call download-bin,$(SOPS),"https://github.com/mozilla/sops/releases/download/$(SOPS_VERSION)/sops-$(SOPS_VERSION).$$(uname | tr '[:upper:]' '[:lower:]').amd64")
$(HELM_PLUGINS):
$(call download-tar-gz,$(HELM_PLUGINS),"https://github.com/jkroepke/helm-secrets/releases/download/$(HELM_SECRETS_VERSION)/helm-secrets.tar.gz")
$(BATS):
@echo Downloading bats
@{ \
set -e ;\
mkdir -p $(BIN_DIR) ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
git clone -c 'advice.detachedHead=false' --branch $(BATS_VERSION) https://github.com/bats-core/bats-core.git . >/dev/null;\
./install.sh $(BATS_DIR) ;\
ln -s $(BATS_DIR)/bin/bats $(BATS) ;\
}
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)/bin
# 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)/build/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
# download-bin downloads a binary into the location given as first argument
define download-bin
@[ -f $(1) ] || { \
set -e ;\
mkdir -p `dirname $(1)` ;\
TMP_FILE=$$(mktemp) ;\
echo "Downloading $(2)" ;\
curl -fsSLo $$TMP_FILE $(2) ;\
chmod +x $$TMP_FILE ;\
mv $$TMP_FILE $(1) ;\
}
endef
# download-tar-gz downloads a tar.gz or .tgz file and extracts it into the location given as first argument
define download-tar-gz
@[ -d $(1) ] || { \
set -e ;\
echo $(1) ;\
mkdir -p $(1) ;\
cd $(1) ;\
echo "Downloading $(2)" ;\
curl -fsSLo downloaded.tar.gz $(2) ;\
tar -xzf downloaded.tar.gz ;\
rm downloaded.tar.gz ;\
}
endef