-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathMakefile
180 lines (142 loc) · 6.8 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
UNAME_S := $(shell uname -s)
NC := $(shell tput sgr0) # No Color
ifeq ($(UNAME_S),Linux)
COCKROACH_BIN ?= https://binaries.cockroachdb.com/cockroach-v23.2.0.linux-amd64.tgz
HELM_BIN ?= https://get.helm.sh/helm-v3.14.0-linux-amd64.tar.gz
K3D_BIN ?= https://github.com/k3d-io/k3d/releases/download/v5.7.4/k3d-linux-amd64
KUBECTL_BIN ?= https://dl.k8s.io/release/v1.29.1/bin/linux/amd64/kubectl
YQ_BIN ?= https://github.com/mikefarah/yq/releases/download/v4.31.2/yq_linux_amd64
JQ_BIN ?= https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
OPM_TAR ?= https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest-4.8/opm-linux-4.8.57.tar.gz
OPM_BIN ?= opm
endif
ifeq ($(UNAME_S),Darwin)
COCKROACH_BIN ?= https://binaries.cockroachdb.com/cockroach-v23.2.0.darwin-10.9-amd64.tgz
HELM_BIN ?= https://get.helm.sh/helm-v3.14.0-darwin-amd64.tar.gz
K3D_BIN ?= https://github.com/k3d-io/k3d/releases/download/v5.7.4/k3d-darwin-arm64
KUBECTL_BIN ?= https://dl.k8s.io/release/v1.29.1/bin/darwin/amd64/kubectl
YQ_BIN ?= https://github.com/mikefarah/yq/releases/download/v4.31.2/yq_darwin_amd64
JQ_BIN ?= https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64
OPM_TAR ?= https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest-4.8/opm-mac-4.8.57.tar.gz
OPM_BIN ?= darwin-amd64-opm
endif
K3D_CLUSTER ?= chart-testing
REGISTRY ?= gcr.io
REPOSITORY ?= cockroachlabs-helm-charts/cockroach-self-signer-cert
DOCKER_NETWORK_NAME ?= "k3d-${K3D_CLUSTER}"
LOCAL_REGISTRY ?= "localhost:5000"
CLUSTER_SIZE ?= 1
export BUNDLE_IMAGE ?= cockroach-operator-bundle
export HELM_OPERATOR_IMAGE ?= cockroach-helm-operator
export OPERATOR_IMAGE ?= cockroach-operator
export QUAY_DOCKER_REGISTRY ?= quay.io
export QUAY_PROJECT ?= cockroachdb
export VERSION ?= $(shell cat version.txt)
.DEFAULT_GOAL := all
all: build
BOLD = \033[1m
CLEAR = \033[0m
CYAN = \033[36m
help: ## Display this help
@awk '\
BEGIN {FS = ":.*##"; printf "Usage: make $(CYAN)<target>$(CLEAR)\n"} \
/^[a-z0-9]+([\/]%)?([\/](%-)?[a-z\-0-9%]+)*:.*? ##/ { printf " $(CYAN)%-15s$(CLEAR) %s\n", $$1, $$2 } \
/^##@/ { printf "\n$(BOLD)%s$(CLEAR)\n", substr($$0, 5) }' \
$(MAKEFILE_LIST)
##@ Build
.PHONY: build
build: build/chart build/self-signer ## build the helm chart and self-signer
build/chart: bin/helm ## build the helm chart to build/artifacts
@build/make.sh
build/self-signer: bin/yq ## build the self-signer image
@docker build --platform=linux/amd64 -f build/docker-image/self-signer-cert-utility/Dockerfile \
--build-arg COCKROACH_VERSION=$(shell bin/yq '.appVersion' ./cockroachdb/Chart.yaml) \
-t ${REGISTRY}/${REPOSITORY}:$(shell bin/yq '.tls.selfSigner.image.tag' ./cockroachdb/values.yaml) .
##@ Release
release: ## publish the build artifacts to S3
@build/release.sh
build-and-push/self-signer: bin/yq ## push the self-signer image
@docker buildx build --platform=linux/amd64,linux/arm64 -f build/docker-image/self-signer-cert-utility/Dockerfile \
--build-arg COCKROACH_VERSION=$(shell bin/yq '.appVersion' ./cockroachdb/Chart.yaml) --push \
-t ${REGISTRY}/${REPOSITORY}:$(shell bin/yq '.tls.selfSigner.image.tag' ./cockroachdb/values.yaml) .
##@ Dev
dev/clean: ## remove built artifacts
@rm -r build/artifacts/
## Setup/teardown registries for easier local dev
dev/registries/up: bin/k3d
@if [ "`docker ps -f name=registry.localhost -q`" = "" ]; then \
echo "$(CYAN)Starting local Docker registry (for fast offline image push/pull)...$(NC)"; \
./tests/k3d/registries.sh up $(DOCKER_NETWORK_NAME); \
fi
dev/registries/down: bin/k3d
@if [ "`docker ps -f name=registry.localhost -q`" != "" ]; then \
echo "$(CYAN)Stopping local Docker registry (for fast offline image push/pull)...$(NC)"; \
./tests/k3d/registries.sh down $(DOCKER_NETWORK_NAME); \
fi
dev/registries/bounce: bin/k3d dev/registries/down dev/registries/up
dev/push/local: dev/registries/up
@echo "$(CYAN)Pushing image to local registry...$(NC)"
@docker build --platform=linux/amd64 -f build/docker-image/self-signer-cert-utility/Dockerfile \
--build-arg COCKROACH_VERSION=$(shell bin/yq '.appVersion' ./cockroachdb/Chart.yaml) \
-t ${LOCAL_REGISTRY}/${REPOSITORY}:$(shell bin/yq '.tls.selfSigner.image.tag' ./cockroachdb/values.yaml) .
@docker push "${LOCAL_REGISTRY}/${REPOSITORY}:$(shell bin/yq '.tls.selfSigner.image.tag' ./cockroachdb/values.yaml)"
##@ Test
test/cluster: bin/k3d test/cluster/up ## start a local k3d cluster for testing
test/cluster/bounce: bin/k3d test/cluster/down test/cluster/up ## restart a local k3d cluster for testing
test/cluster/up: bin/k3d
@bin/k3d cluster list | grep $(K3D_CLUSTER) || ./tests/k3d/dev-cluster.sh up --name "$(K3D_CLUSTER)" --nodes $(CLUSTER_SIZE)
test/cluster/down: bin/k3d
./tests/k3d/dev-cluster.sh down --name "$(K3D_CLUSTER)"
test/e2e/%: PKG=$*
test/e2e/%: bin/cockroach bin/kubectl bin/helm build/self-signer test/cluster ## run e2e tests for package (e.g. install or rotate)
@PATH="$(PWD)/bin:${PATH}" go test -timeout 30m -v ./tests/e2e/${PKG}/... || EXIT_CODE=$$?; \
$(MAKE) test/cluster/down; \
exit $${EXIT_CODE:-0}
test/lint: bin/helm ## lint the helm chart
@build/lint.sh && bin/helm lint cockroachdb
test/template: bin/cockroach bin/helm ## Run template tests
@PATH="$(PWD)/bin:${PATH}" go test -v ./tests/template/...
test/units: bin/cockroach ## Run unit tests in ./pkg/...
@PATH="$(PWD)/bin:${PATH}" go test -v ./pkg/...
##@ Binaries
bin: bin/cockroach bin/helm bin/k3d bin/kubectl bin/yq ## install all binaries
bin/cockroach: ## install cockroach
@mkdir -p bin
@curl -L $(COCKROACH_BIN) | tar -xzf - -C bin/ --strip-components 1
@rm -rf bin/lib
bin/helm: ## install helm
@mkdir -p bin
@curl -L $(HELM_BIN) | tar -xzf - -C bin/ --strip-components 1
@rm -f bin/README.md bin/LICENSE
bin/k3d: ## install k3d
@mkdir -p bin
@curl -Lo bin/k3d $(K3D_BIN)
@chmod +x bin/k3d
bin/kubectl: ## install kubectl
@mkdir -p bin
@curl -Lo bin/kubectl $(KUBECTL_BIN)
@chmod +x bin/kubectl
bin/yq: ## install yq
@mkdir -p bin
@curl -Lo bin/yq $(YQ_BIN)
@chmod +x bin/yq
bin/jq: ## install jq
@mkdir -p bin
@curl -Lo bin/jq $(JQ_BIN)
@chmod +x bin/jq
bin/opm: ## install opm
@mkdir -p bin
@curl -Lo bin/opm.tar.gz $(OPM_TAR)
@tar xvf bin/opm.tar.gz
@mv $(OPM_BIN) bin/opm
@chmod +x bin/opm
build-and-release-olm-operator: bin/yq bin/jq bin/opm
./build/olm_builder.sh
prepare_bundle: bin/yq bin/jq
./build/olm_builder.sh "update_olm_operator"
build-and-push-operator-image:
docker buildx build --platform=linux/amd64,linux/arm64 \
-t $(QUAY_DOCKER_REGISTRY)/$(QUAY_PROJECT)/$(HELM_OPERATOR_IMAGE):$(VERSION) --push -f build/docker-image/operator/Dockerfile .
build-and-push-bundle-image:
docker buildx build --platform=linux/amd64,linux/arm64 \
-t $(QUAY_DOCKER_REGISTRY)/$(QUAY_PROJECT)/$(BUNDLE_IMAGE):$(VERSION) --push -f build/docker-image/olm-catalog/bundle.Dockerfile ./