generated from unleashed/rust-template
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
242 lines (198 loc) · 8.7 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
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
COMPOSEFILE := $(PROJECT_PATH)/compose/docker-compose.yaml
DOCKER_COMPOSE_BIN ?= $(shell which docker-compose)
DOCKER_COMPOSE := $(DOCKER_COMPOSE_BIN) -f $(COMPOSEFILE)
DOCKER ?= $(shell which podman 2> /dev/null || which docker 2> /dev/null || echo docker)
OPEN_APP ?= xdg-open
BUILDER_IMAGE_NAME ?= threescale-wasm-auth-builder
BUILDER_CONTAINER_NAME ?= threescale-wasm-auth-builder-container
.PHONY: release-extension
release-extension: export BUILD?=release
release-extension: ## Build a release WASM filter and docker image
$(MAKE) build-extension
.PHONY: build-extension
build-extension: export IMAGE_VERSION?=latest
build-extension: build ## Build WASM filter and docker image
$(MAKE) -C $(PROJECT_PATH)/servicemesh build
.PHONY: clean-extension
clean-extension: export IMAGE_VERSION?=latest
clean-extension: clean ## Clean WASM filter and docker image
$(MAKE) -C $(PROJECT_PATH)/servicemesh clean
.PHONY: push-extension
push-extension: export IMAGE_VERSION?=latest
push-extension: ## Push WASM filter docker image
$(MAKE) -C $(PROJECT_PATH)/servicemesh push
.PHONY: with-container-do
with-container-do:
$(DOCKER) run --rm -v $(PROJECT_PATH):/build:z -ti $(BUILDER_IMAGE_NAME) $(BUILDER_CMD)
.PHONY: release
release: export BUILD?=release
release: ## Build release WASM filter
$(MAKE) build
.PHONY: release-with-container
release-with-container: export BUILD?=release
release-with-container: export BUILDER_CMD=make build
release-with-container: builder-image ## Build WASM filter in release mode (via container)
$(MAKE) -C $(PROJECT_PATH) -f $(MKFILE_PATH) with-container-do
.PHONY: builder-image
builder-image:
$(DOCKER) history -q $(BUILDER_IMAGE_NAME) 2> /dev/null >&2 || \
$(DOCKER) build -t $(BUILDER_IMAGE_NAME) -f $(PROJECT_PATH)/ci/Dockerfile.build $(PROJECT_PATH)
.PHONY: clean-builder-container
clean-builder-container:
-$(DOCKER) kill $(BUILDER_CONTAINER_NAME)
.PHONY: clean-builder-image
clean-builder-image: clean-builder-container ## Remove builder container and image
-$(DOCKER) rmi $(BUILDER_IMAGE_NAME)
.PHONY: build-with-container
build-with-container: export BUILDER_CMD=make build
build-with-container: builder-image ## Build WASM filter (via container)
$(MAKE) -C $(PROJECT_PATH) -f $(MKFILE_PATH) with-container-do
.PHONY: build
build: export TARGET?=wasm32-unknown-unknown
build: export BUILD?=debug
build: ## Build WASM filter
if test "x$(BUILD)" = "xrelease"; then \
cargo build --target=$(TARGET) --release $(CARGO_EXTRA_ARGS) && \
wasm-snip -o $(PROJECT_PATH)/target/$(TARGET)/$(BUILD)/snipped.wasm $(PROJECT_PATH)/target/$(TARGET)/$(BUILD)/threescale_wasm_auth.wasm && \
mv $(PROJECT_PATH)/target/$(TARGET)/$(BUILD)/threescale_wasm_auth.wasm $(PROJECT_PATH)/target/$(TARGET)/$(BUILD)/threescale_wasm_auth_cargo.wasm && \
wasm-opt -O4 --dce -o $(PROJECT_PATH)/target/$(TARGET)/$(BUILD)/threescale_wasm_auth.wasm $(PROJECT_PATH)/target/$(TARGET)/$(BUILD)/snipped.wasm; \
else \
cargo build --target=$(TARGET) $(CARGO_EXTRA_ARGS) ; \
fi
mkdir -p $(PROJECT_PATH)/compose/wasm
cp $(PROJECT_PATH)/target/$(TARGET)/$(BUILD)/threescale_wasm_auth.wasm $(PROJECT_PATH)/compose/wasm/
ln -f $(PROJECT_PATH)/target/$(TARGET)/$(BUILD)/threescale_wasm_auth.wasm $(PROJECT_PATH)/container/plugin.wasm
clean: ## Clean WASM filter
cargo clean
rm -f $(PROJECT_PATH)/compose/wasm/threescale_wasm_auth.wasm
rm -f $(PROJECT_PATH)/container/plugin.wasm
.PHONY: clean-with-container
clean-with-container: export BUILDER_CMD=make clean
clean-with-container: builder-image ## Clean WASM filter (via container)
$(MAKE) -C $(PROJECT_PATH) -f $(MKFILE_PATH) with-container-do
.PHONY: doc
doc: ## Open project documentation
cargo doc --open
.PHONY: istio-loglevel
istio-loglevel: ## Set Istio proxy log level (use LOG_LEVEL)
$(MAKE) -C $(PROJECT_PATH)/servicemesh istio-loglevel
.PHONY: istio-logs
istio-logs: ## Stream Istio proxy logs
$(MAKE) -C $(PROJECT_PATH)/servicemesh istio-logs
.PHONY: istio-deploy
istio-deploy: build ## Deploy extension to Istio
@echo >&2 "************************************************************"
@echo >&2 " You need to copy the WASM file to the cluster and mount it"
@echo >&2 " Check EnvoyFilter and annotations in the pod deployment"
@echo >&2 "************************************************************"
$(MAKE) -C $(PROJECT_PATH)/servicemesh istio-apply
.PHONY: istio-clean
istio-clean: ## Remove extension from Istio
$(MAKE) -C $(PROJECT_PATH)/servicemesh istio-clean
.PHONY: ossm-deploy
ossm-deploy: build-extension ## Deploy extension to Openshift Service Mesh
@echo >&2 "***************************************************************"
@echo >&2 " You need to push the WASM container to an accessible registry"
@echo >&2 "***************************************************************"
$(MAKE) -C $(PROJECT_PATH)/servicemesh istio-apply
.PHONY: ossm-clean
ossm-clean: ## Remove extension from Openshift Service Mesh
$(MAKE) -C $(PROJECT_PATH)/servicemesh istio-clean
.PHONY: up
up: ## Start docker-compose containers
$(DOCKER_COMPOSE) up
.PHONY: stop
stop: ## Stop docker-compose containers
$(DOCKER_COMPOSE) stop
.PHONY: status
status: ## Status of docker-compose containers
$(DOCKER_COMPOSE) ps
.PHONY: top
top: ## Show runtime information about docker-compose containers
$(DOCKER_COMPOSE) top
kill: ## Force-stop docker-compose containers
$(DOCKER_COMPOSE) kill
.PHONY: down
down: ## Stop and remove containers and other docker-compose resources
$(DOCKER_COMPOSE) down
.PHONY: shell
shell:
$(DOCKER_COMPOSE) exec shell /bin/bash
.PHONY: proxy-info
proxy-info: export INDEX?=1
proxy-info: ## Obtain the local host address and port for a service (use SERVICE, PORT and optionally INDEX)
$(DOCKER_COMPOSE) port --index $(INDEX) $(SERVICE) $(PORT)
.PHONY: proxy-url
proxy-url: export INDEX?=1
proxy-url: export SCHEME?=http
proxy-url: ## Obtain a URL for the given service (use SERVICE, PORT and optionally INDEX)
$(DOCKER_COMPOSE) port --index $(INDEX) $(SERVICE) $(PORT)
.PHONY: proxy
proxy: export INDEX?=1
proxy: export SCHEME?=http
proxy: LOCALURL=$(shell $(DOCKER_COMPOSE) port --index $(INDEX) $(SERVICE) $(PORT))
proxy: ## Open service and port in a browser (same as proxy-info, but optionally define SCHEME and OPEN_APP)
$(OPEN_APP) $(SCHEME)://$(LOCALURL)
.PHONY: sso
sso: export SERVICE=keycloak
sso: export PORT?=8080
sso: ## Open Keycloak SSO IDP
$(MAKE) proxy
.PHONY: keycloak
keycloak: sso
.PHONY: ingress-helper
ingress-helper: export SERVICE?=ingress
ingress-helper: export PORT?=80
ingress-helper: export TARGET?=proxy-url
ingress-helper:
$(MAKE) $(TARGET)
.PHONY: ingress-url
ingress-url: ## Show the ingress URL
$(MAKE) ingress-helper
.PHONY: ingress-open
ingress-open: export TARGET?=proxy
ingress-open: ## Open the ingress URL
$(MAKE) ingress-helper
.PHONY: ingress-admin-url
ingress-admin-url: export PORT?=8001
ingress-admin-url: ## Show the ingress admin URL
$(MAKE) ingress-helper
.PHONY: ingress-admin-open
ingress-admin-open: export PORT?=8001
ingress-admin-open: export TARGET?=proxy
ingress-admin-open: ## Open the ingress admin URL
$(MAKE) ingress-helper
.PHONY: curl
curl: export SCHEME?=http
curl: export SERVICE?=ingress
curl: export INDEX?=1
curl: export PORT?=80
curl: export HOST?=web.app
curl: export USER_KEY?=invalid-key
curl: export TARGET?=$$($(DOCKER_COMPOSE) port --index $(INDEX) $(SERVICE) $(PORT))
curl: ## Perform a request to a specific service (default ingress:80 with Host: web.app, please set USER_KEY)
curl -vvv -H "Host: $(HOST)" -H "X-API-Key: $(USER_KEY)" "$(SCHEME)://$(TARGET)/$(SVC_PATH)"
.PHONY: curl-web.app
curl-web.app: export USER_KEY?=$(WEB_KEY)
curl-web.app: ## Perform a curl call to web.app (make sure to export secrets, ie. source ./env)
$(MAKE) curl
.PHONY: curl-compose
curl-compose: curl-web.app ## Perform a curl call to the docker-compose cluster
.PHONY: curl-istio
curl-istio: export KUBECTL?=kubectl
curl-istio: export ISTIO_NS?=istio-system
curl-istio: export ISTIO_INGRESS?=istio-ingressgateway
curl-istio: export SVC_PATH?=productpage
curl-istio: export TARGET?=$(shell $(KUBECTL) -n $(ISTIO_NS) get service $(ISTIO_INGRESS) -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):$(shell $(KUBECTL) -n $(ISTIO_NS) get service $(ISTIO_INGRESS) -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
curl-istio: ## Perform a curl call to your Istio Ingress
$(MAKE) curl-web.app
.PHONY: curl-ossm
curl-ossm: export KUBECTL?=oc
curl-ossm: ## Perform a curl call to your Openshift Service Mesh or Maistra Ingress
$(MAKE) curl-istio
# Check http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## Print this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)