forked from nats-io/nack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
210 lines (180 loc) · 7.13 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
200
201
202
203
204
205
206
207
208
209
210
export GO111MODULE := on
now := $(shell date -u +%Y-%m-%dT%H:%M:%S%z)
gitBranch := $(shell git rev-parse --abbrev-ref HEAD)
gitCommit := $(shell git rev-parse --short HEAD)
repoDirty := $(shell git diff --quiet || echo "-dirty")
VERSION ?= version-not-set
linkerVars := -X main.BuildTime=$(now) -X main.GitInfo=$(gitBranch)-$(gitCommit)$(repoDirty) -X main.Version=$(VERSION)
drepo ?= natsio
jetstreamGenIn:= $(shell grep -l -R -F "// +k8s:" pkg/jetstream/apis)
jetstreamSrc := $(shell find cmd/jetstream-controller pkg/jetstream controllers/jetstream -name "*.go") pkg/jetstream/apis/jetstream/v1beta2/zz_generated.deepcopy.go
configReloaderSrc := $(shell find cmd/nats-server-config-reloader/ pkg/natsreloader/ -name "*.go")
bootConfigSrc := $(shell find cmd/nats-boot-config/ pkg/bootconfig/ -name "*.go")
# You might override this so as to use a more recent version, to update old
# generated imports, and so migrate away from old import paths and get back to
# a consistent import tree.
codeGeneratorDir ?=
default:
# Try these (read Makefile for more recipes):
# make jetstream-controller
# make nats-server-config-reloader
# make nats-boot-config
pkg/jetstream/generated pkg/jetstream/apis/jetstream/v1beta2/zz_generated.deepcopy.go: fetch-modules $(jetstreamGenIn) pkg/k8scodegen/file-header.txt
rm -rf pkg/jetstream/generated
# Temporary chmod fix until we migrate to kube_codegen.sh
D="$(codeGeneratorDir)"; : "$${D:=`go list -m -f '{{.Dir}}' k8s.io/code-generator`}"; \
chmod u+x "$$D/generate-internal-groups.sh"; \
GOFLAGS='' bash "$$D/generate-groups.sh" all \
github.com/nats-io/nack/pkg/jetstream/generated \
github.com/nats-io/nack/pkg/jetstream/apis \
"jetstream:v1beta2" \
--output-base . \
--go-header-file pkg/k8scodegen/file-header.txt
mv github.com/nats-io/nack/pkg/jetstream/generated pkg/jetstream/generated
mv github.com/nats-io/nack/pkg/jetstream/apis/jetstream/v1beta2/zz_generated.deepcopy.go pkg/jetstream/apis/jetstream/v1beta2/zz_generated.deepcopy.go
rm -rf github.com
jetstream-controller: $(jetstreamSrc)
go build -race -o $@ \
-ldflags "$(linkerVars)" \
github.com/nats-io/nack/cmd/jetstream-controller
jetstream-controller.docker: $(jetstreamSrc)
CGO_ENABLED=0 GOOS=linux go build -o $@ \
-ldflags "-s -w $(linkerVars)" \
-tags timetzdata \
github.com/nats-io/nack/cmd/jetstream-controller
.PHONY: jetstream-controller-docker
jetstream-controller-docker:
ifneq ($(ver),)
docker build --tag $(drepo)/jetstream-controller:$(ver) \
--build-arg VERSION=$(ver) \
--file docker/jetstream-controller/Dockerfile .
else
# Missing version, try this.
# make jetstream-controller-docker ver=1.2.3
exit 1
endif
.PHONY: jetstream-controller-dockerx
jetstream-controller-dockerx:
ifneq ($(ver),)
# Ensure 'docker buildx ls' shows correct platforms.
docker buildx build \
--tag $(drepo)/jetstream-controller:$(ver) --tag $(drepo)/jetstream-controller:latest \
--build-arg VERSION=$(ver) \
--platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 \
--file docker/jetstream-controller/Dockerfile \
--push .
else
# Missing version, try this.
# make jetstream-controller-dockerx ver=1.2.3
exit 1
endif
nats-server-config-reloader: $(configReloaderSrc)
go build -race -o $@ \
-ldflags "$(linkerVars)" \
github.com/nats-io/nack/cmd/nats-server-config-reloader
nats-server-config-reloader.docker: $(configReloaderSrc)
CGO_ENABLED=0 GOOS=linux go build -o $@ \
-ldflags "-s -w $(linkerVars)" \
-tags timetzdata \
github.com/nats-io/nack/cmd/nats-server-config-reloader
.PHONY: nats-server-config-reloader-docker
nats-server-config-reloader-docker:
ifneq ($(ver),)
docker build --tag $(drepo)/nats-server-config-reloader:$(ver) \
--build-arg VERSION=$(ver) \
--file docker/nats-server-config-reloader/Dockerfile .
else
# Missing version, try this.
# make nats-server-config-reloader-docker ver=1.2.3
exit 1
endif
.PHONY: nats-server-config-reloader-dockerx
nats-server-config-reloader-dockerx:
ifneq ($(ver),)
# Ensure 'docker buildx ls' shows correct platforms.
docker buildx build \
--tag $(drepo)/nats-server-config-reloader:$(ver) --tag $(drepo)/nats-server-config-reloader:latest \
--build-arg VERSION=$(ver) \
--platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 \
--file docker/nats-server-config-reloader/Dockerfile \
--push .
else
# Missing version, try this.
# make nats-server-config-reloader-dockerx ver=1.2.3
exit 1
endif
nats-boot-config: $(bootConfigSrc)
go build -race -o $@ \
-ldflags "$(linkerVars)" \
github.com/nats-io/nack/cmd/nats-boot-config
nats-boot-config.docker: $(bootConfigSrc)
CGO_ENABLED=0 GOOS=linux go build -o $@ \
-ldflags "-s -w $(linkerVars)" \
-tags timetzdata \
github.com/nats-io/nack/cmd/nats-boot-config
.PHONY: nats-boot-config-docker
nats-boot-config-docker:
ifneq ($(ver),)
docker build --tag $(drepo)/nats-boot-config:$(ver) \
--build-arg VERSION=$(ver) \
--file docker/nats-boot-config/Dockerfile .
else
# Missing version, try this.
# make nats-boot-config-docker ver=1.2.3
exit 1
endif
.PHONY: nats-boot-config-dockerx
nats-boot-config-dockerx:
ifneq ($(ver),)
# Ensure 'docker buildx ls' shows correct platforms.
docker buildx build \
--tag $(drepo)/nats-boot-config:$(ver) --tag $(drepo)/nats-boot-config:latest \
--build-arg VERSION=$(ver) \
--platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 \
--file docker/nats-boot-config/Dockerfile \
--push .
else
# Missing version, try this.
# make nats-boot-config-dockerx ver=1.2.3
exit 1
endif
.PHONY: fetch-modules
# This will error if we have removed some code to be regenerated, so we instead silence it and force success
fetch-modules:
go list -f '{{with .Module}}{{end}}' all >/dev/null 2>&1 || true
.PHONY: build
build: jetstream-controller nats-server-config-reloader nats-boot-config
.PHONY: test
test:
go vet ./controllers/... ./pkg/natsreloader/...
go test -race -cover -count=1 -timeout 10s ./controllers/... ./pkg/natsreloader/...
.PHONY: clean
clean:
rm -f jetstream-controller jetstream-controller.docker \
nats-server-config-reloader nats-server-config-reloader.docker \
nats-boot-config nats-boot-config.docker
tools/minikube:
mkdir -p $(dir $@)
curl -L -o $@ https://storage.googleapis.com/minikube/releases/v1.25.1/minikube-linux-amd64
chmod u+x $@
tools/kubeconfig.yaml:
mkdir -p $(dir $@)
touch $@
chmod 600 $@
.PHONY: minikube-start
minikube-start: kver ?= 1.22.2
minikube-start: tools/kubeconfig.yaml tools/minikube
KUBECONFIG=$(word 1,$^) $(word 2,$^) start --vm-driver=docker --kubernetes-version=v$(kver) \
--extra-config=apiserver.service-account-signing-key-file=/var/lib/minikube/certs/sa.key \
--extra-config=apiserver.service-account-key-file=/var/lib/minikube/certs/sa.pub \
--extra-config=apiserver.service-account-issuer=api \
--extra-config=apiserver.service-account-api-audiences=api
.PHONY: minikube-stop
minikube-stop: tools/kubeconfig.yaml tools/minikube
KUBECONFIG=$(word 1,$^) $(word 2,$^) stop
.PHONY: minikube-delete
minikube-delete: tools/kubeconfig.yaml tools/minikube
KUBECONFIG=$(word 1,$^) $(word 2,$^) delete
.PHONY: minikube-status
minikube-status: tools/kubeconfig.yaml tools/minikube
KUBECONFIG=$(word 1,$^) $(word 2,$^) status