From 6950d8d76965371df70a735b499d17377e6db42b Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Mon, 18 May 2020 20:49:15 +0530 Subject: [PATCH] provision: Don't run migrations on `zulip` db in CircleCI. The automated tests running in CircleCI don't actually use the `zulip` db, so we can skip running migrations on it in some CircleCI shards to save time. NOTE: This only effects build jobs that run provision, except the `production-build` job where we skip building the dbs altogether. Migrations still run on `focal-backend` build job to ensure we are testing all our development setup code. --- .circleci/config.yml | 5 ++++- tools/ci/setup-backend | 2 +- tools/lib/provision.py | 6 ++++++ tools/lib/provision_inner.py | 18 ++++++++++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f86cac7ae6..816753e835 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,7 +45,7 @@ aliases: rm -f /home/circleci/.gitconfig # This is the main setup job for the test suite - mispipe "tools/ci/setup-backend 2>&1" ts + mispipe "tools/ci/setup-backend --skip-dev-db-build" ts # Cleaning caches is mostly unnecessary in Circle, because # most builds don't get to write to the cache. @@ -236,6 +236,9 @@ jobs: - *save_cache_requirements - *save_emoji_cache - *run_backend_tests + - run: + name: Check development database build + command: mispipe "tools/ci/setup-backend" ts - *notify_failure_status "xenial-legacy": diff --git a/tools/ci/setup-backend b/tools/ci/setup-backend index f83d63d65a..d99ea61f87 100755 --- a/tools/ci/setup-backend +++ b/tools/ci/setup-backend @@ -6,7 +6,7 @@ set -x # Provisioning may fail due to many issues but most of the times a network # connection issue is the reason. So we are going to retry entire provisioning # once again if that fixes our problem. -tools/provision || { +tools/provision "$@" 2>&1 || { ret=$? if [ "$ret" = 1 ]; then echo "\`provision\`: Something went wrong with the provisioning, might be a network issue, Retrying to provision..." diff --git a/tools/lib/provision.py b/tools/lib/provision.py index 3f11bce04a..e7e1f6ae56 100755 --- a/tools/lib/provision.py +++ b/tools/lib/provision.py @@ -425,6 +425,7 @@ def main(options: argparse.Namespace) -> "NoReturn": provision_inner, *(["--force"] if options.is_force else []), *(["--build-release-tarball-only"] if options.is_build_release_tarball_only else []), + *(["--skip-dev-db-build"] if options.skip_dev_db_build else []), ], ) @@ -440,5 +441,10 @@ if __name__ == "__main__": default=False, help="Provision needed to build release tarball.") + parser.add_argument('--skip-dev-db-build', action='store_true', + dest='skip_dev_db_build', + default=False, + help="Don't run migrations on dev database.") + options = parser.parse_args() main(options) diff --git a/tools/lib/provision_inner.py b/tools/lib/provision_inner.py index 6582e2d2d8..94f5c16d12 100755 --- a/tools/lib/provision_inner.py +++ b/tools/lib/provision_inner.py @@ -253,8 +253,17 @@ def main(options: argparse.Namespace) -> int: dev_template_db_status = DEV_DATABASE.template_status() if options.is_force or dev_template_db_status == 'needs_rebuild': run(["tools/setup/postgres-init-dev-db"]) - run(["tools/rebuild-dev-database"]) - DEV_DATABASE.write_new_db_digest() + if options.skip_dev_db_build: + # We don't need to build the manual development + # database on CircleCI for running tests, so we can + # just leave it as a template db and save a minute. + # + # Important: We don't write a digest as that would + # incorrectly claim that we ran migrations. + pass + else: + run(["tools/rebuild-dev-database"]) + DEV_DATABASE.write_new_db_digest() elif dev_template_db_status == 'run_migrations': DEV_DATABASE.run_db_migrations() elif dev_template_db_status == 'current': @@ -327,5 +336,10 @@ if __name__ == "__main__": default=False, help="Provision for test suite with production settings.") + parser.add_argument('--skip-dev-db-build', action='store_true', + dest='skip_dev_db_build', + default=False, + help="Don't run migrations on dev database.") + options = parser.parse_args() sys.exit(main(options))