provision: Use a more efficient approach for getting yarn version.

Since yarn has a package.json conveniently available, we can parse
that with jq, saving the expensive operation of starting up yarn.

This saves ~300ms in a no-op provision.
This commit is contained in:
Tim Abbott
2018-12-07 14:28:04 -08:00
parent a1ca8c262a
commit 630968b632
3 changed files with 14 additions and 3 deletions

View File

@@ -163,7 +163,7 @@ fi
apt-get -y dist-upgrade "${APT_OPTIONS[@]}" apt-get -y dist-upgrade "${APT_OPTIONS[@]}"
if ! apt-get install -y \ if ! apt-get install -y \
puppet git curl wget \ puppet git curl wget jq \
python python3 python-six python3-six crudini \ python python3 python-six python3-six crudini \
"${ADDITIONAL_PACKAGES[@]}"; then "${ADDITIONAL_PACKAGES[@]}"; then
set +x set +x

View File

@@ -6,7 +6,7 @@ ZULIP_SRV="/srv"
if [ "$TRAVIS" ] ; then if [ "$TRAVIS" ] ; then
ZULIP_SRV="/home/travis" ZULIP_SRV="/home/travis"
fi fi
YARN_BIN="$ZULIP_SRV/zulip-yarn/bin/yarn" YARN_PACKAGE_JSON="$ZULIP_SRV/zulip-yarn/package.json"
node_version=8.11.1 node_version=8.11.1
yarn_version=1.7.0 yarn_version=1.7.0
@@ -20,7 +20,12 @@ if node_wrapper_path="$(command -v node)"; then
current_node_version="$(node --version)" current_node_version="$(node --version)"
fi fi
if [ "$($YARN_BIN --version 2>/dev/null)" = "$yarn_version" ] && [ "$current_node_version" = "v$node_version" ] && [ -L "$node_wrapper_path" ]; then current_yarn_version="none"
if [ -e "$YARN_PACKAGE_JSON" ]; then
current_yarn_version=$(jq -r '.version' "$YARN_PACKAGE_JSON")
fi
if [ "$current_yarn_version" = "$yarn_version" ] && [ "$current_node_version" = "v$node_version" ] && [ -L "$node_wrapper_path" ]; then
echo "Node version $node_version and yarn version $yarn_version are already installed." echo "Node version $node_version and yarn version $yarn_version are already installed."
exit 0 exit 0
fi fi

View File

@@ -37,6 +37,12 @@ VENV_DEPENDENCIES = [
"libxslt1-dev", # Used for installing talon "libxslt1-dev", # Used for installing talon
"libpq-dev", # Needed by psycopg2 "libpq-dev", # Needed by psycopg2
"libssl-dev", # Needed to build pycurl and other libraries "libssl-dev", # Needed to build pycurl and other libraries
# This is technically a node dependency, but we add it here
# because we don't have another place that we install apt packages
# on upgrade of a production server, and it's not worth adding
# another call to `apt install` for.
"jq", # Used by scripts/lib/install-node to check yarn version
] ]
codename = parse_lsb_release()["DISTRIB_CODENAME"] codename = parse_lsb_release()["DISTRIB_CODENAME"]