Пример #1
0
def fix_ownership(verbose: bool, dry_run: bool):
    shell_params = ShellParams(
        verbose=verbose,
        mount_sources=MOUNT_ALL,
        python=DEFAULT_PYTHON_MAJOR_MINOR_VERSION,
    )
    extra_docker_flags = get_extra_docker_flags(MOUNT_ALL)
    env = construct_env_variables_docker_compose_command(shell_params)
    cmd = [
        "docker",
        "run",
        "-t",
        *extra_docker_flags,
        "-e",
        "GITHUB_ACTIONS=",
        "-e",
        "SKIP_ENVIRONMENT_INITIALIZATION=true",
        "--pull",
        "never",
        shell_params.airflow_image_name_with_tag,
        "/opt/airflow/scripts/in_container/run_fix_ownership.sh",
    ]
    run_command(cmd,
                verbose=verbose,
                dry_run=dry_run,
                text=True,
                env=env,
                check=False)
    # Always succeed
    sys.exit(0)
Пример #2
0
def stop(verbose: bool, dry_run: bool, preserve_volumes: bool):
    command_to_execute = ['docker-compose', 'down', "--remove-orphans"]
    if not preserve_volumes:
        command_to_execute.append("--volumes")
    shell_params = ShellParams({})
    env_variables = construct_env_variables_docker_compose_command(shell_params)
    run_command(command_to_execute, verbose=verbose, dry_run=dry_run, env=env_variables)
Пример #3
0
def run_shell_with_build_image_checks(verbose: bool, dry_run: bool,
                                      shell_params: ShellParams):
    """
    Executes shell command built from params passed, checking if build is not needed.
    * checks if there are enough resources to run shell
    * checks if image was built at least once (if not - forces the build)
    * if not forces, checks if build is needed and asks the user if so
    * builds the image if needed
    * prints information about the build
    * constructs docker compose command to enter shell
    * executes it

    :param verbose: print commands when running
    :param dry_run: do not execute "write" commands - just print what would happen
    :param shell_params: parameters of the execution
    """
    check_docker_resources(verbose, shell_params.airflow_image_name)
    build_ci_image_check_cache = Path(BUILD_CACHE_DIR,
                                      shell_params.airflow_branch,
                                      f".built_{shell_params.python}")
    if build_ci_image_check_cache.exists():
        console.print(
            f'[bright_blue]{shell_params.the_image_type} image already built locally.[/]'
        )
    else:
        console.print(
            f'[bright_yellow]{shell_params.the_image_type} image not built locally. '
            f'Forcing build.[/]')
        shell_params.force_build = True

    if not shell_params.force_build:
        build_image_if_needed_steps(verbose, dry_run, shell_params)
    else:
        build_image(
            verbose,
            dry_run=dry_run,
            python=shell_params.python,
            upgrade_to_newer_dependencies="false",
        )
    shell_params.print_badge_info()
    cmd = [
        'docker-compose', 'run', '--service-ports', "-e", "BREEZE", '--rm',
        'airflow'
    ]
    cmd_added = shell_params.command_passed
    env_variables = construct_env_variables_docker_compose_command(
        shell_params)
    if cmd_added is not None:
        cmd.extend(['-c', cmd_added])
    run_command(cmd,
                verbose=verbose,
                dry_run=dry_run,
                env=env_variables,
                text=True)
Пример #4
0
def build_docs(
    verbose: bool,
    dry_run: bool,
    github_repository: str,
    docs_only: bool,
    spellcheck_only: bool,
    package_filter: Tuple[str],
):
    """Build documentation in the container."""
    params = BuildCiParams(github_repository=github_repository,
                           python=DEFAULT_PYTHON_MAJOR_MINOR_VERSION)
    ci_image_name = params.airflow_image_name
    doc_builder = DocBuildParams(
        package_filter=package_filter,
        docs_only=docs_only,
        spellcheck_only=spellcheck_only,
    )
    extra_docker_flags = get_extra_docker_flags(MOUNT_SELECTED)
    env = construct_env_variables_docker_compose_command(params)
    cmd = [
        "docker",
        "run",
        "-t",
        *extra_docker_flags,
        "-e",
        "GITHUB_ACTIONS=",
        "-e",
        "SKIP_ENVIRONMENT_INITIALIZATION=true",
        "--pull",
        "never",
        ci_image_name,
        "/opt/airflow/scripts/in_container/run_docs_build.sh",
        *doc_builder.args_doc_builder,
    ]
    process = run_command(cmd,
                          verbose=verbose,
                          dry_run=dry_run,
                          text=True,
                          env=env,
                          check=False)
    sys.exit(process.returncode)
Пример #5
0
def run_generate_constraints(
    shell_params: ShellParams, dry_run: bool, verbose: bool, generate_constraints_mode: str
) -> Tuple[int, str]:
    env_variables = construct_env_variables_docker_compose_command(shell_params)
    extra_docker_flags = get_extra_docker_flags(shell_params.mount_sources)
    cmd_to_run = [
        "docker",
        "run",
        "-t",
        *extra_docker_flags,
        "-e",
        "SKIP_ENVIRONMENT_INITIALIZATION=true",
        "-e",
        f"GENERATE_CONSTRAINTS_MODE={generate_constraints_mode}",
        "--pull",
        "never",
        shell_params.airflow_image_name_with_tag,
        "/opt/airflow/scripts/in_container/run_generate_constraints.sh",
    ]
    generate_constraints_result = run_command(cmd_to_run, verbose=verbose, dry_run=dry_run, env=env_variables)
    return (
        generate_constraints_result.returncode,
        f"Generate constraints Python {shell_params.python}:{generate_constraints_mode}",
    )