-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
93 lines (71 loc) · 2.87 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
GO ?= go
include $(CURDIR)/versions.mk
.PHONY: all
all: build
##@ General
.PHONY: help
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)
##@ Build
BINARY_VERSION ?= $(GIT_TAG)
ifdef VERSION
BINARY_VERSION = $(VERSION)
endif
# Only set Version if building a tag or VERSION is set
ifneq ($(BINARY_VERSION),)
LDFLAGS += -X github.com/yeahdongcn/kustohelmize/internal/version.version=$(BINARY_VERSION)
endif
VERSION_METADATA = unreleased
# Clear the "unreleased" string in BuildMetadata
ifneq ($(GIT_TAG),)
VERSION_METADATA =
endif
LDFLAGS += -X github.com/yeahdongcn/kustohelmize/internal/version.metadata=$(VERSION_METADATA)
LDFLAGS += -X github.com/yeahdongcn/kustohelmize/internal/version.gitCommit=$(GIT_COMMIT)
LDFLAGS += -X github.com/yeahdongcn/kustohelmize/internal/version.gitTreeState=$(GIT_DIRTY)
LDFLAGS += $(EXT_LDFLAGS)
.PHONY: build
build: ## Build the binary.
GO111MODULE=on CGO_ENABLED=0 $(GO) build -o bin/kustohelmize -ldflags '$(LDFLAGS)' $(CURDIR)/main.go
##@ Test
.PHONY: examples
examples: build kubernetes-split-yaml ## Test the binary against the examples.
cd examples/memcached-operator; KUSTOHELMIZE=../../bin/kustohelmize make helm
.PHONY: test
test: go-test build kubernetes-split-yaml 0100 0200 0300 0400 0500 ## Test the binary.
.PHONY: go-test
go-test:
$(GO) test ./...
.PHONY: 0100
0100: build
bin/kustohelmize create --from=test/testdata/0100_deployment.yaml test/output/0100/mychart
.PHONY: 0200
0200: build
bin/kustohelmize create --from=test/testdata/0200_sample.yaml --version=1.0.0 --app-version=1.0.0 --description="Helm chart for testing" test/output/0200/mychart
.PHONY: 0300
0300: build
bin/kustohelmize create --from=test/testdata/0300_sample.yaml --suppress-namespace --version=1.0.0 --app-version=1.0.0 --description="Helm chart with suppressed namespace" test/output/0300/no-ns-chart
.PHONY: 0400
0400: build
bin/kustohelmize create --from=test/testdata/0400_issuer.yaml test/output/0400/mychart
.PHONY: 0500
0500: build
bin/kustohelmize create --from=test/testdata/0500_deployment.yaml test/output/0500/mychart
##@ Tools
KUBERNETES-SPLIT-YAML = $(shell pwd)/bin/kubernetes-split-yaml
.PHONY: kubernetes-split-yaml
kubernetes-split-yaml: ## Download kubernetes-split-yaml locally if necessary.
$(call go-install-tool,$(KUBERNETES-SPLIT-YAML),github.com/mogensen/[email protected])
# go-install-tool will 'go install' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-install-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