From 01c23ae6a3424cc961fe76bc325655550d698df6 Mon Sep 17 00:00:00 2001 From: "vitess-bot[bot]" <108069721+vitess-bot[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 08:28:44 -0700 Subject: [PATCH] Cherry-pick 7603abc53459065f4420c92a0ae29f5ccb1cad10 with conflicts --- examples/common/scripts/vtadmin-up.sh | 43 +++++++++++++++-- web/vtadmin/build.sh | 68 +++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 5 deletions(-) create mode 100755 web/vtadmin/build.sh diff --git a/examples/common/scripts/vtadmin-up.sh b/examples/common/scripts/vtadmin-up.sh index 387ba439fb0..2394af49858 100755 --- a/examples/common/scripts/vtadmin-up.sh +++ b/examples/common/scripts/vtadmin-up.sh @@ -1,5 +1,26 @@ #!/bin/bash +<<<<<<< HEAD +======= +# Copyright 2023 The Vitess Authors. +# +# 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. + +function output() { + echo -e "$@" +} + +>>>>>>> 7603abc534 (Update VTAdmin build script (#15839)) script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")" source "${script_dir}/../env.sh" @@ -10,9 +31,16 @@ web_dir="${script_dir}/../../../web/vtadmin" vtadmin_api_port=14200 vtadmin_web_port=14201 +<<<<<<< HEAD +======= +case_insensitive_hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]') + +output "\n\033[1;32mvtadmin-api expects vtadmin-web at, and set http-origin to \"http://${case_insensitive_hostname}:${vtadmin_web_port}\"\033[0m" + +>>>>>>> 7603abc534 (Update VTAdmin build script (#15839)) vtadmin \ - --addr "${hostname}:${vtadmin_api_port}" \ - --http-origin "http://${hostname}:${vtadmin_web_port}" \ + --addr "${case_insensitive_hostname}:${vtadmin_api_port}" \ + --http-origin "http://${case_insensitive_hostname}:${vtadmin_web_port}" \ --http-tablet-url-tmpl "http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \ --tracer "opentracing-jaeger" \ --grpc-tracing \ @@ -29,15 +57,20 @@ echo ${vtadmin_api_pid} > "${log_dir}/vtadmin-api.pid" echo "\ vtadmin-api is running! - - API: http://${hostname}:${vtadmin_api_port} + - API: http://${case_insensitive_hostname}:${vtadmin_api_port} - Logs: ${log_dir}/vtadmin-api.out - PID: ${vtadmin_api_pid} " # Wait for vtadmin to successfully discover the cluster expected_cluster_result="{\"result\":{\"clusters\":[{\"id\":\"${cluster_name}\",\"name\":\"${cluster_name}\"}]},\"ok\":true}" +<<<<<<< HEAD for _ in {0..300}; do result=$(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters") +======= +for _ in {0..100}; do + result=$(curl -s "http://${case_insensitive_hostname}:${vtadmin_api_port}/api/clusters") +>>>>>>> 7603abc534 (Update VTAdmin build script (#15839)) if [[ ${result} == "${expected_cluster_result}" ]]; then break fi @@ -45,7 +78,7 @@ for _ in {0..300}; do done # Check one last time -[[ $(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters") == "${expected_cluster_result}" ]] || fail "vtadmin failed to discover the running example Vitess cluster." +[[ $(curl -s "http://${case_insensitive_hostname}:${vtadmin_api_port}/api/clusters") == "${expected_cluster_result}" ]] || fail "vtadmin failed to discover the running example Vitess cluster." # Download nvm and node if [[ -z ${NVM_DIR} ]]; then @@ -86,7 +119,7 @@ echo ${vtadmin_web_pid} > "${log_dir}/vtadmin-web.pid" echo "\ vtadmin-web is running! - - Browser: http://${hostname}:${vtadmin_web_port} + - Browser: http://${case_insensitive_hostname}:${vtadmin_web_port} - Logs: ${log_dir}/vtadmin-web.out - PID: ${vtadmin_web_pid} " diff --git a/web/vtadmin/build.sh b/web/vtadmin/build.sh new file mode 100755 index 00000000000..b8481ccdc0e --- /dev/null +++ b/web/vtadmin/build.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Copyright 2023 The Vitess Authors. +# +# 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. + +function output() { + echo -e "$@" +} + +script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")" +pushd ${VTROOT} +source "./build.env" +popd +web_dir="${script_dir}" + +vtadmin_api_port=14200 + +if [ -z "${hostname}" ] +then + hostname=$(hostname -f) + output "\n\033[1;32mhostname was empty, set it to \"${hostname}\"\033[0m" +fi + +case_insensitive_hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]') + +# Download nvm and node +if [[ -z ${NVM_DIR} ]]; then + export NVM_DIR="$HOME/.nvm" +fi + +if [[ -z ${NODE_VERSION} ]]; then + export NODE_VERSION="20.12.2" +fi + +output "\nInstalling nvm...\n" + +if [ -d "$NVM_DIR" ]; then + output "\033[1;32mnvm is already installed!\033[0m" +else + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash && output "\033[1;32mnvm is installed!\033[0m" || fail "\033[1;32mnvm failed to install!\033[0m" +fi + +source "$NVM_DIR/nvm.sh" + +output "\nConfiguring Node.js $NODE_VERSION\n" +nvm install "$NODE_VERSION" || fail "Could not install and use nvm $NODE_VERSION." + +npm --prefix "$web_dir" --silent install + +export PATH=$PATH:$web_dir/node_modules/.bin/ + +vite_vtadmin_api_address="http://${case_insensitive_hostname}:${vtadmin_api_port}" +output "\n\033[1;32mSetting VITE_VTADMIN_API_ADDRESS to \"${vite_vtadmin_api_address}\"\033[0m" + +VITE_VTADMIN_API_ADDRESS="http://${case_insensitive_hostname}:${vtadmin_api_port}" \ + VITE_ENABLE_EXPERIMENTAL_TABLET_DEBUG_VARS="true" \ + npm run --prefix "$web_dir" build