forked from pomerium/ingress-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
253 lines (205 loc) · 8.09 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
KUBEENV_GOARCH=$(shell go env GOARCH)
CRD_PACKAGE=github.com/pomerium/ingress-controller/apis/ingress/v1
# Image URL to use all building/pushing image targets
IMG?=ingress-controller:latest
CRD_OPTIONS?=
ENVTEST_K8S_VERSION=$(shell go list -f '{{.Module.Version}}' k8s.io/api | sed 's/v0/1/')
ENVTEST_VERSION=$(shell go list -f '{{.Module.Version}}' sigs.k8s.io/controller-runtime/tools/setup-envtest)
CONTROLLER_GEN=go run sigs.k8s.io/controller-tools/cmd/[email protected]
# 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
# Pomerium core requires a special tag set to indicate
# the embedded resources would be supplied externally
GOTAGS = -tags embed_pomerium
GOLDFLAGS = -X github.com/pomerium/pomerium/internal/version.Version=$(shell go list -f '{{.Module.Version}}' github.com/pomerium/pomerium) \
-X github.com/pomerium/pomerium/internal/version.BuildMeta=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \
-X github.com/pomerium/pomerium/internal/version.ProjectName=pomerium-ingress-controller \
-X github.com/pomerium/pomerium/internal/version.ProjectURL=https://www.pomerium.io
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: all
all: build
@echo "==> $@"
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: manifests
manifests: config/crd/bases/ingress.pomerium.io_pomerium.yaml
@echo "==> $@"
config/crd/bases/ingress.pomerium.io_pomerium.yaml: apis/ingress/v1/pomerium_types.go
@echo "==> $@"
@$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role crd paths=$(CRD_PACKAGE) output:crd:artifacts:config=config/crd/bases
.PHONY: test
test: envoy manifests envtest pomerium-ui
@echo "==> $@"
@KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path --arch=$(KUBEENV_GOARCH))" go test $(GOTAGS) ./...
.PHONY: lint
lint: envoy pomerium-ui
@echo "==> $@"
@VERSION=$$(go run github.com/mikefarah/yq/[email protected] '.jobs.lint.steps[] | select(.uses == "golangci/golangci-lint-action*") | .with.version' .github/workflows/lint.yml) && \
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$$VERSION run ./...
##@ Build
.PHONY: build
build: pomerium-ui build-go ## Build manager binary.
@echo "==> $@"
# called from github actions to build multi-arch images outside of docker
.PHONY: build-ci
build-ci: envoy-ci pomerium-ui
@GOOS=linux GOARCH=amd64 go build $(GOTAGS) --ldflags="$(GOLDFLAGS)" -o bin/manager-linux-amd64 main.go
@GOOS=linux GOARCH=arm64 go build $(GOTAGS) --ldflags="$(GOLDFLAGS)" -o bin/manager-linux-arm64 main.go
##@ Build
.PHONY: build-go
build-go: envoy
@echo "==> $@"
@go build $(GOTAGS) --ldflags="$(GOLDFLAGS)" -o bin/manager main.go
.PHONY: envoy-ci
envoy-ci:
@echo "==> $@"
@TARGET=linux-amd64 scripts/get-envoy.bash
@TARGET=linux-arm64 scripts/get-envoy.bash
.PHONY: envoy
envoy:
@echo "==> $@"
@./scripts/get-envoy.bash
UI_DIR = $(shell go list -f {{.Dir}} github.com/pomerium/pomerium/ui)
internal/ui:
@echo "==> $@"
@cp -rf $(UI_DIR) ./internal
@chmod u+w internal/ui internal/ui/dist
internal/ui/node_modules: internal/ui
@echo "==> $@"
@cd internal/ui && yarn install --network-timeout 1000000
.PHONY: pomerium-ui
pomerium-ui: internal/ui/dist/index.js
internal/ui/dist/index.js: internal/ui/node_modules
@echo "==> $@"
@cd internal/ui && yarn build
.PHONY: run
run: manifests
@echo "==> $@"
@go run $(GOTAGS) ./main.go
.PHONY: docker-build
docker-build: build test ## Build docker image with the manager.
@echo "==> $@"
@docker build -t ${IMG} .
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
@echo "==> $@"
@docker push ${IMG}
.PHONE: snapshot
snapshot:
@echo "==> $@"
@goreleaser release --snapshot --rm-dist
##@ Deployment
.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
@echo "==> $@"
@$(KUSTOMIZE) build config/crd | kubectl apply -f -
.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
@echo "==> $@"
@$(KUSTOMIZE) build config/crd | kubectl delete -f -
.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
@echo "==> $@"
@cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
@$(KUSTOMIZE) build config/default | kubectl apply -f -
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
@echo "==> $@"
@$(KUSTOMIZE) build config/default | kubectl delete -f -
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
@echo "==> $@"
@mkdir -p $(LOCALBIN)
.PHONY: clean
clean:
@echo "==> $@"
@chmod -Rf u+w ./bin || true
@rm -rf pomerium/envoy/bin/*
@rm -rf $(LOCALBIN)
@rm -rf testbin
@chmod -Rf u+w internal/ui || true
@rm -rf internal/ui
KUSTOMIZE ?= $(LOCALBIN)/kustomize
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@echo "==> $@"
$(KUSTOMIZE): $(LOCALBIN)
@echo "==> $@"
@rm -rf $(KUSTOMIZE)
@curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
.PHONY: envtest
envtest: $(ENVTEST)
$(ENVTEST): $(LOCALBIN)
@echo "==> $@"
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
.PHONY: deployment
deployment: kustomize
@echo "==> $@"
@$(KUSTOMIZE) build config/default > deployment.yaml
.PHONY: docs
docs: manifests
@echo "==> $@"
@go run docs/cmd/main.go > reference.md
#
# --- internal development targets
#
.PHONY: dev-install
dev-install:
@echo "==> $@"
@echo "deleting pods..."
#@kubectl delete --force --selector app.kubernetes.io/name=pomerium pods || true
@kubectl delete deployment/pomerium -n pomerium --wait || true
@$(KUSTOMIZE) build config/dev/local --load-restrictor LoadRestrictionsNone | kubectl apply --filename -
.PHONY: dev-logs
dev-logs:
@stern -n pomerium --selector app.kubernetes.io/name=pomerium
.PHONY: dev-gen-secrets
dev-gen-secrets:
@echo "==> $@"
@$(KUSTOMIZE) build config/dev/gen_secrets | kubectl apply --filename -
.PHONY: dev-build
dev-build:
@echo "==> $@"
@make -e GOOS=linux envoy
@GOOS=linux GOARCH=arm64 go build $(GOTAGS) -o bin/manager-linux-arm64 main.go
.PHONY: dev-clean
dev-clean:
@echo "==> $@"
@kubectl delete ns/pomerium --wait || true
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef