From ca4c695d796daf416e40c2fcfa66c4cd894d01f1 Mon Sep 17 00:00:00 2001 From: Florent Poinsard <35779988+frouioui@users.noreply.github.com> Date: Fri, 30 Jun 2023 10:46:34 +0200 Subject: [PATCH] Improve time taken to run the examples by optimizing `vtadmin` build (#13262) --- .github/workflows/create_release.yml | 5 +++ Makefile | 4 ++ examples/common/scripts/vtadmin-up.sh | 45 ++++++++--------------- web/vtadmin/build.sh | 53 +++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 30 deletions(-) create mode 100755 web/vtadmin/build.sh diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 7c2c75b2afe..4765b6b8f84 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -22,6 +22,11 @@ jobs: with: go-version: 1.20.5 + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: '18.16.0' + - name: Tune the OS run: | sudo sysctl -w net.ipv4.ip_local_port_range="22768 65535" diff --git a/Makefile b/Makefile index c78f12d2b56..bc1f0007dfc 100644 --- a/Makefile +++ b/Makefile @@ -91,6 +91,10 @@ endif -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) \ -ldflags "$(shell tools/build_version_flags.sh)" \ -o ${VTROOTBIN} ./go/... +ifndef NOVTADMINBUILD + echo "Building VTAdmin Web, disable VTAdmin build by setting 'NOVTADMINBUILD'" + ./web/vtadmin/build.sh +endif # cross-build can be used to cross-compile Vitess client binaries # Outside of select client binaries (namely vtctlclient & vtexplain), cross-compiled Vitess Binaries are not recommended for production deployments diff --git a/examples/common/scripts/vtadmin-up.sh b/examples/common/scripts/vtadmin-up.sh index fd4cd6e7f0c..faa2e6a177f 100755 --- a/examples/common/scripts/vtadmin-up.sh +++ b/examples/common/scripts/vtadmin-up.sh @@ -1,5 +1,19 @@ #!/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. + script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")" source "${script_dir}/../env.sh" @@ -47,36 +61,7 @@ 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." -# Download nvm and node -if [[ -z ${NVM_DIR} ]]; then - export NVM_DIR="$HOME/.nvm" -fi - -if [[ -z ${NODE_VERSION} ]]; then - export NODE_VERSION="18.16.0" -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.0/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." - -# As a TODO, it'd be nice to make the assumption that vtadmin-web is already -# installed and built (since we assume that `make` has already been run for -# other Vitess components.) -npm --prefix "$web_dir" --silent install - -VITE_VTADMIN_API_ADDRESS="http://${hostname}:${vtadmin_api_port}" \ - VITE_ENABLE_EXPERIMENTAL_TABLET_DEBUG_VARS="true" \ - npm run --prefix "$web_dir" build +[[ ! -d "$web_dir/build" ]] && fail "Please make sure the VTAdmin files are built in $web_dir/build, using 'make build'" "${web_dir}/node_modules/.bin/serve" --no-clipboard -l $vtadmin_web_port -s "${web_dir}/build" \ > "${log_dir}/vtadmin-web.out" 2>&1 & diff --git a/web/vtadmin/build.sh b/web/vtadmin/build.sh new file mode 100755 index 00000000000..1b540d5b422 --- /dev/null +++ b/web/vtadmin/build.sh @@ -0,0 +1,53 @@ +#!/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}")" +source "${script_dir}/../../build.env" +web_dir="${script_dir}" + +vtadmin_api_port=14200 + +# Download nvm and node +if [[ -z ${NVM_DIR} ]]; then + export NVM_DIR="$HOME/.nvm" +fi + +if [[ -z ${NODE_VERSION} ]]; then + export NODE_VERSION="18.16.0" +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.0/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 + +VITE_VTADMIN_API_ADDRESS="http://${hostname}:${vtadmin_api_port}" \ + VITE_ENABLE_EXPERIMENTAL_TABLET_DEBUG_VARS="true" \ + npm run --prefix "$web_dir" build