Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-17.0] Update VTAdmin build script (#15839) #15848

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions examples/common/scripts/vtadmin-up.sh
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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 \
Expand All @@ -29,23 +57,28 @@ 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
sleep 0.1
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
Expand Down Expand Up @@ -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}
"
68 changes: 68 additions & 0 deletions web/vtadmin/build.sh
Original file line number Diff line number Diff line change
@@ -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
Loading