provision: Skip some rm, mkdir, chown commands if possible.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2019-08-13 04:54:51 +00:00
committed by Tim Abbott
parent 2a1305de9f
commit 88793e80ea
2 changed files with 7 additions and 9 deletions

View File

@@ -391,15 +391,13 @@ def main(options):
] ]
run_as_root(proxy_env + ["scripts/lib/install-node"], sudo_args = ['-H']) run_as_root(proxy_env + ["scripts/lib/install-node"], sudo_args = ['-H'])
if not os.access(NODE_MODULES_CACHE_PATH, os.W_OK):
run_as_root(["mkdir", "-p", NODE_MODULES_CACHE_PATH])
run_as_root(["chown", "%s:%s" % (user_id, user_id), NODE_MODULES_CACHE_PATH])
# This is a wrapper around `yarn`, which we run last since # This is a wrapper around `yarn`, which we run last since
# it can often fail due to network issues beyond our control. # it can often fail due to network issues beyond our control.
try: try:
# Hack: We remove `node_modules` as root to work around an
# issue with the symlinks being improperly owned by root.
if os.path.islink("node_modules"):
run_as_root(["rm", "-f", "node_modules"])
run_as_root(["mkdir", "-p", NODE_MODULES_CACHE_PATH])
run_as_root(["chown", "%s:%s" % (user_id, user_id), NODE_MODULES_CACHE_PATH])
setup_node_modules(prefer_offline=True) setup_node_modules(prefer_offline=True)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
print(WARNING + "`yarn install` failed; retrying..." + ENDC) print(WARNING + "`yarn install` failed; retrying..." + ENDC)

View File

@@ -80,9 +80,9 @@ def main(options: argparse.Namespace) -> int:
# The `build_emoji` script requires `emoji-datasource` package # The `build_emoji` script requires `emoji-datasource` package
# which we install via npm; thus this step is after installing npm # which we install via npm; thus this step is after installing npm
# packages. # packages.
if not os.path.isdir(EMOJI_CACHE_PATH): if not os.access(EMOJI_CACHE_PATH, os.W_OK):
run_as_root(["mkdir", EMOJI_CACHE_PATH]) run_as_root(["mkdir", "-p", EMOJI_CACHE_PATH])
run_as_root(["chown", "%s:%s" % (user_id, user_id), EMOJI_CACHE_PATH]) run_as_root(["chown", "%s:%s" % (user_id, user_id), EMOJI_CACHE_PATH])
run(["tools/setup/emoji/build_emoji"]) run(["tools/setup/emoji/build_emoji"])
# copy over static files from the zulip_bots package # copy over static files from the zulip_bots package