This is an automated email from the ASF dual-hosted git repository.

pierrejeambrun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new c2477b3a44 Add command to build a base image with all airflow versions 
(#34577)
c2477b3a44 is described below

commit c2477b3a442d9d8031aee3b3afff4ef8706e321d
Author: Pierre Jeambrun <[email protected]>
AuthorDate: Sat Sep 23 20:29:18 2023 +0200

    Add command to build a base image with all airflow versions (#34577)
---
 dev/breeze/src/airflow_breeze/utils/cdxgen.py | 27 ++++++++++++++++++++++++++-
 dev/breeze/src/airflow_breeze/utils/github.py |  2 ++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/dev/breeze/src/airflow_breeze/utils/cdxgen.py 
b/dev/breeze/src/airflow_breeze/utils/cdxgen.py
index e72ef8fc72..74a3b7765d 100644
--- a/dev/breeze/src/airflow_breeze/utils/cdxgen.py
+++ b/dev/breeze/src/airflow_breeze/utils/cdxgen.py
@@ -31,7 +31,11 @@ import yaml
 
 from airflow_breeze.global_constants import DEFAULT_PYTHON_MAJOR_MINOR_VERSION
 from airflow_breeze.utils.console import Output, get_console
-from airflow_breeze.utils.github import download_constraints_file, 
download_file_from_github
+from airflow_breeze.utils.github import (
+    download_constraints_file,
+    download_file_from_github,
+    get_active_airflow_versions,
+)
 from airflow_breeze.utils.path_utils import AIRFLOW_SOURCES_ROOT, FILES_DIR
 from airflow_breeze.utils.run_utils import run_command
 from airflow_breeze.utils.shared_options import get_dry_run
@@ -211,6 +215,27 @@ chown --recursive {os.getuid()}:{os.getgid()} 
{DOCKER_FILE_PREFIX}
     )
 
 
+def build_all_airflow_versions_base_image(python_version: str):
+    """
+    Build an image with all airflow versions pre-installed in separate 
virtualenvs.
+    """
+    image_name = 
f"apache/airflow-dev/all_airflow_versions/python{python_version}"
+    dockerfile = f"""
+FROM ghcr.io/apache/airflow/main/ci/python{python_version}
+RUN pip install --upgrade pip
+    """
+    for airflow_version in get_active_airflow_versions():
+        dockerfile += f"""
+# Create the virtualenv and install the proper airflow version in it
+RUN python -m venv /opt/airflow/airflow-{airflow_version} && \
+/opt/airflow/airflow-{airflow_version}/bin/pip install --upgrade pip && \
+/opt/airflow/airflow-{airflow_version}/bin/pip install 
apache-airflow=={airflow_version} \
+    --constraint https://raw.githubusercontent.com/apache/airflow/\
+constraints-{airflow_version}/constraints-{python_version}.txt
+"""
+    run_command(["docker", "build", "--tag", image_name, "-"], 
input=dockerfile, text=True, check=True)
+
+
 @dataclass
 class SbomApplicationJob:
     airflow_version: str
diff --git a/dev/breeze/src/airflow_breeze/utils/github.py 
b/dev/breeze/src/airflow_breeze/utils/github.py
index 7ae4f914bb..2c8f67dbea 100644
--- a/dev/breeze/src/airflow_breeze/utils/github.py
+++ b/dev/breeze/src/airflow_breeze/utils/github.py
@@ -71,6 +71,8 @@ ACTIVE_TAG_MATCH = re.compile(r"^(\d+)\.\d+\.\d+$")
 def get_active_airflow_versions(confirm: bool = True) -> list[str]:
     """
     Gets list of active Airflow versions from GitHub.
+
+    :param confirm: if True, will ask the user before proceeding with the 
versions found
     :return: list of active Airflow versions
     """
     from git import GitCommandError, Repo

Reply via email to