Skip to content

Commit

Permalink
feat: Separate the config workflow into two phases: prepare and init (h…
Browse files Browse the repository at this point in the history
  • Loading branch information
CH3CHO authored Oct 25, 2023
1 parent a8509e3 commit 2a19563
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
62 changes: 48 additions & 14 deletions bin/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ DEFAULT_GATEWAY_HTTPS_PORT=443
DEFAULT_GATEWAY_METRICS_PORT=15020
DEFAULT_CONSOLE_PORT=8080

COMMAND_PREPARE="prepare"
COMMAND_INIT="init"
KNOWN_COMMANDS=($COMMAND_PREPARE, $COMMAND_INIT)

cd "$(dirname -- "$0")"
ROOT=$(dirname -- "$(pwd -P)")
COMPOSE_ROOT="$ROOT/compose"
Expand All @@ -31,6 +35,8 @@ source "$ROOT/bin/base.sh"

source "$COMPOSE_ROOT/.env"

CONFIGURED_MARK="$COMPOSE_ROOT/.configured"

initArch() {
ARCH=$(uname -m)
case $ARCH in
Expand Down Expand Up @@ -58,8 +64,14 @@ parseArgs() {

POSITIONAL_ARGS=()

COMMAND=""
MODE="wizard"

if [[ $1 != "-"* ]]; then
COMMAND="$1"
shift
fi

while [[ $# -gt 0 ]]; do
case $1 in
-r | --rerun)
Expand Down Expand Up @@ -175,20 +187,42 @@ parseArgs() {
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 [ "$MODE" == "params" ]; then
configureByArgs
else
configureStorage
configureConsole
configurePorts
if [ -z "$COMMAND" -o "$COMMAND" == "$COMMAND_PREPARE" ]; then
if [ "$MODE" == "params" ]; then
configureByArgs
else
configureStorage
configureConsole
configurePorts
fi
writeConfiguration
fi

writeConfiguration
runInitializer
outputWelcomeMessage
if [ -z "$COMMAND" -o "$COMMAND" == "$COMMAND_INIT" ]; then
runInitializer
touch "$CONFIGURED_MARK"
outputWelcomeMessage
fi
}

resetEnv() {
Expand Down Expand Up @@ -293,7 +327,6 @@ configureFileStorageByArgs() {
# A user home based path.
FILE_ROOT_DIR="${HOME}${FILE_ROOT_DIR#\~}"
fi
echo "Root: $FILE_ROOT_DIR"
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."
Expand Down Expand Up @@ -595,9 +628,12 @@ EOF
}

runInitializer() {
# Reload the latest env data from file.
source "$COMPOSE_ROOT/.env"

echo "==== Build Configurations ==== "

if [ "$USE_BUILTIN_NACOS" == "Y" ]; then
if [ "$COMPOSE_PROFILES" == "nacos" ]; then
echo "Starting built-in Nacos service..."
cd "$COMPOSE_ROOT" && runDockerCompose -p higress up -d nacos
retVal=$?
Expand All @@ -614,7 +650,7 @@ runInitializer() {
exit -1
fi

if [ "$USE_BUILTIN_NACOS" == "Y" ] && [ "${AUTO_START}" != "Y" ]; then
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=$?
Expand Down Expand Up @@ -694,7 +730,6 @@ run() {
initArch
initOS
parseArgs "$@"
CONFIGURED_MARK="$COMPOSE_ROOT/.configured"
if [ -f "$CONFIGURED_MARK" ]; then
if [ "$RERUN" == "Y" ]; then
bash $ROOT/bin/reset.sh
Expand All @@ -704,7 +739,6 @@ if [ -f "$CONFIGURED_MARK" ]; then
fi
fi
configure
touch "$CONFIGURED_MARK"
if [ "${AUTO_START}" == "Y" ]; then
echo ""
run
Expand Down
2 changes: 1 addition & 1 deletion bin/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ COMPOSE_ROOT="$ROOT/compose"
cd - > /dev/null

bash $ROOT/bin/shutdown.sh
cd "$COMPOSE_ROOT" && sudo rm -rf ./volumes && rm -f ./.configured
cd "$COMPOSE_ROOT" && rm -rf ./volumes && rm -f ./.configured
2 changes: 1 addition & 1 deletion src/get-higress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ download() {
install() {
tar -zx --exclude="docs" --exclude="src" --exclude="test" -f "$HIGRESS_TMP_FILE" -C "$DESTINATION" --strip-components=1
echo -n "$VERSION" > "$DESTINATION/VERSION"
bash "$DESTINATION/bin/configure.sh" --auto-start ${CONFIG_ARGS[@]}
bash "$DESTINATION/bin/configure.sh" ${CONFIG_ARGS[@]}
}

# update updates the product.
Expand Down

0 comments on commit 2a19563

Please sign in to comment.