-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
107 lines (83 loc) · 2.84 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
BIN := node-policy-webhook
CRD_OPTIONS ?= "crd:trivialVersions=true"
PKG := github.com/softonic/node-policy-webhook
VERSION ?= 0.1.6-dev
ARCH ?= amd64
APP ?= node-policy-webhook
NAMESPACE ?= default
RELEASE_NAME ?= node-policy-webhook
KO_DOCKER_REPO = registry.softonic.io/node-policy-webhook
REPOSITORY ?= node-policy-webhook
IMAGE := $(BIN)
BUILD_IMAGE ?= golang:1.18-buster
deploy-prod: export IMAGE_GEN = "github.com/softonic/node-policy-webhook/cmd/node-policy-webhook"
deploy: export IMAGE_GEN = $(APP):$(VERSION)
.PHONY: all
all: dev
.PHONY: build
build: generate
go mod download
GOARCH=${ARCH} go build -ldflags "-X ${PKG}/pkg/version.Version=${VERSION}" ./cmd/node-policy-webhook/.../
.PHONY: test
test:
GOARCH=${ARCH} go test -v -ldflags "-X ${PKG}/pkg/version.Version=${VERSION}" ./...
.PHONY: image
image:
docker build -t $(IMAGE):$(VERSION) -f Dockerfile .
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest
.PHONY: dev
dev: image
kind load docker-image $(IMAGE):$(VERSION)
.PHONY: undeploy
undeploy:
kubectl delete -f manifest.yaml || true
.PHONY: deploy
deploy: manifest
kubectl apply -f manifest.yaml
.PHONY: up
up: image undeploy deploy
.PHONY: docker-push
docker-push:
docker push $(IMAGE):$(VERSION)
docker push $(IMAGE):latest
.PHONY: version
version:
@echo $(VERSION)
.PHONY: secret-values
secret-values:
./hack/generate_helm_cert_secrets $(APP) $(NAMESPACE)
.PHONY: manifest
manifest: controller-gen helm-chart secret-values
docker run --rm -v $(PWD):/app -w /app/ alpine/helm:3.2.3 template --release-name $(RELEASE_NAME) --set "image.tag=$(VERSION)" --set "image.repository=$(REPOSITORY)" -f chart/node-policy-webhook/values.yaml -f chart/node-policy-webhook/secret.values.yaml chart/node-policy-webhook > manifest.yaml
.PHONY: helm-chart
helm-chart: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) webhook paths="./..." output:crd:artifacts:config=chart/node-policy-webhook/templates
.PHONY: helm-deploy
helm-deploy: helm-chart secret-values
helm upgrade --install $(RELEASE_NAME) --namespace $(NAMESPACE) --set "image.tag=$(VERSION)" -f chart/node-policy-webhook/values.yaml -f chart/node-policy-webhook/secret.values.yaml chart/node-policy-webhook
.PHONY: generate
generate: controller-gen
$(CONTROLLER_GEN) crd:crdVersions=v1 object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# find or download controller-gen
# download controller-gen if necessary
.PHONY: controller-gen
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif