-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
608 lines (551 loc) · 16.7 KB
/
Copy pathMakefile
File metadata and controls
608 lines (551 loc) · 16.7 KB
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
600
601
602
603
604
605
606
607
608
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#
# Use bash explicitly in this Makefile to avoid unexpected platform
# incompatibilities among Linux distros.
#
SHELL := /bin/bash
VERSION := 0.8.0
PLUGIN_NAME := hawtio-online-console-plugin
#LAST_RELEASED_PLUGIN_IMAGE := hawtio/$(PLUGIN)
#LAST_RELEASED_VERSION ?=
CONTROLLER_GEN_VERSION := v0.6.1
OPERATOR_SDK_VERSION := v1.26.1
KUSTOMIZE_VERSION := v4.5.4
OPM_VERSION := v1.24.0
PLUGIN_IMAGE := quay.io/hawtio/online-console-plugin
PLUGIN_DOCKERFILE := Dockerfile-plugin
GATEWAY_IMAGE := quay.io/hawtio/online-console-plugin-gateway
GATEWAY_DOCKERFILE := Dockerfile-gateway
# Replace SNAPSHOT with the current timestamp
DATETIMESTAMP=$(shell date -u '+%Y%m%d-%H%M%S')
VERSION := $(subst -SNAPSHOT,-$(DATETIMESTAMP),$(VERSION))
#
# Allows for resources to be loaded from outside the root location of
# the kustomize config file. Ensures that resource don't need to be
# copied around the file system.
#
# See https://kubectl.docs.kubernetes.io/faq/kustomize
#
KOPTIONS := --load-restrictor LoadRestrictionsNone
#
# Deploy specific variables
#
DEPLOY := deploy
BASE := base
PATCHES := patches
PLACEHOLDER := placeholder
GATEWAY := gateway
PLUGIN := plugin
GATEWAY_ROUTE := gateway-route
MASK_IP_ADDRESSES_PATCH := $(PATCHES)/patch-mask-ip-addresses.yml
ONLINE_LOG_LEVEL_PATCH := $(PATCHES)/patch-online-log-level.yml
GATEWAY_LOG_LEVEL_PATCH := $(PATCHES)/patch-gateway-log-level.yml
#
# =======================
# Override-able Variables
# =======================
#
#
# the image name and version
# - used in kustomize install
# - need to preserve original image and version as used in other files
#
CUSTOM_PLUGIN_IMAGE ?= $(PLUGIN_IMAGE)
CUSTOM_PLUGIN_VERSION ?= $(VERSION)
CUSTOM_GATEWAY_IMAGE ?= $(GATEWAY_IMAGE)
CUSTOM_GATEWAY_VERSION ?= $(VERSION)
# Whether the kustomize install should be applied or just printed out
DRY_RUN ?= false
# The namespace to deploy the plugin to on the Openshift cluster
NAMESPACE ?= hawtio-online
# Uninstall all hawtio-onlineresources: [true|false]
UNINSTALL_ALL ?=false
# Whether to mask ip addresses in network responses
MASK_IP_ADDRESSES ?= false
# The Log Level of the hawtio-online server
ONLINE_LOG_LEVEL ?= info
# The Log Level of the hawtio gateway server
GATEWAY_LOG_LEVEL ?= info
#
# =======================
# Macros
# =======================
#
#
# Macro for editing kustomization to define the image references
#
# Parameters:
# - directory of the kustomization.yaml
#
define set-kustomize-plugin-image
$(if $(filter $(PLUGIN_IMAGE),$(CUSTOM_PLUGIN_IMAGE):$(CUSTOM_PLUGIN_VERSION)),,\
@cd $(DEPLOY)/$(1) || exit 1 && \
$(KUSTOMIZE) edit set image $(PLUGIN_IMAGE)=$(CUSTOM_PLUGIN_IMAGE):$(CUSTOM_PLUGIN_VERSION))
endef
define set-kustomize-gateway-image
$(if $(filter $(GATEWAY_IMAGE),$(CUSTOM_GATEWAY_IMAGE):$(CUSTOM_GATEWAY_VERSION)),,\
@cd $(DEPLOY)/$(1) || exit 1 && \
$(KUSTOMIZE) edit set image $(GATEWAY_IMAGE)=$(CUSTOM_GATEWAY_IMAGE):$(CUSTOM_GATEWAY_VERSION))
endef
#
# Macro for editing kustomization to define the namespace
#
# Parameters:
# - directory of the kustomization.yaml
#
define set-kustomize-namespace
@cd $(DEPLOY)/$(1) || exit 1 && \
$(KUSTOMIZE) edit set namespace $(NAMESPACE)
endef
#
# Add or remove a patch on a kustomization.yaml
# targetting a kind of resource
#
# Parameters:
# - directory of the kustomization.yaml
# - [add, remove]
# - path of patch
# - kind of resources, eg. Deployment, Role
#
define add-remove-kind-patch
@cd $(DEPLOY)/$(1) || exit 1 && \
$(KUSTOMIZE) edit $(2) patch --path $(3) --kind $(4) &> /dev/null
endef
define LICENSE_HEADER
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
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.
endef
export LICENSE_HEADER
#
# =======================
# Environment Checks
# =======================
#
kubectl:
ifeq (, $(shell command -v oc 2> /dev/null))
ifeq (, $(shell command -v kubectl 2> /dev/null))
$(error "No oc or kubectl found in PATH. Please install and re-run")
else
KUBECTL=$(shell command -v kubectl 2> /dev/null)
endif
else
KUBECTL=$(shell command -v oc 2> /dev/null)
endif
kustomize:
ifeq (, $(shell command -v kustomize 2> /dev/null))
$(error "No kustomize found in PATH. Please install and re-run")
else
KUSTOMIZE=$(shell command -v kustomize 2> /dev/null)
endif
yarn:
ifeq (, $(shell command -v yarn 2> /dev/null))
$(error "No yarn found in PATH. Please install and re-run")
else
YARN=$(shell command -v yarn 2> /dev/null)
endif
jq:
ifeq (, $(shell command -v jq 2> /dev/null))
$(error "No jq found in PATH. Please install and re-run")
else
JQ=$(shell command -v jq 2> /dev/null)
endif
container-builder:
ifeq (, $(shell command -v podman 2> /dev/null))
ifeq (, $(shell command -v docker 2> /dev/null))
$(error "No docker or podman found in PATH. Please install and re-run")
else
CONTAINER_BUILDER=$(shell command -v docker 2> /dev/null)
endif
else
CONTAINER_BUILDER=$(shell command -v podman 2> /dev/null)
endif
#
# Checks if the cluster user has the necessary privileges to be a cluster-admin
# In this case if the user can list the CRDs then probably a cluster-admin
#
check-admin: kubectl
@output=$$($(KUBECTL) get crd 2>&1) || (echo "****" && echo "**** ERROR: Cannot continue as user is not a Cluster-Admin ****" && echo "****"; exit 1)
.PHONY: kubectl kustomize yarn container-builder check-admin
#
# =========================
# Development and Building
# =========================
#
#---
#
#@ setup
#
#== Sets up yarn by installing all dependencies
#
#=== Calls yarn
#
#---
setup: yarn
yarn install
#---
#
#@ build
#
#== Performs a local build of the console plugin
#
#=== Calls setup
#
#---
build: setup
@echo "####### Building $(PLUGIN_NAME) ..."
yarn build
#---
#
#@ clean
#
#== Cleans the local build by removing everything in dist/
#
#---
clean:
rm -rf packages/*/dist
#---
#
#@ lint
#
#== Executes linting of all source code
#
#=== Calls setup
#
#---
lint: setup
yarn lint
#---
#
#@ lint-fix
#
#== Executes linting of all source code and fixes where it can
#
#=== Calls setup
#
#---
lint-fix: setup
yarn lint:fix
#---
#
#@ format
#
#== Checks the formatting of all source code
#
#=== Calls setup
#
#---
format: setup
yarn format:check
#---
#
#@ format-fix
#
#== Checks the formatting of all source code and fixes it
#
#=== Calls setup
#
#---
format-fix: setup
yarn format:fix
#---
#
#@ test
#
#== Tests the build
#
#=== Calls setup
#
#---
test: setup
yarn test
#---
#
#@ test
#
#== Tests the build
#
#=== Calls setup
#
#---
audit: setup
yarn npm audit --all
#---
#
#@ license
#
#== Extracts all the licenses from the project and create a text file in docker/
#
#=== Calls yarn
#
#---
license: yarn
yarn license
.plugin-image: container-builder license
@echo "####### Building Hawtio Online Console Plugin image... $(CONTAINER_BUILDER)"
$(CONTAINER_BUILDER) build -t $(CUSTOM_PLUGIN_IMAGE):$(CUSTOM_PLUGIN_VERSION) -f $(PLUGIN_DOCKERFILE) .
.gateway-image: container-builder
@echo "####### Building Hawtio Online Console Plugin Gateway image..."
$(CONTAINER_BUILDER) build -t $(CUSTOM_GATEWAY_IMAGE):$(CUSTOM_GATEWAY_VERSION) -f $(GATEWAY_DOCKERFILE) .
#---
#
#@ image
#
#== Executes a local build of the production container images
#
#=== Calls container-builder
#
#---
image: license .plugin-image .gateway-image
.plugin-image-push: container-builder
$(CONTAINER_BUILDER) push $(CUSTOM_PLUGIN_IMAGE):$(CUSTOM_PLUGIN_VERSION)
.gateway-image-push: container-builder
$(CONTAINER_BUILDER) push $(CUSTOM_GATEWAY_IMAGE):$(CUSTOM_GATEWAY_VERSION)
#---
#
#@ image-push
#
#== Pushes the locally build image to the registry
#
#=== Calls container-builder
#
#---
image-push: .plugin-image-push .gateway-image-push
.PHONY: build clean lint lint-fix format format-fix license .plugin-image .gateway-image image .plugin-image-push .gateway-image-push image-push
#
# ============================
# Installation and Deployment
# ============================
#
#---
#
#@ generate-proxying
#
#== Generate a client certificate and TLS secret for Hawtio proxying on Openshift
#
#=== Calls check-admin
#
#* PARAMETERS:
#** NAMESPACE: Set the namespace for the secret
#
#---
generate-proxying: check-admin
NAMESPACE=$(NAMESPACE) ./scripts/generate-proxying.sh
.mask-ip-addresses:
ifeq ($(MASK_IP_ADDRESSES), true)
@$(call add-remove-kind-patch,$(BASE)/$(GATEWAY),add,../../$(MASK_IP_ADDRESSES_PATCH),Deployment)
else
@$(call add-remove-kind-patch,$(BASE)/$(GATEWAY),remove,../../$(MASK_IP_ADDRESSES_PATCH),Deployment)
endif
.onlineLogLevel:
@sed -i 's~.*value:.*~ value: "$(ONLINE_LOG_LEVEL)"~' "$(DEPLOY)/$(ONLINE_LOG_LEVEL_PATCH)"
ifeq ($(ONLINE_LOG_LEVEL), info)
@$(call add-remove-kind-patch,$(BASE)/$(PLUGIN),remove,../../$(ONLINE_LOG_LEVEL_PATCH),Deployment)
else
@$(call add-remove-kind-patch,$(BASE)/$(PLUGIN),add,../../$(ONLINE_LOG_LEVEL_PATCH),Deployment)
endif
.gatewayLogLevel:
@sed -i 's~.*value:.*~ value: "$(GATEWAY_LOG_LEVEL)"~' "$(DEPLOY)/$(GATEWAY_LOG_LEVEL_PATCH)"
ifeq ($(GATEWAY_LOG_LEVEL), info)
@$(call add-remove-kind-patch,$(BASE)/$(GATEWAY),remove,../../$(GATEWAY_LOG_LEVEL_PATCH),Deployment)
else
@$(call add-remove-kind-patch,$(BASE)/$(GATEWAY),add,../../$(GATEWAY_LOG_LEVEL_PATCH),Deployment)
endif
#---
#
#@ install-gateway
#
#== Install the gateway service into the cluster
#
#=== Calls kustomize
#=== Calls kubectl
#=== Calls jq
#=== Calls generate-proxying
#
#* PARAMETERS:
#** NAMESPACE: Set the namespace for the resources
#** GATEWAY_LOG_LEVEL: Set whether the logging level of the online server
#** [ info | debug | trace ]
#** (info by default)
#** CUSTOM_GATEWAY_IMAGE: Set a custom gateway image to install from
#** CUSTOM_GATEWAY_VERSION: Set a custom gateway version to install from
#** DRY_RUN: Print the resources to be applied instead of applying them [ true | false ]
#
#---
install-gateway: kustomize kubectl jq
# Set the namespace in the setup kustomization yaml
@$(call set-kustomize-namespace,$(BASE)/$(GATEWAY))
# Set the image references of the kustomization
@$(call set-kustomize-gateway-image,$(BASE)/$(GATEWAY))
# Mask IP addresses if required
@$(MAKE) .mask-ip-addresses
# Update the log level of the gateway server
@$(MAKE) -s .gatewayLogLevel
#
# Build the resources
# Either apply to the cluster or output to CLI
# Post-processes any remaining 'placeholder'
# that may remain, eg. in rolebindings
#
ifeq ($(DRY_RUN), true)
@$(KUSTOMIZE) build $(KOPTIONS) $(DEPLOY)/$(BASE)/$(GATEWAY) | \
sed 's/$(PLACEHOLDER)/$(NAMESPACE)/'
else
@$(MAKE) -s generate-proxying
@$(KUSTOMIZE) build $(KOPTIONS) $(DEPLOY)/$(BASE)/$(GATEWAY) | \
sed 's/$(PLACEHOLDER)/$(NAMESPACE)/' | \
$(KUBECTL) apply -f -
endif
#---
#
#@ install-gateway-route
#
#== Install the gateway service into the cluster and a route for external access
#
#=== Calls kustomize
#=== Calls kubectl
#=== Calls jq
#=== Calls generate-proxying
#
#* PARAMETERS:
#** NAMESPACE: Set the namespace for the resources
#** CUSTOM_GATEWAY_IMAGE: Set a custom gateway image to install from
#** CUSTOM_GATEWAY_VERSION: Set a custom gateway version to install from
#** DRY_RUN: Print the resources to be applied instead of applying them [ true | false ]
#
#---
install-gateway-route: kustomize kubectl jq install-gateway
# Set the namespace in the setup kustomization yaml
@$(call set-kustomize-namespace,$(GATEWAY_ROUTE))
# Set the image references of the kustomization
@$(call set-kustomize-gateway-image,$(GATEWAY_ROUTE))
#
# Build the resources
# Either apply to the cluster or output to CLI
# Post-processes any remaining 'placeholder'
# that may remain, eg. in rolebindings
#
ifeq ($(DRY_RUN), true)
@$(KUSTOMIZE) build $(KOPTIONS) $(DEPLOY)/$(GATEWAY_ROUTE) | \
sed 's/$(PLACEHOLDER)/$(NAMESPACE)/'
else
@$(MAKE) -s generate-proxying
@$(KUSTOMIZE) build $(KOPTIONS) $(DEPLOY)/$(GATEWAY_ROUTE) | \
sed 's/$(PLACEHOLDER)/$(NAMESPACE)/' | \
$(KUBECTL) apply -f -
endif
#---
#
#@ install-plugin
#
#== Install the plugin deployment into the cluster
#
#=== Calls kustomize
#=== Calls kubectl
#=== Calls jq
#
#* PARAMETERS:
#** NAMESPACE: Set the namespace for the resources
#** ONLINE_LOG_LEVEL: Set whether the logging level of the online server
#** [ emerg | alert | crit | error | warn | notice | info ]
#** (info by default)
#** CUSTOM_PLUGIN_IMAGE: Set a custom plugin image to install from
#** CUSTOM_PLUGIN_VERSION: Set a custom plugin version to install from
#** DRY_RUN: Print the resources to be applied instead of applying them [ true | false ]
#
#---
install-plugin: kustomize kubectl jq
# Set the namespace in the setup kustomization yaml
@$(call set-kustomize-namespace,$(BASE)/$(PLUGIN))
# Set the image references of the kustomization
@$(call set-kustomize-plugin-image,$(BASE)/$(PLUGIN))
# Update the log level of the online server
@$(MAKE) -s .onlineLogLevel
#
# Build the resources
# Either apply to the cluster or output to CLI
# Post-processes any remaining 'placeholder'
# that may remain, eg. in rolebindings
#
ifeq ($(DRY_RUN), true)
@$(KUSTOMIZE) build $(KOPTIONS) $(DEPLOY)/$(BASE)/$(PLUGIN) | \
sed 's/$(PLACEHOLDER)/$(NAMESPACE)/'
else
@$(KUSTOMIZE) build $(KOPTIONS) $(DEPLOY)/$(BASE)/$(PLUGIN) | \
sed 's/$(PLACEHOLDER)/$(NAMESPACE)/' | \
$(KUBECTL) apply -f -
./scripts/patch-console.sh $(PLUGIN_NAME)
endif
#---
#
#@ install
#
#== Install the deployment into the cluster
#
#=== Calls kustomize
#=== Calls kubectl
#=== Calls jq
#=== Calls install-gateway
#=== Calls install-plugin
#
#* PARAMETERS:
#** NAMESPACE: Set the namespace for the resources
#** CUSTOM_PLUGIN_IMAGE: Set a custom plugin image to install from
#** CUSTOM_PLUGIN_VERSION: Set a custom plugin version to install from
#** CUSTOM_GATEWAY_IMAGE: Set a custom gateway image to install from
#** CUSTOM_GATEWAY_VERSION: Set a custom gateway version to install from
#** DRY_RUN: Print the resources to be applied instead of applying them [ true | false ]
#
#---
install: kustomize kubectl jq install-gateway install-plugin
#---
#
#@ uninstall
#
#== Uninstall all previously installed resources.
#
#=== Cluster-admin privileges are required.
#
#=== Calls kustomize
#=== Calls kubectl
#
#* PARAMETERS:
#** NAMESPACE: Set the namespace to uninstall the resources from
#** DRY_RUN: Print the resources to be applied instead of applying them [true|false]
#
#---
uninstall: kubectl kustomize
# Set the namespace in the all target kustomization yaml
@$(call set-kustomize-namespace,$(BASE))
ifeq ($(DRY_RUN), false)
@$(KUSTOMIZE) build $(KOPTIONS) $(DEPLOY)/$(BASE) | kubectl delete --ignore-not-found=true -f -
else
@$(KUSTOMIZE) build $(KOPTIONS) $(DEPLOY)/$(BASE) | kubectl delete --dry-run=client -f -
endif
help: ## Show this help screen.
@awk 'BEGIN { printf "\nUsage: make \033[31m<PARAM1=val1 PARAM2=val2>\033[0m \033[36m<target>\033[0m\n"; printf "\nAvailable targets are:\n" } /^#@/ { printf "\033[36m%-15s\033[0m", $$2; subdesc=0; next } /^#===/ { printf "%-14s \033[32m%s\033[0m\n", " ", substr($$0, 5); subdesc=1; next } /^#==/ { printf "\033[0m%s\033[0m\n\n", substr($$0, 4); next } /^#\*\*/ { printf "%-14s \033[31m%s\033[0m\n", " ", substr($$0, 4); next } /^#\*/ && (subdesc == 1) { printf "\n"; next } /^#\-\-\-/ { printf "\n"; next }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
default: help
.PHONY: generate-proxying install-gateway install-gateway-route install-plugin install uninstall help