Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behaviour of build/pull after recent Breeze changes #24657

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions dev/breeze/src/airflow_breeze/commands/ci_image_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
option_github_token,
option_github_username,
option_image_name,
option_image_tag,
option_image_tag_for_building,
option_image_tag_for_pulling,
option_image_tag_for_verifying,
option_install_providers_from_sources,
option_parallelism,
option_platform_multiple,
Expand Down Expand Up @@ -191,7 +193,7 @@
}


def start_building(ci_image_params: BuildCiParams, dry_run: bool, verbose: bool) -> bool:
def check_if_image_building_is_needed(ci_image_params: BuildCiParams, dry_run: bool, verbose: bool) -> bool:
"""Starts building attempt. Returns false if we should not continue"""
if not ci_image_params.force_build and not ci_image_params.upgrade_to_newer_dependencies:
if not should_we_run_the_build(build_ci_params=ci_image_params):
Expand Down Expand Up @@ -238,7 +240,7 @@ def run_build_in_parallel(
@option_github_token
@option_github_username
@option_docker_cache
@option_image_tag
@option_image_tag_for_building
@option_prepare_buildx_cache
@option_push_image
@option_empty_image
Expand Down Expand Up @@ -292,7 +294,7 @@ def run_build(ci_image_params: BuildCiParams) -> None:
params.python = python
params.answer = answer
params_list.append(params)
start_building(params_list[0], dry_run=dry_run, verbose=verbose)
check_if_image_building_is_needed(params_list[0], dry_run=dry_run, verbose=verbose)
run_build_in_parallel(
image_params_list=params_list,
python_version_list=python_version_list,
Expand All @@ -302,7 +304,7 @@ def run_build(ci_image_params: BuildCiParams) -> None:
)
else:
params = BuildCiParams(**parameters_passed)
start_building(params, dry_run=dry_run, verbose=verbose)
check_if_image_building_is_needed(params, dry_run=dry_run, verbose=verbose)
run_build(ci_image_params=params)


Expand All @@ -317,7 +319,7 @@ def run_build(ci_image_params: BuildCiParams) -> None:
@option_github_token
@option_verify_image
@option_wait_for_image
@option_image_tag
@option_image_tag_for_pulling
@option_tag_as_latest
@click.argument('extra_pytest_args', nargs=-1, type=click.UNPROCESSED)
def pull_ci_image(
Expand All @@ -329,13 +331,20 @@ def pull_ci_image(
python_versions: str,
github_token: str,
parallelism: int,
image_tag: Optional[str],
image_tag: str,
wait_for_image: bool,
tag_as_latest: bool,
verify_image: bool,
extra_pytest_args: Tuple,
):
"""Pull and optionally verify CI images - possibly in parallel for all Python versions."""
if image_tag == "latest":
get_console().print("[red]You cannot pull latest images because they are not published any more!\n")
get_console().print(
"[yellow]You need to specify commit tag to pull and image. If you wish to get"
" the latest image, you need to run `breeze build-image` command\n"
)
sys.exit(1)
perform_environment_checks(verbose=verbose)
if run_in_parallel:
python_version_list = get_python_version_list(python_versions)
Expand Down Expand Up @@ -386,7 +395,7 @@ def pull_ci_image(
@option_dry_run
@option_python
@option_github_repository
@option_image_tag
@option_image_tag_for_verifying
@option_image_name
@option_pull_image
@click.argument('extra_pytest_args', nargs=-1, type=click.UNPROCESSED)
Expand All @@ -396,7 +405,7 @@ def verify_ci_image(
python: str,
github_repository: str,
image_name: str,
image_tag: str,
image_tag: Optional[str],
pull_image: bool,
extra_pytest_args: Tuple,
):
Expand Down Expand Up @@ -582,8 +591,9 @@ def rebuild_or_pull_ci_image_if_needed(
upgrade_to_newer_dependencies=False,
image_tag=command_params.image_tag,
platform=command_params.platform,
force_build=command_params.force_build,
potiuk marked this conversation as resolved.
Show resolved Hide resolved
)
if command_params.image_tag is not None:
if command_params.image_tag is not None and command_params.image_tag != "latest":
return_code, message = run_pull_image(
image_params=ci_image_params,
dry_run=dry_run,
Expand All @@ -605,4 +615,5 @@ def rebuild_or_pull_ci_image_if_needed(
'Forcing build.[/]'
)
ci_image_params.force_build = True
run_build_ci_image(verbose, dry_run=dry_run, ci_image_params=ci_image_params, parallel=False)
if check_if_image_building_is_needed(ci_image_params=ci_image_params, dry_run=dry_run, verbose=verbose):
run_build_ci_image(verbose, dry_run=dry_run, ci_image_params=ci_image_params, parallel=False)
12 changes: 6 additions & 6 deletions dev/breeze/src/airflow_breeze/commands/developer_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
option_force_build,
option_forward_credentials,
option_github_repository,
option_image_tag,
option_image_tag_for_running,
option_installation_package_format,
option_integration,
option_load_default_connection,
Expand Down Expand Up @@ -113,9 +113,9 @@
"--use-packages-from-dist",
"--package-format",
"--force-build",
"--image-tag",
"--mount-sources",
"--debian-version",
"--image-tag",
],
},
],
Expand All @@ -142,9 +142,9 @@
"--use-packages-from-dist",
"--package-format",
"--force-build",
"--image-tag",
"--mount-sources",
"--debian-version",
"--image-tag",
],
},
],
Expand Down Expand Up @@ -173,8 +173,8 @@
"--use-packages-from-dist",
"--package-format",
"--force-build",
"--mount-sources",
"--image-tag",
"--mount-sources",
],
},
],
Expand Down Expand Up @@ -244,7 +244,7 @@
@option_mount_sources
@option_integration
@option_db_reset
@option_image_tag
@option_image_tag_for_running
@option_answer
@click.argument('extra-args', nargs=-1, type=click.UNPROCESSED)
def shell(
Expand Down Expand Up @@ -324,7 +324,7 @@ def shell(
@option_installation_package_format
@option_mount_sources
@option_integration
@option_image_tag
@option_image_tag_for_running
@option_db_reset
@option_answer
@click.argument('extra-args', nargs=-1, type=click.UNPROCESSED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
option_github_token,
option_github_username,
option_image_name,
option_image_tag,
option_image_tag_for_building,
option_image_tag_for_pulling,
option_image_tag_for_verifying,
option_install_providers_from_sources,
option_parallelism,
option_platform_multiple,
Expand Down Expand Up @@ -246,7 +248,7 @@ def run_build_in_parallel(
@option_github_token
@option_github_username
@option_docker_cache
@option_image_tag
@option_image_tag_for_building
@option_prepare_buildx_cache
@option_push_image
@option_empty_image
Expand Down Expand Up @@ -363,7 +365,7 @@ def run_build(prod_image_params: BuildProdParams) -> None:
@option_parallelism
@option_python_versions
@option_github_token
@option_image_tag
@option_image_tag_for_pulling
@option_wait_for_image
@option_tag_as_latest
@option_verify_image
Expand All @@ -377,13 +379,20 @@ def pull_prod_image(
parallelism: int,
python_versions: str,
github_token: str,
image_tag: Optional[str],
image_tag: str,
wait_for_image: bool,
tag_as_latest: bool,
verify_image: bool,
extra_pytest_args: Tuple,
):
"""Pull and optionally verify Production images - possibly in parallel for all Python versions."""
if image_tag == "latest":
get_console().print("[red]You cannot pull latest images because they are not published any more!\n")
get_console().print(
"[yellow]You need to specify commit tag to pull and image. If you wish to get"
" the latest image, you need to run `breeze build-image` command\n"
)
sys.exit(1)
perform_environment_checks(verbose=verbose)
if run_in_parallel:
python_version_list = get_python_version_list(python_versions)
Expand Down Expand Up @@ -436,7 +445,7 @@ def pull_prod_image(
@option_dry_run
@option_python
@option_github_repository
@option_image_tag
@option_image_tag_for_verifying
@option_image_name
@option_pull_image
@click.option(
Expand All @@ -451,7 +460,7 @@ def verify_prod_image(
python: str,
github_repository: str,
image_name: str,
image_tag: str,
image_tag: Optional[str],
pull_image: bool,
slim_image: bool,
extra_pytest_args: Tuple,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
option_answer,
option_dry_run,
option_github_repository,
option_image_tag,
option_image_tag_for_running,
option_installation_package_format,
option_package_format,
option_parallelism,
Expand Down Expand Up @@ -402,7 +402,7 @@ def run_generate_constraints_in_parallel(
@option_run_in_parallel
@option_parallelism
@option_python_versions
@option_image_tag
@option_image_tag_for_running
@option_answer
@option_debug_release_management
@option_airflow_constraints_mode_ci
Expand All @@ -414,7 +414,7 @@ def generate_constraints(
run_in_parallel: bool,
parallelism: int,
python_versions: str,
image_tag: str,
image_tag: Optional[str],
answer: Optional[str],
debug: bool,
airflow_constraints_mode: str,
Expand Down
8 changes: 4 additions & 4 deletions dev/breeze/src/airflow_breeze/commands/testing_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
option_dry_run,
option_github_repository,
option_image_name,
option_image_tag,
option_image_tag_for_running,
option_integration,
option_mount_sources,
option_mssql_version,
Expand Down Expand Up @@ -109,7 +109,7 @@
@option_dry_run
@option_python
@option_github_repository
@option_image_tag
@option_image_tag_for_running
@option_image_name
@click.argument('extra_pytest_args', nargs=-1, type=click.UNPROCESSED)
def docker_compose_tests(
Expand All @@ -118,7 +118,7 @@ def docker_compose_tests(
python: str,
github_repository: str,
image_name: str,
image_tag: str,
image_tag: Optional[str],
extra_pytest_args: Tuple,
):
"""Run docker-compose tests."""
Expand Down Expand Up @@ -243,7 +243,7 @@ def run_with_progress(
help="Limit progress to percentage only and just show the summary when tests complete.",
is_flag=True,
)
@option_image_tag
@option_image_tag_for_running
@option_mount_sources
@click.option(
"--test-type",
Expand Down
24 changes: 21 additions & 3 deletions dev/breeze/src/airflow_breeze/utils/common_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,29 @@
help='The user name used to authenticate to GitHub.',
envvar='GITHUB_USERNAME',
)
option_image_tag = click.option(
option_image_tag_for_pulling = click.option(
'-t',
'--image-tag',
help='Tag of the image which is used to pull or run the image (implies --mount-sources=skip'
' when using to run shell or tests) ',
help='Tag of the image which is used to pull the image',
envvar='IMAGE_TAG',
required=True,
)
option_image_tag_for_building = click.option(
'-t',
'--image-tag',
help='Tag the image after building it',
envvar='IMAGE_TAG',
)
option_image_tag_for_running = click.option(
'-t',
'--image-tag',
help='Tag of the image which is used to run the image (implies --mount-sources=skip)',
envvar='IMAGE_TAG',
)
option_image_tag_for_verifying = click.option(
'-t',
'--image-tag',
help='Tag of the image when verifying it',
envvar='IMAGE_TAG',
)
option_image_name = click.option(
Expand Down
Loading