forked from higress-group/higress-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.sh
More file actions
executable file
·814 lines (749 loc) · 23.7 KB
/
configure.sh
File metadata and controls
executable file
·814 lines (749 loc) · 23.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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
#!/usr/bin/env bash
# Copyright (c) 2023 Alibaba Group Holding Ltd.
# Licensed 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.
BUILTIN_NACOS_SERVER_URL=nacos://nacos:8848
DEFAULT_NACOS_NS=higress-system
DEFAULT_NACOS_CONSOLE_PORT=8888
DEFAULT_NACOS_HTTP_PORT=8848
DEFAULT_GATEWAY_HTTP_PORT=80
DEFAULT_GATEWAY_HTTPS_PORT=443
DEFAULT_GATEWAY_METRICS_PORT=15020
DEFAULT_CONSOLE_PORT=8080
DEFAULT_USE_PLUGIN_SERVER="Y"
COMMAND_PREPARE="prepare"
COMMAND_INIT="init"
KNOWN_COMMANDS=($COMMAND_PREPARE, $COMMAND_INIT)
cd "$(dirname -- "$0")"
ROOT=$(dirname -- "$(pwd -P)")
COMPOSE_ROOT="$ROOT/compose"
cd - >/dev/null
source "$ROOT/bin/base.sh"
source "$COMPOSE_ROOT/.env"
HIGRESS_PLUGIN_SERVER_TAG=${HIGRESS_PLUGIN_SERVER_TAG:-2.2.1}
CONFIGURED_MARK="$COMPOSE_ROOT/.configured"
initArch() {
ARCH=$(uname -m)
case $ARCH in
armv5*) ARCH="armv5";;
armv6*) ARCH="armv6";;
armv7*) ARCH="arm";;
aarch64) ARCH="arm64";;
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
esac
}
initOS() {
OS="$(uname|tr '[:upper:]' '[:lower:]')"
case "$OS" in
# Minimalist GNU for Windows
mingw*|cygwin*) OS='windows';;
esac
}
parseArgs() {
resetEnv
POSITIONAL_ARGS=()
COMMAND=""
MODE="wizard"
if [[ $1 != "-"* ]]; then
COMMAND="$1"
shift
fi
while [[ $# -gt 0 ]]; do
case $1 in
-r | --rerun)
RERUN="Y"
shift
;;
-a | --auto-start)
AUTO_START="Y"
shift
;;
-c)
CONFIG_URL="$2"
MODE="params"
shift
shift
;;
--config-url=*)
CONFIG_URL="${1#*=}"
MODE="params"
shift
;;
--use-builtin-nacos)
USE_BUILTIN_NACOS="Y"
MODE="params"
shift
;;
--nacos-ns=*)
NACOS_NS="${1#*=}"
MODE="params"
shift
;;
--nacos-username=*)
NACOS_USERNAME="${1#*=}"
MODE="params"
shift
;;
--nacos-password=*)
NACOS_PASSWORD="${1#*=}"
MODE="params"
shift
;;
-k)
NACOS_DATA_ENC_KEY="${2}"
MODE="params"
shift
shift
;;
--data-enc-key=*)
NACOS_DATA_ENC_KEY="${1#*=}"
MODE="params"
shift
;;
--s)
CONFIG_STORAGE="$2"
MODE="params"
shift
shift
;;
--storage=*)
CONFIG_STORAGE="${1#*=}"
MODE="params"
shift
;;
--nacos-console-port=*)
NACOS_CONSOLE_PORT="${1#*=}"
MODE="params"
shift
;;
--nacos-service-port=*)
NACOS_CONSOLE_PORT="${1#*=}"
MODE="params"
shift
;;
--nacos-port=*)
NACOS_HTTP_PORT="${1#*=}"
MODE="params"
shift
;;
--gateway-http-port=*)
GATEWAY_HTTP_PORT="${1#*=}"
MODE="params"
shift
;;
--gateway-https-port=*)
GATEWAY_HTTPS_PORT="${1#*=}"
MODE="params"
shift
;;
--gateway-metrics-port=*)
GATEWAY_METRICS_PORT="${1#*=}"
MODE="params"
shift
;;
--console-port=*)
CONSOLE_PORT="${1#*=}"
MODE="params"
shift
;;
--use-plugin-server)
USE_PLUGIN_SERVER="Y"
MODE="params"
shift
;;
--no-plugin-server)
USE_PLUGIN_SERVER="N"
MODE="params"
shift
;;
-h | --help)
outputUsage
exit 0
;;
-* | --*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
if [ -n "$COMMAND" ] && [[ ! ${KNOWN_COMMANDS[@]} =~ "$COMMAND" ]]; then
echo "Unknown command: $COMMAND"
exit 1
fi
if [ "$COMMAND" == "$COMMAND_PREPARE" ]; then
if [ "$AUTO_START" == "Y" ]; then
echo "Auto start flag is not available in \"$COMMAND_PREPARE\" command."
exit 1
fi
elif [ "$COMMAND" == "$COMMAND_INIT" ]; then
if [ "$MODE" == "params" ]; then
echo "No configuration change is allowed in \"$COMMAND_INIT\" command."
exit 1
fi
fi
}
configure() {
if [ -z "$COMMAND" -o "$COMMAND" == "$COMMAND_PREPARE" ]; then
if [ "$MODE" == "params" ]; then
configureByArgs
else
configureStorage
configurePluginServer
configureConsole
configurePorts
fi
writeConfiguration
fi
if [ -z "$COMMAND" -o "$COMMAND" == "$COMMAND_INIT" ]; then
runInitializer
touch "$CONFIGURED_MARK"
outputWelcomeMessage
fi
}
resetEnv() {
COMPOSE_PROFILES=""
CONFIG_STORAGE=""
FILE_ROOT_DIR=""
NACOS_SERVER_URL=""
NACOS_NS=""
NACOS_USERNAME=""
NACOS_PASSWORD=""
# Not to reset the encryption key to avoid accidental key losts.
# NACOS_DATA_ENC_KEY=""
NACOS_CONSOLE_PORT=$DEFAULT_NACOS_CONSOLE_PORT
NACOS_HTTP_PORT=$DEFAULT_NACOS_HTTP_PORT
NACOS_GRPC_PORT=$(($DEFAULT_NACOS_HTTP_PORT + 1000))
GATEWAY_HTTP_PORT=$DEFAULT_GATEWAY_HTTP_PORT
GATEWAY_HTTPS_PORT=$DEFAULT_GATEWAY_HTTPS_PORT
GATEWAY_METRICS_PORT=$DEFAULT_GATEWAY_METRICS_PORT
CONSOLE_PORT=$DEFAULT_CONSOLE_PORT
USE_PLUGIN_SERVER=""
}
configureByArgs() {
if [ "$USE_BUILTIN_NACOS" == "Y" ] || [[ $CONFIG_URL == "nacos://"* ]]; then
configureNacosByArgs
elif [[ $CONFIG_URL == "file://"* ]]; then
configureFileStorageByArgs
else
echo "Invalid config service URL: $CONFIG_URL"
exit -1
fi
configureConsoleByArgs
if [ -z "$USE_PLUGIN_SERVER" ]; then
USE_PLUGIN_SERVER="$DEFAULT_USE_PLUGIN_SERVER"
fi
configurePortsByArgs
}
configureNacosByArgs() {
CONFIG_STORAGE="nacos"
if [ "$USE_BUILTIN_NACOS" == "Y" ] && [ -n "$CONFIG_URL" ]; then
echo "Only one of the following flags shall be provided: --use-builtin-nacos, --config-url"
exit -1
fi
if [ "$USE_BUILTIN_NACOS" == "Y" ] || [ -n "$CONFIG_URL" ]; then
if [ "$USE_BUILTIN_NACOS" == "Y" ]; then
COMPOSE_PROFILES="nacos"
NACOS_SERVER_URL="$BUILTIN_NACOS_SERVER_URL"
else
COMPOSE_PROFILES=""
NACOS_SERVER_URL="$CONFIG_URL"
if [[ $NACOS_SERVER_URL == *"localhost"* ]] || [[ $NACOS_SERVER_URL == *"/127."* ]]; then
echo "Higress will be running in a docker container. localhost or loopback addresses won't work. Please use a non-loopback host in the Nacos URL."
exit -1
fi
fi
else
echo "One of the following flags shall be provided: --use-builtin-nacos, --config-url"
exit -1
fi
if [ -n "$NACOS_USERNAME" ] || [ -n "$NACOS_PASSWORD" ]; then
if [ "$USE_BUILTIN_NACOS" == "Y" ]; then
echo "Built-in Nacos doesn't have auth enabled. Username and password settings will be ignored."
NACOS_USERNAME=""
NACOS_PASSWORD=""
elif [ -z "$NACOS_USERNAME" ] || [ -z "$NACOS_PASSWORD" ]; then
echo "Both Nacos username and password shall be provided."
exit -1
fi
fi
KEY_LENGTH=${#NACOS_DATA_ENC_KEY}
NACOS_USE_RANDOM_DATA_ENC_KEY=N
if [ $KEY_LENGTH == 0 ]; then
NACOS_DATA_ENC_KEY=$(cat /dev/urandom | head -n 10 | md5sum | head -c32)
NACOS_USE_RANDOM_DATA_ENC_KEY=Y
elif [ $KEY_LENGTH != 32 ] && [ "$USE_BUILTIN_NACOS" != "Y" ]; then
echo "Expecting 32 characters for --data-enc-key, but got ${KEY_LENGTH}."
exit -1
fi
}
configureFileStorageByArgs() {
CONFIG_STORAGE="file"
FILE_ROOT_DIR="${CONFIG_URL#file://}"
if [ "$OS" == "windows" ]; then
# Fix path separators
FILE_ROOT_DIR="${FILE_ROOT_DIR//\\//}"
if [[ "$FILE_ROOT_DIR" == "."* ]] || [[ "$FILE_ROOT_DIR" == "~/"* ]]; then
# A relatpath ive or user home based path. Do nothing.
:
elif [[ "$FILE_ROOT_DIR" != "/"* ]]; then
echo 'Invalid file URL. Relative path must begin with a ".". Absolute path must begin with a "/" or "~/".'
exit -1
elif [[ "$FILE_ROOT_DIR" == *":"* ]]; then
FILE_ROOT_DIR="${FILE_ROOT_DIR#/}"
fi
fi
if [[ "$FILE_ROOT_DIR" == '~/'* ]]; then
# A user home based path.
FILE_ROOT_DIR="${HOME}${FILE_ROOT_DIR#\~}"
fi
mkdir -p "$FILE_ROOT_DIR" && cd "$_"
if [ $? -ne 0 ]; then
echo "Unable to create/access the config folder. Please fix it or choose another one."
exit -1
fi
FILE_ROOT_DIR="$(pwd)"
if [ "$OS" == "windows" ]; then
FILE_ROOT_DIR="$(cygpath -w "$FILE_ROOT_DIR")"
fi
cd - &>/dev/null
}
configurePortsByArgs() {
if [ "$CONFIG_STORAGE" == "nacos" ]; then
if [ "$USE_BUILTIN_NACOS" == "Y" ]; then
validatePort $NACOS_CONSOLE_PORT "Invalid --nacos-console-port value." 1
validatePort $NACOS_HTTP_PORT "Invalid --nacos-port/--nacos-service-port value." 1
NACOS_GRPC_PORT=$(($NACOS_HTTP_PORT + 1000))
validatePort $NACOS_GRPC_PORT "--nacos-port value must be less than 64536." 1
else
NACOS_CONSOLE_PORT=$DEFAULT_NACOS_CONSOLE_PORT
NACOS_HTTP_PORT=$DEFAULT_NACOS_HTTP_PORT
NACOS_GRPC_PORT=$(($DEFAULT_NACOS_HTTP_PORT + 1000))
fi
fi
validatePort $GATEWAY_HTTP_PORT "Invalid --gateway-http-port value." 1
validatePort $GATEWAY_HTTPS_PORT "Invalid --gateway-https-port value." 1
validatePort $GATEWAY_METRICS_PORT "Invalid --gateway-metrics-port value." 1
validatePort $CONSOLE_PORT "Invalid --console-port value." 1
}
configureConsoleByArgs() {
:
}
configureStorage() {
echo "==== Configure Config Storage ===="
while true; do
readNonEmpty "Please select a configuration storage (file/nacos): "
CONFIG_STORAGE=$input
if [ "$CONFIG_STORAGE" == "nacos" ]; then
configureNacos
break
elif [ "$CONFIG_STORAGE" == "file" ]; then
configureFileStorage
break
else
echo "Unknown input: $CONFIG_STORAGE"
fi
done
}
configureNacos() {
while true; do
readNonEmpty "Use built-in Nacos service (Y/N): "
useCurrentKey=$input
if [ "$useCurrentKey" == "Y" ] || [ "$useCurrentKey" == "y" ]; then
if [ "$ARCH" != "amd64" ]; then
echo "Sorry, built-in Nacos service doesn't support your platform."
continue
fi
USE_BUILTIN_NACOS="Y"
COMPOSE_PROFILES="nacos"
NACOS_SERVER_URL="${BUILTIN_NACOS_SERVER_URL}"
NACOS_USERNAME=""
NACOS_PASSWORD=""
break
elif [ "$useCurrentKey" == "N" ] || [ "$useCurrentKey" == "n" ]; then
COMPOSE_PROFILES=""
configureStandaloneNacosServer
break
else
echo "Unknown input: $useCurrentKey"
fi
done
}
configureStandaloneNacosServer() {
while true; do
readNonEmpty "Please input Nacos service URL (e.g. nacos://192.168.1.1:8848): "
if [[ $input != "nacos://"* ]]; then
echo "Only \"nacos://\" is supported at the moment."
continue
fi
if [[ $input == *"localhost"* ]] || [[ $input == *"/127."* ]]; then
echo "Higress will be running in a docker container. localhost or loopback addresses won't work. Please use a non-loopback host in the URL."
continue
fi
NACOS_SERVER_URL=$input
break
done
while true; do
readNonEmpty "Is authentication enabled in the Nacos service (Y/N): "
enableNacosAuth=$input
if [ "$enableNacosAuth" == "Y" ] || [ "$enableNacosAuth" == "y" ]; then
readNonEmpty "Please provide the username to access Nacos: "
NACOS_USERNAME=$input
readNonEmptySecret "Please provide the password to access Nacos: "
NACOS_PASSWORD=$input
break
elif [ "$enableNacosAuth" == "N" ] || [ "$enableNacosAuth" == "n" ]; then
NACOS_USERNAME=""
NACOS_PASSWORD=""
break
else
echo "Unknown input: $enableNacosAuth"
fi
done
readWithDefault "Please input Nacos namespace ID [${DEFAULT_NACOS_NS}]: " "$NACOS_NS"
NACOS_NS=$input
while true; do
CURRENT_KEY_LENGTH=${#NACOS_DATA_ENC_KEY}
if [ $CURRENT_KEY_LENGTH != 0 ]; then
useCurrentKey=''
while true; do
readNonEmpty "Data encryption key found in the env file. Do you want to keep using the current key? (Y/N): "
useCurrentKey=$input
if [ "$useCurrentKey" == "Y" ] || [ "$useCurrentKey" == "y" ] || [ "$useCurrentKey" == "N" ] || [ "$useCurrentKey" == "n" ]; then
break
else
echo "Unknown input: $useCurrentKey"
fi
done
if [ "$useCurrentKey" == "Y" ] || [ "$useCurrentKey" == "y" ]; then
break
fi
fi
readWithDefault "Please input a 32-char long string for data encryption (Enter to generate a random one): " ""
NACOS_DATA_ENC_KEY=$input
KEY_LENGTH=${#NACOS_DATA_ENC_KEY}
if [ $KEY_LENGTH == 0 ]; then
NACOS_DATA_ENC_KEY=$(cat /dev/urandom | head -n 10 | md5sum | head -c32)
elif [ $KEY_LENGTH != 32 ]; then
echo "Expecting 32 characters, but got ${KEY_LENGTH}."
continue
fi
break
done
}
configureFileStorage() {
while true; do
readNonEmpty "Please input the root path of config folder: "
FILE_ROOT_DIR="$input"
if [ "$OS" == "windows" ]; then
if [[ "$FILE_ROOT_DIR" == "."* ]]; then
:
elif [[ "$FILE_ROOT_DIR" == "/"* ]]; then
:
elif [[ "$FILE_ROOT_DIR" == *":"* ]]; then
FILE_ROOT_DIR="${FILE_ROOT_DIR//\\//}"
else
FILE_ROOT_DIR="/${FILE_ROOT_DIR//\\//}"
fi
fi
mkdir -p "$FILE_ROOT_DIR" && cd "$_"
if [ $? -ne 0 ]; then
echo "Unable to create/access the config folder. Please fix it or choose another one."
continue
fi
FILE_ROOT_DIR="$(pwd)"
if [ "$OS" == "windows" ]; then
FILE_ROOT_DIR="$(cygpath -w "$FILE_ROOT_DIR")"
fi
cd - &>/dev/null
break
done
}
configurePluginServer() {
echo "==== Configure Plugin Server ===="
readWithDefault "Use built-in plugin server for WASM plugin distribution? (Y/N) [${DEFAULT_USE_PLUGIN_SERVER}]: " "$DEFAULT_USE_PLUGIN_SERVER"
if [ "$input" == "Y" ] || [ "$input" == "y" ]; then
USE_PLUGIN_SERVER="Y"
else
USE_PLUGIN_SERVER="N"
fi
}
configureConsole() {
# echo "==== Configure Higress Console ===="
:
}
configurePorts() {
echo "==== Configure Ports to be used by Higress ===="
if [ "$USE_BUILTIN_NACOS" == "Y" ]; then
while true; do
readPortWithDefault "Please input the local HTTP port to access the built-in Nacos service [${DEFAULT_NACOS_HTTP_PORT}]: " ${DEFAULT_NACOS_HTTP_PORT}
NACOS_HTTP_PORT=$input
NACOS_GRPC_PORT=$(($NACOS_HTTP_PORT + 1000))
validatePort $NACOS_GRPC_PORT "The HTTP port of Nacos must be less than 64536." 0
if [ $? -eq 0 ]; then
break
fi
readPortWithDefault "Please input the local HTTP port to access the built-in Nacos console [${DEFAULT_NACOS_CONSOLE_PORT}]: " ${DEFAULT_NACOS_CONSOLE_PORT}
NACOS_CONSOLE_PORT=$input
done
fi
readPortWithDefault "Please input the local HTTP port to access Higress Gateway [${DEFAULT_GATEWAY_HTTP_PORT}]: " ${DEFAULT_GATEWAY_HTTP_PORT}
GATEWAY_HTTP_PORT=$input
readPortWithDefault "Please input the local HTTPS port to access Higress Gateway [${DEFAULT_GATEWAY_HTTPS_PORT}]: " ${DEFAULT_GATEWAY_HTTPS_PORT}
GATEWAY_HTTPS_PORT=$input
readPortWithDefault "Please input the local metrics port to be listened by Higress Gateway [${DEFAULT_GATEWAY_METRICS_PORT}]: " ${DEFAULT_GATEWAY_METRICS_PORT}
GATEWAY_METRICS_PORT=$input
readPortWithDefault "Please input the local port to access Higress Console [${DEFAULT_CONSOLE_PORT}]: " ${DEFAULT_CONSOLE_PORT}
CONSOLE_PORT=$input
}
outputUsage() {
echo -n "Usage: $(basename -- "$0") [OPTIONS...]"
echo '
-a, --auto-start start Higress after configuration
-c, --config-url=URL URL of the config storage
Use Nacos with format: nacos://192.168.0.1:8848
Use local files with format: file:///opt/higress/conf
--use-builtin-nacos use the built-in Nacos service instead of
an external one to store configurations
--nacos-ns=NACOS-NAMESPACE
the ID of Nacos namespace to store configurations
default to "higress-system" if unspecified
--nacos-username=NACOS-USERNAME
the username used to access Nacos
only needed if auth is enabled in Nacos
--nacos-password=NACOS-PASSWORD
the password used to access Nacos
only needed if auth is enabled in Nacos
-k, --data-enc-key=KEY the key used to encrypt sensitive configurations
MUST contain 32 characters
A random key will be generated if unspecified
--nacos-service-port=NACOS-SERVICE-PORT
the HTTP port used to access the built-in Nacos service
default to 8848 if unspecified
--nacos-console-port=NACOS-CONSOLE-PORT
the HTTP port used to access the built-in Nacos console
default to 8888 if unspecified
--gateway-http-port=GATEWAY-HTTP-PORT
the HTTP port to be listened by the gateway
default to 80 if unspecified
--gateway-https-port=GATEWAY-HTTPS-PORT
the HTTPS port to be listened by the gateway
default to 443 if unspecified
--gateway-metrics-port=GATEWAY-METRICS-PORT
the metrics port to be listened by the gateway
default to 15020 if unspecified
--console-port=CONSOLE-PORT
the port used to visit Higress Console
default to 8080 if unspecified
--use-plugin-server use the built-in plugin server for WASM plugin
distribution via HTTP (default)
--no-plugin-server disable the built-in plugin server, WASM plugins
will be loaded from OCI images instead
-r, --rerun re-run the configuration workflow even if
Higress is already configured
-h, --help give this help list'
}
outputWelcomeMessage() {
echo '
___ ___ ___ ________ ________ _______ ________ ________
|\ \|\ \|\ \|\ ____\|\ __ \|\ ___ \ |\ ____\ |\ ____\
\ \ \\\ \ \ \ \ \___|\ \ \|\ \ \ __/|\ \ \___|_\ \ \___|_
\ \ __ \ \ \ \ \ __\ \ _ _\ \ \_|/_\ \_____ \\ \_____ \
\ \ \ \ \ \ \ \ \|\ \ \ \\ \\ \ \_|\ \|____|\ \\|____|\ \
\ \__\ \__\ \__\ \_______\ \__\\ _\\ \_______\____\_\ \ ____\_\ \
\|__|\|__|\|__|\|_______|\|__|\|__|\|_______|\_________\\_________\
\|_________\|_________|
'
echo "Higress is configured successfully."
echo ""
if [ "$CONFIG_STORAGE" == "nacos" -a "$USE_BUILTIN_NACOS" != "Y" ]; then
echo "Important Notes:"
echo " Sensitive configurations are encrypted when saving to Nacos."
echo " When configuring another server with the same Nacos configuration service, please make sure to add the following argument so all servers use the same encryption key:"
echo " --data-enc-key='${NACOS_DATA_ENC_KEY}'"
echo ""
fi
echo "Usage:"
echo " Start: $ROOT/bin/startup.sh"
echo " Stop: $ROOT/bin/shutdown.sh"
echo " View Component Statuses: $ROOT/bin/status.sh"
echo " View Logs: $ROOT/bin/logs.sh"
echo " Re-configure: $ROOT/bin/configure.sh -r"
echo ""
echo "Happy Higressing!"
}
writeConfiguration() {
if [ -z "$NACOS_SERVER_URL" ]; then
NACOS_SERVER_HTTP_URL=""
else
NACOS_SERVER_HTTP_URL=${NACOS_SERVER_URL/nacos:\/\//http://}
NACOS_SERVER_HTTP_URL=${NACOS_SERVER_HTTP_URL%/}/nacos
fi
# Build COMPOSE_PROFILES with plugin-server support
if [ "$USE_PLUGIN_SERVER" == "Y" ]; then
if [ -n "$COMPOSE_PROFILES" ]; then
COMPOSE_PROFILES="${COMPOSE_PROFILES},plugin-server"
else
COMPOSE_PROFILES="plugin-server"
fi
fi
# Generate wasm plugin URL variables
if [ "$USE_PLUGIN_SERVER" == "Y" ]; then
WASM_PLUGIN_URL_PATTERN="http://plugin-server:8002/plugins/\${name}/\${version}/plugin.wasm"
MCP_SERVER_WASM_URL="http://plugin-server:8002/plugins/mcp-server/1.0.0/plugin.wasm"
else
WASM_PLUGIN_URL_PATTERN=''
MCP_SERVER_WASM_URL=''
fi
cat <<EOF >$COMPOSE_ROOT/.env
COMPOSE_PROFILES='${COMPOSE_PROFILES}'
CONFIG_STORAGE='${CONFIG_STORAGE}'
FILE_ROOT_DIR='${FILE_ROOT_DIR}'
NACOS_SERVER_URL='${NACOS_SERVER_HTTP_URL}'
NACOS_NS='${NACOS_NS:-${DEFAULT_NACOS_NS}}'
NACOS_USERNAME='${NACOS_USERNAME}'
NACOS_PASSWORD='${NACOS_PASSWORD}'
NACOS_DATA_ENC_KEY='${NACOS_DATA_ENC_KEY}'
NACOS_USE_RANDOM_DATA_ENC_KEY='${NACOS_USE_RANDOM_DATA_ENC_KEY}'
NACOS_SERVER_TAG='${NACOS_SERVER_TAG}'
HIGRESS_RUNNER_TAG='${HIGRESS_RUNNER_TAG}'
HIGRESS_API_SERVER_TAG='${HIGRESS_API_SERVER_TAG}'
HIGRESS_CONTROLLER_TAG='${HIGRESS_CONTROLLER_TAG}'
HIGRESS_PILOT_TAG='${HIGRESS_PILOT_TAG}'
HIGRESS_GATEWAY_TAG='${HIGRESS_GATEWAY_TAG}'
HIGRESS_CONSOLE_TAG='${HIGRESS_CONSOLE_TAG}'
HIGRESS_PLUGIN_SERVER_TAG='${HIGRESS_PLUGIN_SERVER_TAG}'
WASM_PLUGIN_URL_PATTERN='${WASM_PLUGIN_URL_PATTERN}'
MCP_SERVER_WASM_URL='${MCP_SERVER_WASM_URL}'
PROMETHEUS_TAG='${PROMETHEUS_TAG}'
PROMTAIL_TAG='${PROMTAIL_TAG}'
LOKI_TAG='${LOKI_TAG}'
GRAFANA_TAG='${GRAFANA_TAG}'
NACOS_CONSOLE_PORT='${NACOS_CONSOLE_PORT}'
NACOS_HTTP_PORT='${NACOS_HTTP_PORT}'
NACOS_GRPC_PORT='${NACOS_GRPC_PORT}'
GATEWAY_HTTP_PORT='${GATEWAY_HTTP_PORT}'
GATEWAY_HTTPS_PORT='${GATEWAY_HTTPS_PORT}'
GATEWAY_METRICS_PORT='${GATEWAY_METRICS_PORT}'
CONSOLE_PORT='${CONSOLE_PORT}'
EOF
}
runInitializer() {
# Reload the latest env data from file.
source "$COMPOSE_ROOT/.env"
echo "==== Build Configurations ==== "
if [[ "$COMPOSE_PROFILES" == *"nacos"* ]]; then
echo "Starting built-in Nacos service..."
cd "$COMPOSE_ROOT" && runDockerCompose -p higress up -d nacos
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Starting built-in Nacos service fails with $retVal"
exit $retVal
fi
fi
cd "$COMPOSE_ROOT" && runDockerCompose -p higress run -T --rm initializer
local retVal=$?
if [ $retVal -ne 0 ]; then
echo "Higress configuration failed with $retVal."
exit -1
fi
if [[ "$COMPOSE_PROFILES" == *"nacos"* ]] && [ "${AUTO_START}" != "Y" ]; then
echo "Stopping built-in Nacos service..."
cd "$COMPOSE_ROOT" && runDockerCompose -p higress down --remove-orphans
local retVal=$?
if [ $retVal -ne 0 ]; then
echo "Stopping built-in Nacos service fails with $retVal"
fi
fi
}
readNonEmpty() {
# $1 prompt
while true; do
read -r -p "$1" input
if [ -n "$input" ]; then
break
fi
done
}
readNonEmptySecret() {
# $1 prompt
while true; do
read -r -s -p "$1" input
if [ -n "$input" ]; then
echo ""
break
fi
done
}
readWithDefault() {
# $1 prompt
# $2 default
read -r -p "$1" input
if [ -z "$input" ]; then
input="$2"
fi
}
readPortWithDefault() {
# $1 prompt
# $2 default
for (( ; ; )); do
read -r -p "$1" input
if [ -z "$input" ]; then
input="$2"
break
fi
validatePort "$input" "Invalid port number." 0
if [ $? -eq 0 ]; then
break
fi
done
}
validatePort() {
# $1 port
# $2 error message
# $3 exit when error if set to 1
if [[ $1 =~ ^[0-9]+$ ]] && [ $1 -gt 0 ] && [ $1 -lt 65536 ]; then
return 0
fi
echo "$2"
if [ $3 -eq 1 ]; then
exit -1
else
return -1
fi
}
run() {
echo "Starting Higress..."
echo ""
bash $ROOT/bin/startup.sh
}
initArch
initOS
parseArgs "$@"
if [ -f "$CONFIGURED_MARK" ]; then
if [ "$RERUN" == "Y" ]; then
bash $ROOT/bin/reset.sh
else
echo "Higress is already configured. Please add \"-r\" if you want to re-run the configuration workflow."
exit -1
fi
fi
configure
if [ "${AUTO_START}" == "Y" ]; then
echo ""
run
fi