Exemplo n.º 1
0
def deploy_postgres(settings):
    print_separator("postgres")

    docker_build("postgres", settings)

    restore_seqr_db_from_backup = settings.get("RESTORE_SEQR_DB_FROM_BACKUP")
    reset_db = settings.get("RESET_DB")

    if reset_db or restore_seqr_db_from_backup:
        # Since pgdata is stored on a persistent volume, redeploying does not get rid of it. If any existing pgdata is
        # present, even if the databases are empty, postgres will not fully re-initialize the database. This is
        # good if you want to keep the data across a deployment, but problematic if you actually need to rest and
        # reinitialize the db. Therefore, when the database needs to be fully reinitialized, delete pgdata
        run_in_pod(get_pod_name("postgres",
                                deployment_target=settings["DEPLOY_TO"]),
                   "rm -rf /var/lib/postgresql/data/pgdata",
                   verbose=True)

    deploy_pod("postgres", settings, wait_until_pod_is_ready=True)

    if restore_seqr_db_from_backup:
        postgres_pod_name = get_pod_name(
            "postgres", deployment_target=settings["DEPLOY_TO"])
        _restore_seqr_db_from_backup(
            postgres_pod_name, restore_seqr_db_from_backup,
            settings.get("RESTORE_REFERENCE_DB_FROM_BACKUP"))
Exemplo n.º 2
0
def open_shell_in_component(component,
                            deployment_target,
                            shell_path='/bin/bash'):
    """Open a command line shell in the given component"""

    run_in_pod(component,
               shell_path,
               deployment_target=deployment_target,
               is_interactive=True)
Exemplo n.º 3
0
def _drop_seqr_db(postgres_pod_name):
    run_in_pod(postgres_pod_name, "psql -U postgres postgres -c 'drop database seqrdb'",
               errors_to_ignore=["does not exist"],
               verbose=True,
               )
    run_in_pod(postgres_pod_name, "psql -U postgres postgres -c 'drop database reference_data_db'",
               errors_to_ignore=["does not exist"],
               verbose=True,
               )
Exemplo n.º 4
0
def reset_database(database=[], deployment_target=None):
    """Runs kubectl commands to delete and reset the given database(s).

    Args:
        component (list): one more database labels - "seqrdb"
        deployment_target (string): value from DEPLOYMENT_TARGETS - eg. "gcloud-dev"
    """
    if "seqrdb" in database:
        postgres_pod_name = get_pod_name("postgres", deployment_target=deployment_target)
        if not postgres_pod_name:
            logger.error("postgres pod must be running")
        else:
            run_in_pod(postgres_pod_name, "psql -U postgres postgres -c 'drop database seqrdb'" % locals(), errors_to_ignore=["does not exist"])
            run_in_pod(postgres_pod_name, "psql -U postgres postgres -c 'create database seqrdb'" % locals())
Exemplo n.º 5
0
def deploy_seqr(settings):
    print_separator("seqr")

    if settings["BUILD_DOCKER_IMAGES"]:
        seqr_git_hash = run("git log -1 --pretty=%h",
                            errors_to_ignore=["Not a git repository"])
        seqr_git_hash = (
            ":" + seqr_git_hash.strip()) if seqr_git_hash is not None else ""

        docker_build("seqr", settings, [
            "--build-arg SEQR_SERVICE_PORT=%s" % settings["SEQR_SERVICE_PORT"],
            "--build-arg SEQR_UI_DEV_PORT=%s" % settings["SEQR_UI_DEV_PORT"],
            "-f deploy/docker/seqr/Dockerfile",
            "-t %(DOCKER_IMAGE_NAME)s" + seqr_git_hash,
        ])

    if settings["ONLY_PUSH_TO_REGISTRY"]:
        return

    restore_seqr_db_from_backup = settings.get("RESTORE_SEQR_DB_FROM_BACKUP")
    reset_db = settings.get("RESET_DB")

    deployment_target = settings["DEPLOY_TO"]
    postgres_pod_name = get_pod_name("postgres",
                                     deployment_target=deployment_target)

    if settings["DELETE_BEFORE_DEPLOY"]:
        delete_pod("seqr", settings)
    elif reset_db or restore_seqr_db_from_backup:
        seqr_pod_name = get_pod_name('seqr',
                                     deployment_target=deployment_target)
        if seqr_pod_name:
            sleep_until_pod_is_running("seqr",
                                       deployment_target=deployment_target)

            run_in_pod(seqr_pod_name,
                       "/usr/local/bin/stop_server.sh",
                       verbose=True)

    if reset_db:
        _drop_seqr_db(postgres_pod_name)
    if restore_seqr_db_from_backup:
        _drop_seqr_db(postgres_pod_name)
        _restore_seqr_db_from_backup(postgres_pod_name,
                                     restore_seqr_db_from_backup)
    else:
        run_in_pod(
            postgres_pod_name,
            "psql -U postgres postgres -c 'create database seqrdb'",
            errors_to_ignore=["already exists"],
            verbose=True,
        )
        run_in_pod(
            postgres_pod_name,
            "psql -U postgres postgres -c 'create database reference_data_db'",
            errors_to_ignore=["already exists"],
            verbose=True,
        )

    deploy_pod("seqr", settings, wait_until_pod_is_ready=True)
Exemplo n.º 6
0
def redeploy_seqr(deployment_target):
    print_separator('re-deploying seqr')

    seqr_pod_name = get_pod_name('seqr', deployment_target=deployment_target)
    if not seqr_pod_name:
        raise ValueError('No seqr pod found, unable to re-deploy')
    sleep_until_pod_is_running('seqr', deployment_target=deployment_target)

    run_in_pod(seqr_pod_name, 'git pull', verbose=True)
    run_in_pod(seqr_pod_name, './manage.py migrate', verbose=True)
    run_in_pod(seqr_pod_name, '/usr/local/bin/restart_server.sh')
Exemplo n.º 7
0
def _restore_seqr_db_from_backup(postgres_pod_name, seqrdb_backup, reference_data_backup=None):
    run_in_pod(postgres_pod_name, "psql -U postgres postgres -c 'create database seqrdb'", verbose=True)
    run_in_pod(postgres_pod_name, "psql -U postgres postgres -c 'create database reference_data_db'", verbose=True)
    run("kubectl cp '{backup}' {postgres_pod_name}:/root/$(basename {backup})".format(
        postgres_pod_name=postgres_pod_name, backup=seqrdb_backup), verbose=True)
    run_in_pod(
        postgres_pod_name, "/root/restore_database_backup.sh postgres seqrdb /root/$(basename {backup})".format(
            backup=seqrdb_backup), verbose=True)
    run_in_pod(postgres_pod_name, "rm /root/$(basename {backup})".format(backup=seqrdb_backup, verbose=True))

    if reference_data_backup:
        run("kubectl cp '{backup}' {postgres_pod_name}:/root/$(basename {backup})".format(
            postgres_pod_name=postgres_pod_name, backup=reference_data_backup), verbose=True)
        run_in_pod(
            postgres_pod_name, "/root/restore_database_backup.sh postgres reference_data_db /root/$(basename {backup})".format(
                backup=reference_data_backup), verbose=True)
        run_in_pod(postgres_pod_name, "rm /root/$(basename {backup})".format(backup=reference_data_backup, verbose=True))