Skip to content
Permalink
Browse files
Better fix for constraint-reference (#23845)
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.
  • Loading branch information
potiuk committed May 21, 2022
1 parent cc3ab43 commit 10a0d8e7085f018b7328533030de76b48de747e2
Showing 8 changed files with 30 additions and 34 deletions.
@@ -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
@@ -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,
@@ -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,
@@ -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
@@ -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,
@@ -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
@@ -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

@@ -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"
@@ -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
@@ -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
@@ -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}"]
@@ -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
@@ -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}"]
)
@@ -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}",
]
)

@@ -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,
@@ -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),
@@ -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,
@@ -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")
@@ -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")
@@ -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",
@@ -1 +1 @@
ab4be8e4ea37747cdbb1a4ad12ea5e33
aa34cfc99f60649fea3b808ef225981e

0 comments on commit 10a0d8e

Please sign in to comment.