-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
199 lines (160 loc) · 6.89 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
PROJECT_DIR := $(shell pwd)
BIN_DIR ?= $(PROJECT_DIR)/bin
export TEST_RESULTS ?= $(PROJECT_DIR)/test-results
export TMP_DIR ?= $(PROJECT_DIR)/tmp
export PATH := $(BIN_DIR):$(PATH)
export OUTPUT_DIR ?= $(TMP_DIR)/test-artifacts
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
TERRAFORM_VERSION ?= 1.9.6
TOFU_VERSION ?= 1.8.2
KUBECTL_VERSION ?= 1.31.1
KWOKCTL_VERSION ?= 0.6.0
HELM_VERSION ?= 3.16.1
MINIKUBE_VERSION ?= 1.34.0
NUODB_CP_VERSION ?= 2.7.0
GOTESTSUM := bin/gotestsum
TFPLUGINDOCS := bin/tfplugindocs
OAPI_CODEGEN := bin/oapi-codegen
TERRAFORM := bin/terraform
TOFU := bin/tofu
KUBECTL := bin/kubectl
KWOKCTL := bin/kwokctl
HELM := bin/helm
MINIKUBE := bin/minikube
GOLANGCI_LINT := bin/golangci-lint
NUODB_CP := bin/nuodb-cp
# For actual releases, GoReleaser uses the Git tag to obtain the version and
# not this variable, but this is used by the `make package` target which is
# invoked by the e2e app test.
PUBLISH_VERSION ?= $(shell ./get-version.sh)
PUBLISH_DIR ?= $(PROJECT_DIR)/dist
IGNORE_NOT_FOUND ?= true
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.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)
##@ Dependencies
$(TERRAFORM):
mkdir -p bin tmp
curl -L -s https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(OS)_$(ARCH).zip -o tmp/terraform.zip
cd tmp && unzip terraform.zip
mv tmp/terraform $(TERRAFORM)
$(TOFU):
mkdir -p bin tmp
curl -L -s https://github.com/opentofu/opentofu/releases/download/v$(TOFU_VERSION)/tofu_$(TOFU_VERSION)_$(OS)_$(ARCH).zip -o tmp/tofu.zip
cd tmp && unzip tofu.zip tofu
mv tmp/tofu $(TOFU)
$(KUBECTL):
mkdir -p bin
curl -L -s https://dl.k8s.io/release/v$(KUBECTL_VERSION)/bin/$(OS)/$(ARCH)/kubectl -o $(KUBECTL)
chmod +x $(KUBECTL)
$(KWOKCTL):
mkdir -p bin
curl -L -s https://github.com/kubernetes-sigs/kwok/releases/download/v$(KWOKCTL_VERSION)/kwokctl-$(OS)-$(ARCH) -o $(KWOKCTL)
chmod +x $(KWOKCTL)
$(HELM):
mkdir -p bin
curl -L -s https://get.helm.sh/helm-v$(HELM_VERSION)-$(OS)-$(ARCH).tar.gz | tar -xz -C bin --strip-components=1 $(OS)-$(ARCH)/helm
chmod +x $(HELM)
$(MINIKUBE):
mkdir -p bin
curl -L -s https://storage.googleapis.com/minikube/releases/v$(MINIKUBE_VERSION)/minikube-$(OS)-$(ARCH) -o $(MINIKUBE)
chmod +x $(MINIKUBE)
$(NUODB_CP):
mkdir -p bin
curl -L -s https://github.com/nuodb/nuodb-cp-releases/releases/download/v$(NUODB_CP_VERSION)/nuodb-cp -o $(NUODB_CP)
chmod +x $(NUODB_CP)
bin/%:
$(MAKE) install-tools
.PHONY: install-tools
install-tools: ## Install tools declared as dependencies in tools.go
@echo "Installing build tools declared in tools.go..."
@go list -e -f '{{range .Imports}}{{.}} {{end}}' tools.go | GOBIN=$(BIN_DIR) xargs go install
##@ Development
.PHONY: check-no-changes
check-no-changes: ## Check that there are no uncommitted changes
$(eval GIT_STATUS := $(shell git status --porcelain))
@[ "$(GIT_STATUS)" = "" ] || ( echo "There are uncommitted changes:\n$(GIT_STATUS)"; exit 1; )
.PHONY: check-version
check-version: ## Check that Git tag matches version in code
$(eval FROM_HEAD := $(shell git tag --points-at=HEAD | sed -n 's/^v//p'))
@[ -z "$(FROM_HEAD)" ] || [ "$(FROM_HEAD)" = "$(PUBLISH_VERSION)" ] || ( echo "Tag version ($(FROM_HEAD)) does not match code version ($(PUBLISH_VERSION))"; exit 1; )
.PHONY: generate
generate: $(TFPLUGINDOCS) $(OAPI_CODEGEN) $(TERRAFORM) ## Generate Golang client for the NuoDB REST API and Terraform provider documentation
@if git tag --points-at HEAD | grep -q "^v"; then \
echo "Updating openapi.yaml because commit has version tag..." ;\
$(MAKE) update-spec ;\
fi
go mod tidy
go generate
.PHONY: update-spec
update-spec: ## Update spec to released Control Plane version
curl -s https://raw.githubusercontent.com/nuodb/nuodb-cp-releases/v$(NUODB_CP_VERSION)/openapi.yaml -o openapi.yaml
.PHONY: lint
lint: $(GOLANGCI_LINT) ## Run linters to check code quality and find for common errors
$(GOLANGCI_LINT) run
##@ Testing
.PHONY: kwok-deps
kwok-deps: $(KWOKCTL) $(KUBECTL) $(HELM)
.PHONY: k8s-deps
k8s-deps: $(KUBECTL) $(HELM) $(NUODB_CP)
.PHONY: minikube-deps
minikube-deps: $(MINIKUBE) k8s-deps
.PHONY: external-deps
setup-%: %-deps
mkdir -p $(OUTPUT_DIR) $(TMP_DIR)
[ ! -x "./deploy/$*/setup.sh" ] || ./deploy/$*/setup.sh
env-%: %-deps
@[ ! -x "./deploy/$*/env.sh" ] || ./deploy/$*/env.sh
logs-%: %-deps
[ ! -x "./deploy/$*/logs.sh" ] || ./deploy/$*/logs.sh
teardown-%: %-deps
[ ! -x "./deploy/$*/teardown.sh" ] || ./deploy/$*/teardown.sh
.PHONY: testacc
testacc: $(GOTESTSUM) $(TERRAFORM) ## Run acceptance tests
@if [ "$$USE_TOFU" = true ]; then \
$(MAKE) $(TOFU) ;\
fi
mkdir -p $(TEST_RESULTS)
TF_ACC=1 $(GOTESTSUM) --junitfile $(TEST_RESULTS)/gotestsum-report.xml \
--format testname -- -v -count=1 -p 1 -timeout 30m \
-coverprofile $(TEST_RESULTS)/cover.out -coverpkg ./internal/... \
$(TESTARGS) ./...
.PHONY: coverage-report
coverage-report:
go tool cover -html=$(TEST_RESULTS)/cover.out -o $(OUTPUT_DIR)/coverage.html
go tool cover -func $(TEST_RESULTS)/cover.out -o $(OUTPUT_DIR)/coverage.txt
##@ Packaging
.PHONY: package
package: ## Generate the provider for this machines OS and Architecture
PACKAGE_OS=$(OS) PACKAGE_ARCH=$(ARCH) $(MAKE) package-all
.PHONY: package-all
package-all: ## Generate the provider for every OS and Architecture
rm -r $(PUBLISH_DIR) || $(IGNORE_NOT_FOUND)
mkdir -p $(PUBLISH_DIR)
$(eval PACKAGE_OS ?= darwin linux windows)
$(eval PACKAGE_ARCH ?= amd64 arm64)
$(foreach OS, $(PACKAGE_OS), \
$(foreach ARCH, $(PACKAGE_ARCH), $(call package-os,$(OS),$(ARCH))))
$(eval PUBLISH_MIRROR ?= $(PUBLISH_DIR)/pkg_mirror/registry.terraform.io/nuodb/nuodbaas)
mkdir -p $(PUBLISH_MIRROR)
cp $(PUBLISH_DIR)/*.zip $(PUBLISH_MIRROR)
# Build the release package for a given OS and Architecture
define package-os
$(eval PUBLISH_STAGING := $(PUBLISH_DIR)/staging_$(1)_$(2))
$(eval PLUGIN_PKG := $(PUBLISH_DIR)/terraform-provider-nuodbaas_$(PUBLISH_VERSION)_$(1)_$(2).zip)
mkdir -p $(PUBLISH_STAGING)
GOOS=$(1) GOARCH=$(2) go build -o $(PUBLISH_STAGING)/terraform-provider-nuodbaas_v$(PUBLISH_VERSION)
cd $(PUBLISH_STAGING) && zip $(PLUGIN_PKG) ./*
endef