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

Update VTAdmin build script #15839

Merged
merged 3 commits into from
May 6, 2024
Merged
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
20 changes: 13 additions & 7 deletions examples/common/scripts/vtadmin-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# 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}")"
source "${script_dir}/../env.sh"

Expand All @@ -24,11 +28,13 @@ web_dir="${script_dir}/../../../web/vtadmin"
vtadmin_api_port=14200
vtadmin_web_port=14201

echo "vtadmin-api http-origin set to \"http://${hostname}:${vtadmin_web_port}\""
case_insensitive_hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh that was the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! 😄 CORS is case sensitive and I think mac OS comes with a default hostname that is capitalized!


output "\n\033[1;32mvtadmin-api expects vtadmin-web at, and set http-origin to \"http://${case_insensitive_hostname}:${vtadmin_web_port}\"\033[0m"

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 @@ -45,7 +51,7 @@ 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}
"
Expand All @@ -56,15 +62,15 @@ source "${web_dir}/build.sh"
# Wait for vtadmin to successfully discover the cluster
expected_cluster_result="{\"result\":{\"clusters\":[{\"id\":\"${cluster_name}\",\"name\":\"${cluster_name}\"}]},\"ok\":true}"
for _ in {0..100}; do
result=$(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters")
result=$(curl -s "http://${case_insensitive_hostname}:${vtadmin_api_port}/api/clusters")
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."

[[ ! -d "$web_dir/build" ]] && fail "Please make sure the VTAdmin files are built in $web_dir/build, using 'make build'"

Expand All @@ -76,7 +82,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}
"
10 changes: 7 additions & 3 deletions web/vtadmin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ function output() {
}

script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")"
source "${script_dir}/../../build.env"
pushd ${VTROOT}
source "./build.env"
popd
web_dir="${script_dir}"

vtadmin_api_port=14200
Expand All @@ -30,6 +32,8 @@ then
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"
Expand All @@ -56,9 +60,9 @@ npm --prefix "$web_dir" --silent install

export PATH=$PATH:$web_dir/node_modules/.bin/

vite_vtadmin_api_address="http://${hostname}:${vtadmin_api_port}"
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://${hostname}:${vtadmin_api_port}" \
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