-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Makefile
104 lines (83 loc) · 3.48 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
# timoni test, build, install makefile
.ONESHELL:
.SHELLFLAGS += -e
# Repository root based on Git metadata
REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
BIN_DIR := $(REPOSITORY_ROOT)/bin
# API gen tool
CONTROLLER_GEN_VERSION ?= v0.14.0
# Kubernetes env test
ENVTEST_ARCH?=amd64
ENVTEST_KUBERNETES_VERSION?=1.28
all: test build
DEV_VERSION?=0.0.0-$(shell git rev-parse --short HEAD).$(shell date +%s)
build: ## Build the CLI binary.
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(DEV_VERSION)" -o ./bin/timoni ./cmd/timoni
.PHONY: test
test: tidy generate fmt vet install-envtest ## Run the Go tests.
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out
tidy: ## Tidy Go modules.
rm -f go.sum; go mod tidy -compat=1.23
fmt: ## Format Go code.
go fmt ./...
vet: ## Vet Go code.
go vet ./...
cue-vet: build ## Vet and fmt CUE files.
cue fmt ./schemas/...
cue vet ./schemas/...
for dir in ./blueprints/* ; do
cue fmt $$dir/...
./bin/timoni mod vet $$dir
done
for dir in ./examples/* ; do
cue fmt $$dir/...
if [ $$dir != "./examples/bundles" ]; then
./bin/timoni mod vet $$dir
fi
done
./bin/timoni mod vet ./cmd/timoni/testdata/module
./bin/timoni mod vet ./internal/engine/testdata/module
./bin/timoni mod vet ./internal/engine/fetcher/testdata/module
cue fmt ./internal/engine/testdata/module-values
REDIS_VER=$(shell grep 'tag:' examples/redis/values.cue | awk '{ print $$2 }' | tr -d '"')
push-redis: build
./bin/timoni mod push ./examples/redis oci://ghcr.io/stefanprodan/modules/redis -v $(REDIS_VER) --latest \
-a 'org.opencontainers.image.source=https://github.com/stefanprodan/timoni/tree/main/examples/redis' \
-a 'org.opencontainers.image.description=A timoni.sh module for deploying Redis master-replica clusters.' \
-a 'org.opencontainers.image.documentation=https://github.com/stefanprodan/timoni/blob/main/examples/redis/README.md'
.PHONY: install
install: ## Build and install the CLI binary.
go install ./cmd/timoni
generate: controller-gen ## Generate API code.
cd api; $(CONTROLLER_GEN) object:headerFile="license.go.txt" paths="./..."
docs: build
./bin/timoni docgen
prep-docs: docs
find ./docs -name '*.md' -print0 | xargs -0 sed -i 's/```cue/```go/g'
CONTROLLER_GEN=$(BIN_DIR)/controller-gen
.PHONY: controller-gen
controller-gen:
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION))
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(BIN_DIR) -p path)"
install-envtest: setup-envtest ## Install controller-runtime envtest.
$(ENVTEST) use $(ENVTEST_KUBERNETES_VERSION) --arch=$(ENVTEST_ARCH) --bin-dir=$(BIN_DIR)
ENVTEST=$(BIN_DIR)/setup-envtest
.PHONY: envtest
setup-envtest:
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
# 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
.PHONY: help
help: ## Display this help menu
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)