Skip to content

Commit

Permalink
Better fix for constraint-reference (#23845)
Browse files Browse the repository at this point in the history
The previous fix (#23844) broke main on package verification
as the package verification used the same parameter that was set to
empty.

This change rmeoves some remnant from the "bash" version where
we had to check if variable was empty and also making the "constraint"
parameters accepting default values from the current branch to be used
also for build commands.

(cherry picked from commit 10a0d8e)
  • Loading branch information
potiuk authored and ephraimbuddy committed May 21, 2022
1 parent 045abd9 commit 5b5dd7f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 34 deletions.
9 changes: 2 additions & 7 deletions dev/breeze/src/airflow_breeze/commands/ci_image_commands.py
Expand Up @@ -22,7 +22,6 @@

import click

from airflow_breeze.branch_defaults import DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH
from airflow_breeze.commands.main_command import main
from airflow_breeze.params.build_ci_params import BuildCiParams
from airflow_breeze.params.shell_params import ShellParams
Expand All @@ -36,6 +35,7 @@
option_additional_runtime_apt_deps,
option_additional_runtime_apt_env,
option_airflow_constraints_mode_ci,
option_airflow_constraints_reference_build,
option_answer,
option_build_multiple_images,
option_debian_version,
Expand Down Expand Up @@ -221,12 +221,7 @@
@option_runtime_apt_deps
@option_force_build
@option_airflow_constraints_mode_ci
@click.option(
"--airflow-constraints-reference",
default=DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH,
help="Constraint reference to use when building the image.",
envvar='AIRFLOW_CONSTRAINTS_REFERENCE',
)
@option_airflow_constraints_reference_build
@option_tag_as_latest
def build_image(
verbose: bool,
Expand Down
Expand Up @@ -21,7 +21,6 @@

import click

from airflow_breeze.branch_defaults import DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH
from airflow_breeze.commands.main_command import main
from airflow_breeze.global_constants import ALLOWED_INSTALLATION_METHODS, DEFAULT_EXTRAS
from airflow_breeze.params.build_prod_params import BuildProdParams
Expand All @@ -35,6 +34,7 @@
option_additional_runtime_apt_deps,
option_additional_runtime_apt_env,
option_airflow_constraints_mode_prod,
option_airflow_constraints_reference_build,
option_answer,
option_build_multiple_images,
option_debian_version,
Expand Down Expand Up @@ -249,12 +249,7 @@
'--install-airflow-reference',
help="Install Airflow using GitHub tag or branch.",
)
@click.option(
"--airflow-constraints-reference",
default=DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH,
help="Constraint reference to use when building the image.",
envvar='AIRFLOW_CONSTRAINTS_REFERENCE',
)
@option_airflow_constraints_reference_build
@click.option('-V', '--install-airflow-version', help="Install version of Airflow from PyPI.")
@option_additional_extras
@option_additional_dev_apt_deps
Expand Down
4 changes: 1 addition & 3 deletions dev/breeze/src/airflow_breeze/params/_common_build_params.py
Expand Up @@ -21,7 +21,7 @@
from datetime import datetime
from typing import List, Optional

from airflow_breeze.branch_defaults import AIRFLOW_BRANCH, DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH
from airflow_breeze.branch_defaults import AIRFLOW_BRANCH
from airflow_breeze.utils.console import get_console
from airflow_breeze.utils.platforms import get_real_platform

Expand All @@ -42,12 +42,10 @@ class _CommonBuildParams:
additional_runtime_apt_env: str = ""
airflow_branch: str = AIRFLOW_BRANCH
airflow_constraints_location: str = ""
airflow_constraints_reference: str = "constraints-main"
answer: Optional[str] = None
build_id: int = 0
constraints_github_repository: str = "apache/airflow"
debian_version: str = "bullseye"
default_constraints_branch = DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH
dev_apt_command: str = ""
dev_apt_deps: str = ""
docker_cache: str = "registry"
Expand Down
5 changes: 5 additions & 0 deletions dev/breeze/src/airflow_breeze/params/build_ci_params.py
Expand Up @@ -18,6 +18,7 @@
from pathlib import Path
from typing import List

from airflow_breeze.branch_defaults import DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH
from airflow_breeze.global_constants import get_airflow_version
from airflow_breeze.params._common_build_params import _CommonBuildParams
from airflow_breeze.utils.console import get_console
Expand All @@ -31,6 +32,7 @@ class BuildCiParams(_CommonBuildParams):
"""

airflow_constraints_mode: str = "constraints-source-providers"
airflow_constraints_reference: str = DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH
airflow_extras: str = "devel_ci"
airflow_pre_cached_pip_packages: bool = True
force_build: bool = False
Expand All @@ -46,6 +48,9 @@ def image_type(self) -> str:
@property
def extra_docker_build_flags(self) -> List[str]:
extra_ci_flags = []
extra_ci_flags.extend(
["--build-arg", f"AIRFLOW_CONSTRAINTS_REFERENCE={self.airflow_constraints_reference}"]
)
if self.airflow_constraints_location is not None and len(self.airflow_constraints_location) > 0:
extra_ci_flags.extend(
["--build-arg", f"AIRFLOW_CONSTRAINTS_LOCATION={self.airflow_constraints_location}"]
Expand Down
21 changes: 9 additions & 12 deletions dev/breeze/src/airflow_breeze/params/build_prod_params.py
Expand Up @@ -41,6 +41,7 @@ class BuildProdParams(_CommonBuildParams):
"""

airflow_constraints_mode: str = "constraints"
airflow_constraints_reference: str = ""
airflow_is_in_context: bool = False
cleanup_context: bool = False
disable_airflow_repo_cache: bool = False
Expand Down Expand Up @@ -79,20 +80,16 @@ def args_for_remote_install(self) -> List:
"AIRFLOW_SOURCES_TO=/empty",
]
)
if len(self.airflow_constraints_reference) > 0:
if re.match('v?2.*', self.airflow_version):
build_args.extend(
["--build-arg", f"AIRFLOW_CONSTRAINTS_REFERENCE={self.airflow_constraints_reference}"]
["--build-arg", f"AIRFLOW_CONSTRAINTS_REFERENCE=constraints-{self.airflow_version}"]
)
else:
if re.match('v?2.*', self.airflow_version):
build_args.extend(
["--build-arg", f"AIRFLOW_CONSTRAINTS_REFERENCE=constraints-{self.airflow_version}"]
)
else:
build_args.extend(
["--build-arg", f"AIRFLOW_CONSTRAINTS_REFERENCE={self.default_constraints_branch}"]
)
if len(self.airflow_constraints_location) > 0:
build_args.extend(
["--build-arg", f"AIRFLOW_CONSTRAINTS_REFERENCE={self.airflow_constraints_reference}"]
)
if self.airflow_constraints_location:
# override location if specified
build_args.extend(
["--build-arg", f"AIRFLOW_CONSTRAINTS_LOCATION={self.airflow_constraints_location}"]
)
Expand Down Expand Up @@ -165,7 +162,7 @@ def extra_docker_build_flags(self) -> List[str]:
"--build-arg",
f"AIRFLOW_INSTALLATION_METHOD={self.installation_method}",
"--build-arg",
f"AIRFLOW_CONSTRAINTS_REFERENCE={self.default_constraints_branch}",
f"AIRFLOW_CONSTRAINTS_REFERENCE={self.airflow_constraints_reference}",
]
)

Expand Down
9 changes: 9 additions & 0 deletions dev/breeze/src/airflow_breeze/utils/common_options.py
Expand Up @@ -19,6 +19,7 @@

import click

from airflow_breeze.branch_defaults import DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH
from airflow_breeze.global_constants import (
ALLOWED_BACKENDS,
ALLOWED_BUILD_CACHE,
Expand Down Expand Up @@ -415,8 +416,16 @@
"--airflow-constraints-reference",
help="Constraint reference to use. Useful with --use-airflow-version parameter to specify "
"constraints for the installed version and to find newer dependencies",
default=DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH,
envvar='AIRFLOW_CONSTRAINTS_REFERENCE',
)
option_airflow_constraints_reference_build = click.option(
"--airflow-constraints-reference",
default=DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH,
help="Constraint reference to use when building the image.",
envvar='AIRFLOW_CONSTRAINTS_REFERENCE',
)

option_airflow_constraints_mode_ci = click.option(
'--airflow-constraints-mode',
type=BetterChoice(ALLOWED_CONSTRAINTS_MODES_CI),
Expand Down
5 changes: 1 addition & 4 deletions dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
Expand Up @@ -36,7 +36,7 @@
# We handle the ImportError so that autocomplete works with just click installed
version = None # type: ignore[assignment]

from airflow_breeze.branch_defaults import AIRFLOW_BRANCH, DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH
from airflow_breeze.branch_defaults import AIRFLOW_BRANCH
from airflow_breeze.global_constants import (
ALLOWED_PACKAGE_FORMATS,
FLOWER_HOST_PORT,
Expand Down Expand Up @@ -456,7 +456,6 @@ def update_expected_environment_variables(env: Dict[str, str]) -> None:
:param env: environment variables to update with missing values if not set.
"""
set_value_to_default_if_not_set(env, 'AIRFLOW_CONSTRAINTS_MODE', "constraints-source-providers")
set_value_to_default_if_not_set(env, 'AIRFLOW_CONSTRAINTS_REFERENCE', DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH)
set_value_to_default_if_not_set(env, 'AIRFLOW_EXTRAS', "")
set_value_to_default_if_not_set(env, 'ANSWER', "")
set_value_to_default_if_not_set(env, 'BREEZE', "true")
Expand All @@ -470,7 +469,6 @@ def update_expected_environment_variables(env: Dict[str, str]) -> None:
set_value_to_default_if_not_set(env, 'DB_RESET', "false")
set_value_to_default_if_not_set(env, 'DEBIAN_VERSION', "bullseye")
set_value_to_default_if_not_set(env, 'DEFAULT_BRANCH', AIRFLOW_BRANCH)
set_value_to_default_if_not_set(env, 'DEFAULT_CONSTRAINTS_BRANCH', DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH)
set_value_to_default_if_not_set(env, 'ENABLED_SYSTEMS', "")
set_value_to_default_if_not_set(env, 'ENABLE_TEST_COVERAGE', "false")
set_value_to_default_if_not_set(env, 'GITHUB_REGISTRY_PULL_IMAGE_TAG', "latest")
Expand Down Expand Up @@ -504,7 +502,6 @@ def update_expected_environment_variables(env: Dict[str, str]) -> None:
"AIRFLOW_CI_IMAGE_WITH_TAG": "airflow_image_name_with_tag",
"AIRFLOW_EXTRAS": "airflow_extras",
"AIRFLOW_CONSTRAINTS_MODE": "airflow_constraints_mode",
"AIRFLOW_CONSTRAINTS_REFERENCE": "airflow_constraints_reference",
"AIRFLOW_IMAGE_KUBERNETES": "airflow_image_kubernetes",
"AIRFLOW_PROD_IMAGE": "airflow_image_name",
"AIRFLOW_SOURCES": "airflow_sources",
Expand Down
2 changes: 1 addition & 1 deletion images/breeze/output-commands-hash.txt
@@ -1 +1 @@
dd085eb6d80d465b5299e4f258153e84
43bc980dd30f21c6979990470870a936

0 comments on commit 5b5dd7f

Please sign in to comment.