-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
599 lines (523 loc) · 23.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
# Copyright AppsCode Inc. and Contributors
#
# Licensed under the AppsCode Community License 1.0.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SHELL=/bin/bash -o pipefail
PRODUCT_OWNER_NAME := appscode
PRODUCT_NAME := auditor-enterprise
ENFORCE_LICENSE ?=
GO_PKG := kubeops.dev
REPO := $(notdir $(shell pwd))
BIN := auditor
COMPRESS ?= no
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false,crdVersions={v1beta1,v1}"
CODE_GENERATOR_IMAGE ?= ghcr.io/appscode/gengo:release-1.29
API_GROUPS ?= auditor:v1alpha1
# Where to push the docker image.
REGISTRY ?= appscode
SRC_REG ?=
# This version-strategy uses git tags to set the version string
git_branch := $(shell git rev-parse --abbrev-ref HEAD)
git_tag := $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "")
commit_hash := $(shell git rev-parse --verify HEAD)
commit_timestamp := $(shell date --date="@$$(git show -s --format=%ct)" --utc +%FT%T)
VERSION := $(shell git describe --tags --always --dirty)
version_strategy := commit_hash
ifdef git_tag
VERSION := $(git_tag)
version_strategy := tag
else
ifeq (,$(findstring $(git_branch),master HEAD))
ifneq (,$(patsubst release-%,,$(git_branch)))
VERSION := $(git_branch)
version_strategy := branch
endif
endif
endif
###
### These variables should not need tweaking.
###
SRC_PKGS := cmd pkg example # directories which hold app source excluding tests (not vendored)
SRC_DIRS := $(SRC_PKGS) test hack/gendocs hack/policy # directories which hold app source (not vendored)
DOCKER_PLATFORMS := linux/amd64 linux/arm linux/arm64
BIN_PLATFORMS := $(DOCKER_PLATFORMS)
# Used internally. Users should pass GOOS and/or GOARCH.
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
BASEIMAGE_PROD ?= gcr.io/distroless/static-debian12
BASEIMAGE_DBG ?= debian:12
IMAGE := $(REGISTRY)/$(BIN)
VERSION_PROD := $(VERSION)
VERSION_DBG := $(VERSION)-dbg
TAG := $(VERSION)_$(OS)_$(ARCH)
TAG_PROD := $(TAG)
TAG_DBG := $(VERSION)-dbg_$(OS)_$(ARCH)
GO_VERSION ?= 1.23
BUILD_IMAGE ?= ghcr.io/appscode/golang-dev:$(GO_VERSION)
CHART_TEST_IMAGE ?= quay.io/helmpack/chart-testing:v3.11.0
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
ifeq ($(OS),windows)
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN).exe
endif
# Directories that we need created to build/test.
BUILD_DIRS := bin/$(OS)_$(ARCH) \
.go/bin/$(OS)_$(ARCH) \
.go/cache \
hack/config \
$(HOME)/.credentials \
$(HOME)/.kube \
$(HOME)/.minikube
DOCKERFILE_PROD = Dockerfile.in
DOCKERFILE_DBG = Dockerfile.dbg
DOCKER_REPO_ROOT := /go/src/$(GO_PKG)/$(REPO)
# If you want to build all binaries, see the 'all-build' rule.
# If you want to build all containers, see the 'all-container' rule.
# If you want to build AND push all containers, see the 'all-push' rule.
all: fmt build
# For the following OS/ARCH expansions, we transform OS/ARCH into OS_ARCH
# because make pattern rules don't match with embedded '/' characters.
build-%:
@$(MAKE) build \
--no-print-directory \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*))
container-%:
@$(MAKE) container \
--no-print-directory \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*))
push-%:
@$(MAKE) push \
--no-print-directory \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*))
all-build: $(addprefix build-, $(subst /,_, $(BIN_PLATFORMS)))
all-container: $(addprefix container-, $(subst /,_, $(DOCKER_PLATFORMS)))
all-push: $(addprefix push-, $(subst /,_, $(DOCKER_PLATFORMS)))
version:
@echo ::set-output name=version::$(VERSION)
@echo ::set-output name=version_strategy::$(version_strategy)
@echo ::set-output name=git_tag::$(git_tag)
@echo ::set-output name=git_branch::$(git_branch)
@echo ::set-output name=commit_hash::$(commit_hash)
@echo ::set-output name=commit_timestamp::$(commit_timestamp)
# Generate a typed clientset
.PHONY: clientset
clientset:
@docker run --rm \
-u $$(id -u):$$(id -g) \
-v /tmp:/.cache \
-v $$(pwd):$(DOCKER_REPO_ROOT) \
-w $(DOCKER_REPO_ROOT) \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(CODE_GENERATOR_IMAGE) \
/go/src/k8s.io/code-generator/generate-groups.sh \
deepcopy \
$(GO_PKG)/$(REPO)/client \
$(GO_PKG)/$(REPO)/apis \
"$(API_GROUPS)" \
--go-header-file "./hack/license/go.txt"
# Generate openapi schema
.PHONY: openapi
openapi: $(addprefix openapi-, $(subst :,_, $(API_GROUPS)))
@echo "Generating openapi/swagger.json"
@docker run --rm \
-u $$(id -u):$$(id -g) \
-v /tmp:/.cache \
-v $$(pwd):$(DOCKER_REPO_ROOT) \
-w $(DOCKER_REPO_ROOT) \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
--env GO111MODULE=on \
--env GOFLAGS="-mod=vendor" \
$(BUILD_IMAGE) \
go run hack/gencrd/main.go
openapi-%:
@echo "Generating openapi schema for $(subst _,/,$*)"
@mkdir -p .config/api-rules
@docker run --rm \
-u $$(id -u):$$(id -g) \
-v /tmp:/.cache \
-v $$(pwd):$(DOCKER_REPO_ROOT) \
-w $(DOCKER_REPO_ROOT) \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(CODE_GENERATOR_IMAGE) \
openapi-gen \
--v 1 --logtostderr \
--go-header-file "./hack/license/go.txt" \
--input-dirs "$(GO_PKG)/$(REPO)/apis/$(subst _,/,$*),k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/util/intstr,k8s.io/apimachinery/pkg/version,k8s.io/api/core/v1,k8s.io/api/apps/v1,kmodules.xyz/client-go/api/v1" \
--output-package "$(GO_PKG)/$(REPO)/apis/$(subst _,/,$*)" \
--report-filename .config/api-rules/violation_exceptions.list
# Generate CRD manifests
.PHONY: gen-crds
gen-crds:
@echo "Generating CRD manifests"
@docker run --rm \
-u $$(id -u):$$(id -g) \
-v /tmp:/.cache \
-v $$(pwd):$(DOCKER_REPO_ROOT) \
-w $(DOCKER_REPO_ROOT) \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(CODE_GENERATOR_IMAGE) \
controller-gen \
$(CRD_OPTIONS) \
paths="./apis/..." \
output:crd:artifacts:config=crds
crds_to_patch :=
.PHONY: patch-crds
patch-crds: $(addprefix patch-crd-, $(crds_to_patch))
patch-crd-%: $(BUILD_DIRS)
@echo "patching $*"
@kubectl patch -f crds/$* -p "$$(cat hack/crd-patch.json)" --type=json --local=true -o yaml > bin/$*
@mv bin/$* crds/$*
.PHONY: label-crds
label-crds: $(BUILD_DIRS)
@for f in crds/*.yaml; do \
echo "applying app.kubernetes.io/name=auditor label to $$f"; \
kubectl label --overwrite -f $$f --local=true -o yaml app.kubernetes.io/name=auditor > bin/crd.yaml; \
mv bin/crd.yaml $$f; \
done
.PHONY: gen-crd-protos
gen-crd-protos: $(addprefix gen-crd-protos-, $(subst :,_, $(API_GROUPS)))
gen-crd-protos-%:
@echo "Generating protobuf for $(subst _,/,$*)"
@docker run --rm \
-u $$(id -u):$$(id -g) \
-v /tmp:/.cache \
-v $$(pwd):$(DOCKER_REPO_ROOT) \
-w $(DOCKER_REPO_ROOT) \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(CODE_GENERATOR_IMAGE) \
go-to-protobuf \
--go-header-file "./hack/license/go.txt" \
--proto-import=$(DOCKER_REPO_ROOT)/vendor \
--proto-import=$(DOCKER_REPO_ROOT)/third_party/protobuf \
--apimachinery-packages=-k8s.io/apimachinery/pkg/api/resource,-k8s.io/apimachinery/pkg/apis/meta/v1,-k8s.io/apimachinery/pkg/apis/meta/v1beta1,-k8s.io/apimachinery/pkg/runtime,-k8s.io/apimachinery/pkg/runtime/schema,-k8s.io/apimachinery/pkg/util/intstr \
--packages=-k8s.io/api/core/v1,-k8s.io/api/apps/v1,-k8s.io/api/rbac/v1,-kubeops.dev/custom-resources/apis/appcatalog/v1alpha1,-kubeops.dev/monitoring-agent-api/api/v1,-kubeops.dev/offshoot-api/api/v1,-kmodules.xyz/client-go/api/v1,kmodules.xyz/custom-resources/apis/$(subst _,/,$*)
.PHONY: manifests
manifests: gen-crds patch-crds label-crds
.PHONY: gen
gen:
@true
fmt: $(BUILD_DIRS)
@docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
/bin/bash -c " \
REPO_PKG=$(GO_PKG) \
./hack/fmt.sh $(SRC_DIRS) \
"
build: $(OUTBIN)
# The following structure defeats Go's (intentional) behavior to always touch
# result files, even if they have not changed. This will still run `go` but
# will not trigger further work if nothing has actually changed.
$(OUTBIN): .go/$(OUTBIN).stamp
@true
# This will build the binary under ./.go and update the real binary iff needed.
.PHONY: .go/$(OUTBIN).stamp
.go/$(OUTBIN).stamp: $(BUILD_DIRS)
@echo "making $(OUTBIN)"
@docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
/bin/bash -c " \
PRODUCT_OWNER_NAME=$(PRODUCT_OWNER_NAME) \
PRODUCT_NAME=$(PRODUCT_NAME) \
ENFORCE_LICENSE=$(ENFORCE_LICENSE) \
ARCH=$(ARCH) \
OS=$(OS) \
VERSION=$(VERSION) \
version_strategy=$(version_strategy) \
git_branch=$(git_branch) \
git_tag=$(git_tag) \
commit_hash=$(commit_hash) \
commit_timestamp=$(commit_timestamp) \
./hack/build.sh \
"
@if [ $(COMPRESS) = yes ] && [ $(OS) != darwin ]; then \
echo "compressing $(OUTBIN)"; \
@docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
upx --brute /go/$(OUTBIN); \
fi
@if ! cmp -s .go/$(OUTBIN) $(OUTBIN); then \
mv .go/$(OUTBIN) $(OUTBIN); \
date >$@; \
fi
@echo
# Used to track state in hidden files.
DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(TAG)
container: bin/.container-$(DOTFILE_IMAGE)-PROD bin/.container-$(DOTFILE_IMAGE)-DBG
ifeq (,$(SRC_REG))
bin/.container-$(DOTFILE_IMAGE)-%: bin/$(OS)_$(ARCH)/$(BIN) $(DOCKERFILE_%)
@echo "container: $(IMAGE):$(TAG_$*)"
@sed \
-e 's|{ARG_BIN}|$(BIN)|g' \
-e 's|{ARG_ARCH}|$(ARCH)|g' \
-e 's|{ARG_OS}|$(OS)|g' \
-e 's|{ARG_FROM}|$(BASEIMAGE_$*)|g' \
$(DOCKERFILE_$*) > bin/.dockerfile-$*-$(OS)_$(ARCH)
@docker buildx build --platform $(OS)/$(ARCH) --load --pull -t $(IMAGE):$(TAG_$*) -f bin/.dockerfile-$*-$(OS)_$(ARCH) .
@docker images -q $(IMAGE):$(TAG_$*) > $@
@echo
else
bin/.container-$(DOTFILE_IMAGE)-%:
@echo "container: $(IMAGE):$(TAG_$*)"
@docker tag $(SRC_REG)/$(BIN):$(TAG_$*) $(IMAGE):$(TAG_$*)
@echo
endif
push: bin/.push-$(DOTFILE_IMAGE)-PROD bin/.push-$(DOTFILE_IMAGE)-DBG
bin/.push-$(DOTFILE_IMAGE)-%: bin/.container-$(DOTFILE_IMAGE)-%
@docker push $(IMAGE):$(TAG_$*)
@echo "pushed: $(IMAGE):$(TAG_$*)"
@echo
.PHONY: docker-manifest
docker-manifest: docker-manifest-PROD docker-manifest-DBG
docker-manifest-%:
docker manifest create -a $(IMAGE):$(VERSION_$*) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(VERSION_$*)_$(subst /,_,$(PLATFORM)))
docker manifest push $(IMAGE):$(VERSION_$*)
.PHONY: test
test: unit-tests e2e-tests
unit-tests: $(BUILD_DIRS)
@docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
/bin/bash -c " \
ARCH=$(ARCH) \
OS=$(OS) \
VERSION=$(VERSION) \
./hack/test.sh $(SRC_PKGS) \
"
# - e2e-tests can hold both ginkgo args (as GINKGO_ARGS) and program/test args (as TEST_ARGS).
# make e2e-tests TEST_ARGS="--selfhosted-operator=false --storageclass=standard" GINKGO_ARGS="--flakeAttempts=2"
#
# - Minimalist:
# make e2e-tests
#
# NB: -t is used to catch ctrl-c interrupt from keyboard and -t will be problematic for CI.
GINKGO_ARGS ?=
TEST_ARGS ?=
.PHONY: e2e-tests
e2e-tests: $(BUILD_DIRS)
@docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
--net=host \
-v $(HOME)/.kube:/.kube \
-v $(HOME)/.minikube:$(HOME)/.minikube \
-v $(HOME)/.credentials:$(HOME)/.credentials \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
--env KUBECONFIG=$(KUBECONFIG) \
--env-file=$$(pwd)/hack/config/.env \
$(BUILD_IMAGE) \
/bin/bash -c " \
ARCH=$(ARCH) \
OS=$(OS) \
VERSION=$(VERSION) \
DOCKER_REGISTRY=$(REGISTRY) \
TAG=$(TAG) \
KUBECONFIG=$${KUBECONFIG#$(HOME)} \
GINKGO_ARGS='$(GINKGO_ARGS)' \
TEST_ARGS='$(TEST_ARGS)' \
./hack/e2e.sh \
"
.PHONY: e2e-parallel
e2e-parallel:
@$(MAKE) e2e-tests GINKGO_ARGS="-p -stream --flakeAttempts=2" --no-print-directory
ADDTL_LINTERS := gofmt,goimports,unparam
.PHONY: lint
lint: $(BUILD_DIRS)
@echo "running linter"
@docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
--env GO111MODULE=on \
--env GOFLAGS="-mod=vendor" \
$(BUILD_IMAGE) \
golangci-lint run --enable $(ADDTL_LINTERS) --timeout=10m --skip-files="generated.*\.go$\" --skip-dirs-use-default --skip-dirs=client,vendor
$(BUILD_DIRS):
@mkdir -p $@
REGISTRY_SECRET ?=
KUBE_NAMESPACE ?= kubeops
ifeq ($(strip $(REGISTRY_SECRET)),)
IMAGE_PULL_SECRETS =
else
IMAGE_PULL_SECRETS = --set imagePullSecrets[0].name=$(REGISTRY_SECRET)
endif
POLICY_FILE ?= "./hack/policy/default-policy.yaml"
LICENSE_FILE ?=
.PHONY: install
install:
@cd ../installer; \
kubectl create ns $(KUBE_NAMESPACE) || true; \
kubectl label ns $(KUBE_NAMESPACE) pod-security.kubernetes.io/enforce=restricted; \
helm install auditor charts/auditor --wait \
--namespace=$(KUBE_NAMESPACE) --create-namespace \
--set-file license=$(LICENSE_FILE) \
--set registryFQDN="" \
--set image.registry=$(REGISTRY) \
--set image.tag=$(TAG) \
--set imagePullPolicy=IfNotPresent \
--set-file policy=$(POLICY_FILE) \
$(IMAGE_PULL_SECRETS); \
.PHONY: uninstall
uninstall:
@cd ../installer; \
helm uninstall auditor --namespace=$(KUBE_NAMESPACE) || true
.PHONY: purge
purge: uninstall
kubectl delete crds -l app.kubernetes.io/name=auditor
.PHONY: dev
dev: gen fmt push
.PHONY: verify
verify: verify-gen verify-modules
.PHONY: verify-modules
verify-modules:
GO111MODULE=on go mod tidy
GO111MODULE=on go mod vendor
@if !(git diff --exit-code HEAD); then \
echo "go module files are out of date"; exit 1; \
fi
.PHONY: verify-gen
verify-gen: gen fmt
@if !(git diff --exit-code HEAD); then \
echo "generated files are out of date, run make gen fmt"; exit 1; \
fi
.PHONY: add-license
add-license:
@echo "Adding license header"
@docker run --rm \
-u $$(id -u):$$(id -g) \
-v /tmp:/.cache \
-v $$(pwd):$(DOCKER_REPO_ROOT) \
-w $(DOCKER_REPO_ROOT) \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
ltag -t "./hack/license" --excludes "vendor contrib" -v
.PHONY: check-license
check-license:
@echo "Checking files have proper license header"
@docker run --rm \
-u $$(id -u):$$(id -g) \
-v /tmp:/.cache \
-v $$(pwd):$(DOCKER_REPO_ROOT) \
-w $(DOCKER_REPO_ROOT) \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
ltag -t "./hack/license" --excludes "vendor contrib" --check -v
.PHONY: ci
ci: check-license lint build unit-tests #cover verify
.PHONY: qa
qa:
@if [ "$$APPSCODE_ENV" = "prod" ]; then \
echo "Nothing to do in prod env. Are you trying to 'release' binaries to prod?"; \
exit 1; \
fi
@if [ "$(version_strategy)" = "tag" ]; then \
echo "Are you trying to 'release' binaries to prod?"; \
exit 1; \
fi
@$(MAKE) clean all-push docker-manifest --no-print-directory
.PHONY: release
release:
@if [ "$$APPSCODE_ENV" != "prod" ]; then \
echo "'release' only works in PROD env."; \
exit 1; \
fi
@if [ "$(version_strategy)" != "tag" ]; then \
echo "apply tag to release binaries and/or docker images."; \
exit 1; \
fi
@$(MAKE) clean all-push docker-manifest --no-print-directory
.PHONY: clean
clean:
rm -rf .go bin
KUBECONFIG:=$(HOME)/.kube/config
.PHONY: run
run:
go run -mod=vendor cmd/auditor/*.go run \
--v=3 --secure-port=8443 \
--kubeconfig=$(KUBECONFIG) \
--authorization-kubeconfig=$(KUBECONFIG) \
--authentication-kubeconfig=$(KUBECONFIG) \
--authentication-skip-lookup \
--license-file=$(LICENSE_FILE) \
--policy-file=$(POLICY_FILE)
.PHONY: usage
usage:
go run -mod=vendor ./cmd/auditor usage \
--server="nats://localhost:4222"
# make and load docker image to kind cluster
.PHONY: push-to-kind
push-to-kind: container
@echo "Loading docker image into kind cluster...."
@kind load docker-image $(REGISTRY)/auditor:$(TAG)
@echo "Image has been pushed successfully into kind cluster."