From 407564086de6d6fbd37a8f17f9f8667dbdf29630 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 24 May 2019 16:09:00 -0700 Subject: [PATCH] provision: Move apt-get update from retry handler to setup-apt-repo. This avoids unnecessarily alarming error messages if the apt cache is missing. Signed-off-by: Anders Kaseorg --- scripts/lib/setup-apt-repo | 6 +++++- tools/lib/provision.py | 28 ++++++++++------------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/scripts/lib/setup-apt-repo b/scripts/lib/setup-apt-repo index dd8967e61b..acb425020f 100755 --- a/scripts/lib/setup-apt-repo +++ b/scripts/lib/setup-apt-repo @@ -27,7 +27,11 @@ touch "$SOURCES_FILE" # Hash it to check if the sources file is changed by the script later. zulip_source_hash=$(sha1sum "$SOURCES_FILE") -apt-get install -y lsb-release apt-transport-https gnupg +pre_setup_deps=(lsb-release apt-transport-https gnupg) +if ! apt-get -s install "${pre_setup_deps[@]}" > /dev/null 2>&1; then + apt-get update +fi +apt-get -y install "${pre_setup_deps[@]}" SCRIPTS_PATH="$(dirname "$(dirname "$0")")" diff --git a/tools/lib/provision.py b/tools/lib/provision.py index 41030c0926..237ef0f954 100755 --- a/tools/lib/provision.py +++ b/tools/lib/provision.py @@ -277,16 +277,16 @@ def setup_shell_profile(shell_profile): write_command(source_activate_command) write_command('cd /srv/zulip') -def install_system_deps(retry=False): - # type: (bool) -> None +def install_system_deps(): + # type: () -> None # By doing list -> set -> list conversion, we remove duplicates. deps_to_install = list(set(SYSTEM_DEPENDENCIES)) if family == 'redhat': - install_yum_deps(deps_to_install, retry=retry) + install_yum_deps(deps_to_install) elif vendor in ["Debian", "Ubuntu"]: - install_apt_deps(deps_to_install, retry=retry) + install_apt_deps(deps_to_install) else: raise AssertionError("Invalid vendor") @@ -297,17 +297,8 @@ def install_system_deps(retry=False): if BUILD_TSEARCH_FROM_SOURCE: run_as_root(["./scripts/lib/build-tsearch-extras"]) -def install_apt_deps(deps_to_install, retry=False): - # type: (List[str], bool) -> None - if retry: - print(WARNING + "`apt-get -y install` failed while installing dependencies; retrying..." + ENDC) - # Since a common failure mode is for the caching in - # `setup-apt-repo` to optimize the fast code path to skip - # running `apt-get update` when the target apt repository - # is out of date, we run it explicitly here so that we - # recover automatically. - run_as_root(['apt-get', 'update']) - +def install_apt_deps(deps_to_install): + # type: (List[str]) -> None # setup-apt-repo does an `apt-get update` run_as_root(["./scripts/lib/setup-apt-repo"]) run_as_root( @@ -318,8 +309,8 @@ def install_apt_deps(deps_to_install, retry=False): + deps_to_install ) -def install_yum_deps(deps_to_install, retry=False): - # type: (List[str], bool) -> None +def install_yum_deps(deps_to_install): + # type: (List[str]) -> None print(WARNING + "RedHat support is still experimental.") run_as_root(["./scripts/lib/setup-yum-repo"]) @@ -412,7 +403,8 @@ def main(options): install_system_deps() except subprocess.CalledProcessError: # Might be a failure due to network connection issues. Retrying... - install_system_deps(retry=True) + print(WARNING + "Installing system dependencies failed; retrying..." + ENDC) + install_system_deps() with open(apt_hash_file_path, 'w') as hash_file: hash_file.write(new_apt_dependencies_hash) else: