Example #1
0
def build_image_checks(verbose: bool, shell_params: ShellBuilder):
    fix_group_permissions()
    build_ci_image_check_cache = Path(BUILD_CACHE_DIR,
                                      shell_params.airflow_branch,
                                      f".built_{shell_params.python_version}")
    if build_ci_image_check_cache.exists():
        console.print(
            f'{shell_params.the_image_type} image already built locally.')
    else:
        console.print(f'{shell_params.the_image_type} image not built locally')

    if not shell_params.force_build:
        build_image_if_needed_steps(verbose, shell_params)
    else:
        build_image(
            verbose,
            python_version=shell_params.python_version,
            upgrade_to_newer_dependencies="false",
        )

    instruct_for_setup()
    check_docker_resources(verbose, str(shell_params.airflow_sources),
                           shell_params.airflow_ci_image_name)
    cmd = ['docker-compose', 'run', '--service-ports', '--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])
    if verbose:
        shell_params.print_badge_info()
    output = run_command(cmd, verbose=verbose, env=env_variables, text=True)
    if verbose:
        console.print(f"[blue]{output}[/]")
Example #2
0
def build_image_if_needed_steps(verbose: bool, shell_params: ShellBuilder):
    build_needed = md5sum_check_if_build_is_needed(
        shell_params.md5sum_cache_dir, shell_params.the_image_type)
    if build_needed:
        try:
            user_status = inputimeout(
                prompt=
                '\nDo you want to build image?Press y/n/q in 5 seconds\n',
                timeout=5,
            )
            if user_status == 'y':
                latest_sha = get_latest_sha(shell_params.github_repository,
                                            shell_params.airflow_branch)
                if is_repo_rebased(latest_sha):
                    build_image(
                        verbose,
                        python_version=shell_params.python_version,
                        upgrade_to_newer_dependencies="false",
                    )
                else:
                    if click.confirm(
                            "\nThis might take a lot of time, we think you should rebase first. \
                            But if you really, really want - you can do it\n"):
                        build_image(
                            verbose,
                            python_version=shell_params.python_version,
                            upgrade_to_newer_dependencies="false",
                        )
                    else:
                        console.print(
                            '\nPlease rebase your code before continuing.\
                                Check this link to know more \
                                     https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#id15\n'
                        )
                        console.print('Exiting the process')
                        sys.exit()
            elif user_status == 'n':
                instruct_build_image(shell_params.the_image_type,
                                     shell_params.python_version)
            elif user_status == 'q':
                console.print('\nQuitting the process')
                sys.exit()
            else:
                console.print('\nYou have given a wrong choice:', user_status,
                              ' Quitting the process')
                sys.exit()
        except TimeoutOccurred:
            console.print('\nTimeout. Considering your response as No\n')
            instruct_build_image(shell_params.the_image_type,
                                 shell_params.python_version)
        except Exception:
            console.print('\nTerminating the process')
            sys.exit()
Example #3
0
def build_ci_image(
    verbose: bool,
    additional_extras: Optional[str],
    python: str,
    additional_dev_apt_deps: Optional[str],
    additional_runtime_apt_deps: Optional[str],
    additional_python_deps: Optional[str],
    additional_dev_apt_command: Optional[str],
    additional_runtime_apt_command: Optional[str],
    additional_dev_apt_env: Optional[str],
    additional_runtime_apt_env: Optional[str],
    dev_apt_command: Optional[str],
    dev_apt_deps: Optional[str],
    runtime_apt_command: Optional[str],
    runtime_apt_deps: Optional[str],
    github_repository: Optional[str],
    build_cache: Optional[str],
    platform: Optional[str],
    debian_version: Optional[str],
    prepare_buildx_cache: bool,
    ci: bool,
    upgrade_to_newer_dependencies: str = "false",
):
    """Builds docker CI image without entering the container."""

    if verbose:
        console.print(
            f"\n[blue]Building image of airflow from {__AIRFLOW_SOURCES_ROOT} "
            f"python version: {python}[/]\n")
    create_directories()
    build_image(
        verbose,
        additional_extras=additional_extras,
        python_version=python,
        additional_dev_apt_deps=additional_dev_apt_deps,
        additional_runtime_apt_deps=additional_runtime_apt_deps,
        additional_python_deps=additional_python_deps,
        additional_runtime_apt_command=additional_runtime_apt_command,
        additional_dev_apt_command=additional_dev_apt_command,
        additional_dev_apt_env=additional_dev_apt_env,
        additional_runtime_apt_env=additional_runtime_apt_env,
        dev_apt_command=dev_apt_command,
        dev_apt_deps=dev_apt_deps,
        runtime_apt_command=runtime_apt_command,
        runtime_apt_deps=runtime_apt_deps,
        github_repository=github_repository,
        docker_cache=build_cache,
        platform=platform,
        debian_version=debian_version,
        prepare_buildx_cache=prepare_buildx_cache,
        ci=ci,
        upgrade_to_newer_dependencies=upgrade_to_newer_dependencies,
    )
Example #4
0
def build_ci_image(
    verbose: bool,
    additional_extras: Optional[str],
    python: Optional[float],
    additional_dev_apt_deps: Optional[str],
    additional_runtime_apt_deps: Optional[str],
    additional_python_deps: Optional[str],
    additional_dev_apt_command: Optional[str],
    additional_runtime_apt_command: Optional[str],
    additional_dev_apt_env: Optional[str],
    additional_runtime_apt_env: Optional[str],
    dev_apt_command: Optional[str],
    dev_apt_deps: Optional[str],
    runtime_apt_command: Optional[str],
    runtime_apt_deps: Optional[str],
    github_repository: Optional[str],
    build_cache: Optional[str],
    upgrade_to_newer_dependencies: bool,
):
    """Builds docker CI image without entering the container."""

    if verbose:
        console.print(
            f"\n[blue]Building image of airflow from {__AIRFLOW_SOURCES_ROOT}[/]\n"
        )
    build_image(
        verbose,
        additional_extras=additional_extras,
        python_version=python,
        additional_dev_apt_deps=additional_dev_apt_deps,
        additional_runtime_apt_deps=additional_runtime_apt_deps,
        additional_python_deps=additional_python_deps,
        additional_runtime_apt_command=additional_runtime_apt_command,
        additional_dev_apt_command=additional_dev_apt_command,
        additional_dev_apt_env=additional_dev_apt_env,
        additional_runtime_apt_env=additional_runtime_apt_env,
        dev_apt_command=dev_apt_command,
        dev_apt_deps=dev_apt_deps,
        runtime_apt_command=runtime_apt_command,
        runtime_apt_deps=runtime_apt_deps,
        github_repository=github_repository,
        docker_cache=build_cache,
        upgrade_to_newer_dependencies=str(
            upgrade_to_newer_dependencies).lower(),
    )