Exemplo n.º 1
0
def install(language):
    # We do not have to install if it is already complete.
    if utils.is_install_complete(language):
        typer.echo("Installation is already complete.")
        return

    typer.echo("Installation might take some time depending on your network"
               " bandwidth. Starting installation...")
    utils.install_images(language)
    utils.install_network()
    typer.echo("Installation was successful.")
Exemplo n.º 2
0
def update(language):
    typer.echo("[Update]: ...")

    # only start if it was running
    should_restart = utils.is_orchest_running()

    if should_restart:
        logging.info("[Shutdown]: ...")

    if config.UPDATE_MODE != "web":
        stop(trace="update")
    else:
        # Both nginx-proxy/update-server are left running
        # during the update to support _updateserver
        stop(skip_names=["nginx-proxy", "update-server"])

    utils.clear_environment_images()

    # Update git repository to get the latest changes to the ``userdir``
    # structure.
    logging.info("Updating repo ...")
    script_path = os.path.join(
        "/orchest", "services", "orchest-ctl", "app", "scripts", "git-update.sh"
    )
    script_process = subprocess.Popen([script_path], cwd="/orchest-host", bufsize=0)
    return_code = script_process.wait()

    if return_code != 0:
        logging.error(
            "'git' repo update failed. Please make sure you don't have "
            "any commits that conflict with the main branch in the "
            "'orchest' repository. Cancelling update."
        )
    else:
        logging.info("Pulling latest images ...")
        utils.install_images(language, force_pull=True)

    typer.echo("[Update]: success")

    if config.UPDATE_MODE != "web" and should_restart:
        start()
Exemplo n.º 3
0
def start():
    # Make sure the installation is complete before starting Orchest.
    if not utils.is_install_complete():
        typer.echo("Installation required. Pulling images in parallel.")
        utils.install_images()
        utils.install_network()
        typer.echo("Installation finished. Attempting to start...")
        return start()

    # Dynamically mount certs directory based on whether it exists in
    # nginx-proxy directory on host
    if proxy_certs_exist_on_host():
        CONTAINER_MAPPING["orchest/nginx-proxy:latest"]["mounts"].append({
            "source":
            os.path.join(config.ENVS["HOST_REPO_DIR"], "services",
                         "nginx-proxy", "certs"),
            "target":
            "/etc/ssl/certs",
        })
    else:
        # in case no certs are found don't expose 443 on host
        del CONTAINER_MAPPING["orchest/nginx-proxy:latest"]["ports"]["443/tcp"]

    if config.RUN_MODE == "dev":
        logging.info(
            "Starting Orchest in DEV mode. This mounts host directories "
            "to monitor for source code changes.")

        utils.dev_mount_inject(CONTAINER_MAPPING)
    else:
        typer.echo("[Start]: ...")

    # Clean up lingering, old images from previous starts.
    utils.clean_containers()

    # TODO: is the repo tag always the first tag in the Docker
    #       Engine API?
    # Determine the containers that are already running as we do not
    # want to run these again.
    running_containers = docker_client.containers.list()
    running_container_images = [
        running_container.image.tags[0]
        for running_container in running_containers
        if len(running_container.image.tags) > 0
    ]

    images_to_start = [
        image_name for image_name in config.ON_START_IMAGES
        if image_name not in running_container_images
    ]

    # Run every container that is not already running. Additionally,
    # use pre-defined container specifications if the container has
    # any.
    for container_image in images_to_start:
        container_spec = CONTAINER_MAPPING.get(container_image, {})
        run_config = utils.convert_to_run_config(container_image,
                                                 container_spec)

        logging.info("Starting image %s" % container_image)
        docker_client.containers.run(**run_config)

    utils.log_server_url()