Skip to content

Commit

Permalink
Breeze help images are now consistently generated in pre-commit (#26032)
Browse files Browse the repository at this point in the history
Images generated for Breeze Help can slightly differ, however we
want them to be generated always consistently. Therefore the images
are now (when using pre-commit) generated inside the CI image rather
than locally.

This change also introduces much more selective image generation
which will make the image generation much faster in case you
change any of breeze code. Previously, any change in any breeze
command parameters triggered regeneration of the images.
With this change, only those commands that get changed get
regenerated (and information about which images need to be regenerated
is printed).

This change removes one of the Breeze setup commands - the hash
generation - as it is now done internally by the regenerate command
and does not need to be externalized (--check-only) flag provides
a way how to check if breeze images need regeneration.
  • Loading branch information
potiuk authored Aug 30, 2022
1 parent 1d06374 commit 733d623
Show file tree
Hide file tree
Showing 65 changed files with 1,758 additions and 1,657 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,6 @@ repos:
pass_filenames: true
files: ^airflow/providers/.*\.py$
additional_dependencies: ['rich>=12.4.4']
- id: update-breeze-cmd-output
name: Update output of breeze commands in BREEZE.rst
entry: ./scripts/ci/pre_commit/pre_commit_breeze_cmd_line.py
language: python
files: ^BREEZE\.rst$|^dev/breeze/.*$|^\.pre-commit-config\.yml$
pass_filenames: false
additional_dependencies: ['rich>=12.4.4', 'rich-click>=1.5']
- id: update-local-yml-file
name: Update mounts in the local yml file
entry: ./scripts/ci/pre_commit/pre_commit_local_yml_mounts.py
Expand Down Expand Up @@ -900,6 +893,13 @@ repos:
exclude: ^docs/rtd-deprecation
require_serial: true
additional_dependencies: ['rich>=12.4.4', 'inputimeout']
- id: update-breeze-cmd-output
name: Update output of breeze commands in BREEZE.rst
entry: ./scripts/ci/pre_commit/pre_commit_breeze_cmd_line.py
language: python
files: ^BREEZE\.rst$|^dev/breeze/.*$|^\.pre-commit-config\.yml$
pass_filenames: false
additional_dependencies: ['rich>=12.4.4', 'rich-click>=1.5']
- id: run-flake8
name: Run flake8
language: python
Expand Down
20 changes: 8 additions & 12 deletions BREEZE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -943,23 +943,19 @@ You can self-upgrade breeze automatically. Those are all available flags of ``se
:width: 100%
:alt: Breeze setup self-upgrade

Exporting breeze command hash output
....................................

You can also dump hash of the configuration options used - this is mostly used to generate the dump
of help of the commands only when they change by pre-commit..

.. image:: ./images/breeze/output_setup_command-hash-export.svg
:width: 100%
:alt: Breeze config command-hash-export


Regenerating images for documentation
.....................................

This documentation contains exported images with "help" of their commands and parameters. You can
regenerate all those images (which might be needed in case new version of rich is used) via
``regenerate-command-images`` command.
regenerate those images that need to be regenerated because their commands changed (usually after
the breeze code has been changed) via ``regenerate-command-images`` command. Usually this is done
automatically via pre-commit, but sometimes (for example when ``rich`` or ``rich-click`` library changes)
you need to regenerate those images.

You can add ``--force`` flag (or ``FORCE="true"`` environment variable to regenerate all images (not
only those that need regeneration). You can also run the command with ``--check-only`` flag to simply
check if there are any images that need regeneration.

.. image:: ./images/breeze/output_setup_regenerate-command-images.svg
:width: 100%
Expand Down
2 changes: 1 addition & 1 deletion STATIC_CODE_CHECKS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ require Breeze Docker image to be build locally.
+--------------------------------------------------------+------------------------------------------------------------------+---------+
| ts-compile-and-lint-javascript | TS types generation and ESLint against current UI files | |
+--------------------------------------------------------+------------------------------------------------------------------+---------+
| update-breeze-cmd-output | Update output of breeze commands in BREEZE.rst | |
| update-breeze-cmd-output | Update output of breeze commands in BREEZE.rst | * |
+--------------------------------------------------------+------------------------------------------------------------------+---------+
| update-breeze-readme-config-hash | Update Breeze README.md with config files hash | |
+--------------------------------------------------------+------------------------------------------------------------------+---------+
Expand Down
21 changes: 2 additions & 19 deletions dev/breeze/src/airflow_breeze/commands/ci_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

from airflow_breeze.global_constants import (
DEFAULT_PYTHON_MAJOR_MINOR_VERSION,
MOUNT_ALL,
RUNS_ON_PUBLIC_RUNNER,
RUNS_ON_SELF_HOSTED_RUNNER,
GithubEvents,
Expand All @@ -54,13 +53,11 @@
from airflow_breeze.utils.custom_param_types import BetterChoice
from airflow_breeze.utils.docker_command_utils import (
check_docker_resources,
get_env_variables_for_docker_commands,
get_extra_docker_flags,
fix_ownership_using_docker,
perform_environment_checks,
)
from airflow_breeze.utils.find_newer_dependencies import find_newer_dependencies
from airflow_breeze.utils.github_actions import get_ga_output
from airflow_breeze.utils.image import find_available_ci_image
from airflow_breeze.utils.path_utils import AIRFLOW_SOURCES_ROOT
from airflow_breeze.utils.run_utils import run_command

Expand Down Expand Up @@ -166,21 +163,7 @@ def fix_ownership(github_repository: str, use_sudo: bool, verbose: bool, dry_run
fix_ownership_without_docker(dry_run=dry_run, verbose=verbose)
sys.exit(0)
get_console().print("[info]Fixing ownership using docker.")
perform_environment_checks(verbose=verbose)
shell_params = find_available_ci_image(github_repository, dry_run, verbose)
extra_docker_flags = get_extra_docker_flags(MOUNT_ALL)
env = get_env_variables_for_docker_commands(shell_params)
cmd = [
"docker",
"run",
"-t",
*extra_docker_flags,
"--pull",
"never",
shell_params.airflow_image_name_with_tag,
"/opt/airflow/scripts/in_container/run_fix_ownership.sh",
]
run_command(cmd, verbose=verbose, dry_run=dry_run, text=True, env=env, check=False)
fix_ownership_using_docker(dry_run=dry_run, verbose=verbose)
# Always succeed
sys.exit(0)

Expand Down
3 changes: 2 additions & 1 deletion dev/breeze/src/airflow_breeze/commands/developer_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ def static_checks(
env=env,
)
if static_checks_result.returncode != 0:
get_console().print("[error]There were errors during pre-commit check. They should be fixed[/]")
if os.environ.get('CI'):
get_console().print("[error]There were errors during pre-commit check. They should be fixed[/]")
sys.exit(static_checks_result.returncode)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from airflow_breeze.commands.ci_image_commands import rebuild_or_pull_ci_image_if_needed
from airflow_breeze.global_constants import (
ALLOWED_PLATFORMS,
APACHE_AIRFLOW_GITHUB_REPOSITORY,
CURRENT_PYTHON_MAJOR_MINOR_VERSIONS,
DEFAULT_PYTHON_MAJOR_MINOR_VERSION,
MOUNT_ALL,
Expand Down Expand Up @@ -525,7 +526,7 @@ def alias_image(image_from: str, image_to: str, dry_run: bool, verbose: bool):
@click.option('--airflow-version', required=True, help="Airflow version to release (2.3.0, 2.3.0rc1 etc.)")
@click.option(
'--dockerhub-repo',
default="apache/airflow",
default=APACHE_AIRFLOW_GITHUB_REPOSITORY,
show_default=True,
help="DockerHub repository for the images",
)
Expand Down
Loading

0 comments on commit 733d623

Please sign in to comment.