Exemplo n.º 1
0
def deploy_to_project(
    dst_project,
    no_confirm,
    secrets_local_dir,
    sets,
    all_services,
    secrets_src_project,
    env_values,
    env_files,
    template_dir,
    ignore_requires,
    scale_resources,
    root_custom_dir,
    pick,
    label,
    skip,
    watch,
    concurrent,
    threadpool_size,
):
    root_custom_dir = get_dir(root_custom_dir,
                              "custom",
                              "custom scripts",
                              optional=True)

    if not dst_project:
        log.error("Error: no destination project given")
        sys.exit(1)

    verify_label(label)

    if secrets_local_dir:
        SecretImporter.local_dir = get_dir(secrets_local_dir,
                                           "secrets",
                                           "secrets",
                                           optional=True)
    if secrets_src_project:
        SecretImporter.source_project = secrets_src_project

    template_dir, env_config_handler, specific_components, sets_selected, confirm_msg = _parse_args(
        template_dir, env_values, env_files, all_services, sets, pick,
        dst_project)

    if not no_confirm and not prompter.yesno(confirm_msg):
        log.info("Aborted by user")
        sys.exit(0)

    switch_to_project(dst_project)

    if watch:
        event_watcher = start_event_watcher(dst_project)

    DeployRunner(
        template_dir,
        dst_project,
        env_config_handler,
        ignore_requires=ignore_requires,
        service_sets_selected=sets_selected,
        resources_scale_factor=scale_resources,
        root_custom_dir=root_custom_dir,
        specific_components=specific_components,
        label=label,
        skip=skip.split(",") if skip else None,
        dry_run=False,
        concurrent=concurrent,
        threadpool_size=threadpool_size,
    ).run()

    if watch and event_watcher:
        event_watcher.stop()

    list_routes(dst_project)
Exemplo n.º 2
0
def list_act_sets(template_dir, output):
    template_dir = get_dir(template_dir, "templates", "template")
    return list_sets(template_dir, output)
Exemplo n.º 3
0
def _parse_args(template_dir, env_values, env_files, all_services, sets, pick,
                dst_project):
    """Parses args common to 'process' and 'deploy'."""
    template_dir = get_dir(template_dir, "templates", "template")

    # Analyze the values provided by --env to determine which config handler we are using
    if env_values and env_files:
        log.error("You cannot use both --env and --env-file")
        sys.exit(1)
    elif env_values:
        all_env_values_are_files = all(
            [os.path.exists(value) for value in env_values])
        some_env_values_are_files = any(
            [os.path.exists(value) for value in env_values])
        if all_env_values_are_files:
            log.info(
                "A specific filename was provided for env, using legacy env file processing"
            )
            env_config_handler = LegacyEnvConfigHandler(env_files=env_values)
        elif some_env_values_are_files:
            log.error(
                "Error: Values for '--env' must be either all filenames, or all env names"
            )
            sys.exit(1)
        else:
            env_config_handler = EnvConfigHandler(env_names=env_values)
    elif env_files:
        log.info(
            "A specific filename was provided for env, using legacy env file processing"
        )
        env_config_handler = LegacyEnvConfigHandler(env_files=env_files)
    else:
        env_config_handler = EnvConfigHandler(env_names=[])

    log.info("Using environments: %s", ", ".join(env_values or env_files))

    if not all_services and not sets and not pick:
        log.error("Error: no service sets or components selected for deploy."
                  " Use --sets, --all, or --pick")
        sys.exit(1)

    server = get_server_info()

    sets_selected = []
    specific_components = []

    if all_services:
        sets_selected = all_sets(template_dir)
    else:
        if pick:
            try:
                [p.split("/")[1] for p in pick.split(",")]
            except (ValueError, IndexError):
                log.error(
                    "Invalid format for '--pick', use: 'service_set/component'"
                )
                sys.exit(1)
            specific_components = list(set(pick.split(",")))
        if sets:
            sets_selected = list(set(sets.split(",")))

    joined_sets = ", ".join(sets_selected)
    joined_comps = ", ".join(specific_components)
    sets_string = f" service sets: [{joined_sets}]" if joined_sets else ""
    comps_string = f" components: [{joined_comps}]" if joined_comps else ""
    confirm_msg = (
        f"Deploying{sets_string}{comps_string} "
        f"to project '{dst_project}' on server {server} -- continue?")

    return template_dir, env_config_handler, specific_components, sets_selected, confirm_msg