This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Makefile
133 lines (101 loc) · 3.86 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
default: build
NAME:=karina
ifeq ($(VERSION),)
VERSION_TAG=$(shell git describe --abbrev=0 --tags --exact-match 2>/dev/null || git describe --abbrev=0 --all)-$(shell date +"%Y%m%d%H%M%S")
else
VERSION_TAG=$(VERSION)-$(shell date +"%Y%m%d%H%M%S")
endif
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Image URL to use all building/pushing image targets
IMG ?= flanksource/karina:latest
# Produce CRDs with v1
CRD_OPTIONS ?= "crd:crdVersions=v1"
.PHONY: help
help:
@cat docs/developer-guide/make-targets.md
.PHONY: release
release: linux darwin compress
.PHONY: build
build:
go build -o ./.bin/$(NAME) -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
.PHONY: linux
linux: .bin/$(NAME)_linux-arm64 .bin/$(NAME)_linux-amd64 .bin/$(NAME)
.bin/$(NAME)_linux-amd64:
GOOS=linux GOARCH=amd64 go build -ldflags "-X \"main.version=$(VERSION_TAG)\"" -o .bin/$(NAME)_linux-amd64
.bin/$(NAME):
GOOS=linux GOARCH=amd64 go build -ldflags "-X \"main.version=$(VERSION_TAG)\"" -o .bin/$(NAME)
.bin/$(NAME)_darwin-amd64:
GOOS=darwin GOARCH=amd64 go build -ldflags "-X \"main.version=$(VERSION_TAG)\"" -o .bin/$(NAME)_darwin-amd64
.bin/$(NAME)_linux-arm64:
GOOS=linux GOARCH=arm64 go build -ldflags "-X \"main.version=$(VERSION_TAG)\"" -o .bin/$(NAME)_linux-arm64
.bin/$(NAME)_darwin-arm64:
GOOS=darwin GOARCH=arm64 go build -ldflags "-X \"main.version=$(VERSION_TAG)\"" -o .bin/$(NAME)_darwin-arm64
.bin/$(NAME).exe:
GOOS=windows GOARCH=amd64 go build -ldflags "-X \"main.version=$(VERSION_TAG)\"" -o .bin/$(NAME).exe
.PHONY: darwin
darwin: .bin/$(NAME)_darwin-amd64 .bin/$(NAME)_linux-arm64 .bin/$(NAME)_darwin-amd64
.PHONY: windows
windows: .bin/$(NAME).exe
.PHONY: compress
compress:
upx -5 ./.bin/*
.PHONY: install
install:
cp ./.bin/$(NAME) /usr/local/bin/
.PHONY: docker
docker:
docker build ./ -t $(NAME)
.PHONY: docker-fast
docker-fast: linux-static
docker build ./ -t $(IMG) -f Dockerfile.fast
.PHONY: serve-docs
serve-docs:
cd docs && make serve
.PHONY: build-api-docs
build-api-docs:
go run main.go docs api pkg/types/inline.go pkg/types/config.go pkg/types/types.go pkg/types/nsx.go > docs/reference/config.md
go run main.go docs cli "docs/cli"
.PHONY: build-docs
build-docs:
cd docs && make build
.PHONY: deploy-docs
deploy-docs:
cd docs && make deploy
.PHONY: lint
lint: build
golangci-lint run --verbose --print-resources-usage
go run test/linter/main.go
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/api/operator/..."
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/types/..."
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/api/calico/..."
static: manifests
mkdir -p config/deploy
cd config/operator/manager && kustomize edit set image controller=${IMG}
kustomize build config/crd > config/deploy/crd.yml
kustomize build config/operator/default > config/deploy/operator.yml
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
cd config/operator/manager && kustomize edit set image controller=${IMG}
kustomize build config/operator/default | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) webhook paths="./pkg/api/operator/..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=karina paths="./pkg/operator/..." output:rbac:artifacts:config=config/operator/rbac
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif