You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ep...@apache.org on 2023/03/08 14:44:24 UTC

[airflow] 09/20: Fix asset compilation in start-airflow (#29185)

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

ephraimanierobi pushed a commit to branch v2-5-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit d56606ea97975794d9d7ef47d79ed4aada66c3bb
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Thu Jan 26 23:40:56 2023 +0100

    Fix asset compilation in start-airflow (#29185)
    
    The recent change #29080 introduced missing black import in the
    pre-commit that run the compilation. The compilation happened in
    the background thread and it's ouptut was only visible in the
    asset_compilation output file
    
    This PR fixes the black import problem by removing unnecessary import,
    but it will also stop start-airflow and exit with error as well as
    surface the output of asset compilation to the console.
    
    (cherry picked from commit c231f1174d67d05384832b75f6ca7c02f5fda73c)
---
 Dockerfile.ci                                          |  9 +++++++++
 dev/breeze/src/airflow_breeze/utils/run_utils.py       | 12 +++++++++---
 scripts/ci/pre_commit/pre_commit_compile_www_assets.py |  1 -
 scripts/docker/entrypoint_ci.sh                        |  9 +++++++++
 4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/Dockerfile.ci b/Dockerfile.ci
index 369faab2ab..76afec0321 100644
--- a/Dockerfile.ci
+++ b/Dockerfile.ci
@@ -623,6 +623,15 @@ If it does not complete soon, you might want to stop it and remove file lock:
             fi
         done
     fi
+    if [ -f "${AIRFLOW_SOURCES}/.build/www/asset_compile.out" ]; then
+        echo
+        echo "${COLOR_RED}The asset compilation failed. Exiting.${COLOR_RESET}"
+        echo
+        cat "${AIRFLOW_SOURCES}/.build/www/asset_compile.out"
+        rm "${AIRFLOW_SOURCES}/.build/www/asset_compile.out"
+        echo
+        exit 1
+    fi
 }
 
 if [[ ${SKIP_ENVIRONMENT_INITIALIZATION=} != "true" ]]; then
diff --git a/dev/breeze/src/airflow_breeze/utils/run_utils.py b/dev/breeze/src/airflow_breeze/utils/run_utils.py
index ac0f689814..0209caf19a 100644
--- a/dev/breeze/src/airflow_breeze/utils/run_utils.py
+++ b/dev/breeze/src/airflow_breeze/utils/run_utils.py
@@ -418,16 +418,22 @@ def _run_compile_internally(command_to_execute: list[str], dev: bool) -> RunComm
             pass
         try:
             with SoftFileLock(WWW_ASSET_COMPILE_LOCK, timeout=5):
-                with open(WWW_ASSET_OUT_FILE, "w") as f:
-                    return run_command(
+                with open(WWW_ASSET_OUT_FILE, "w") as output_file:
+                    result = run_command(
                         command_to_execute,
                         check=False,
                         no_output_dump_on_exception=True,
                         text=True,
                         env=env,
                         stderr=subprocess.STDOUT,
-                        stdout=f,
+                        stdout=output_file,
                     )
+                if result.returncode == 0:
+                    try:
+                        WWW_ASSET_OUT_FILE.unlink()
+                    except FileNotFoundError:
+                        pass
+                return result
         except Timeout:
             get_console().print("[error]Another asset compilation is running. Exiting[/]\n")
             get_console().print("[warning]If you are sure there is no other compilation,[/]")
diff --git a/scripts/ci/pre_commit/pre_commit_compile_www_assets.py b/scripts/ci/pre_commit/pre_commit_compile_www_assets.py
index 4733a1460b..8c43f72fd2 100755
--- a/scripts/ci/pre_commit/pre_commit_compile_www_assets.py
+++ b/scripts/ci/pre_commit/pre_commit_compile_www_assets.py
@@ -24,7 +24,6 @@ from pathlib import Path
 
 sys.path.insert(0, str(Path(__file__).parent.resolve()))  # make sure common_precommit_utils is imported
 from common_precommit_utils import get_directory_hash  # isort: skip # noqa E402
-from common_precommit_black_utils import black_format  # isort: skip # noqa E402
 
 AIRFLOW_SOURCES_PATH = Path(__file__).parents[3].resolve()
 WWW_HASH_FILE = AIRFLOW_SOURCES_PATH / ".build" / "www" / "hash.txt"
diff --git a/scripts/docker/entrypoint_ci.sh b/scripts/docker/entrypoint_ci.sh
index 9454626d6c..85bf24e009 100755
--- a/scripts/docker/entrypoint_ci.sh
+++ b/scripts/docker/entrypoint_ci.sh
@@ -72,6 +72,15 @@ If it does not complete soon, you might want to stop it and remove file lock:
             fi
         done
     fi
+    if [ -f "${AIRFLOW_SOURCES}/.build/www/asset_compile.out" ]; then
+        echo
+        echo "${COLOR_RED}The asset compilation failed. Exiting.${COLOR_RESET}"
+        echo
+        cat "${AIRFLOW_SOURCES}/.build/www/asset_compile.out"
+        rm "${AIRFLOW_SOURCES}/.build/www/asset_compile.out"
+        echo
+        exit 1
+    fi
 }
 
 if [[ ${SKIP_ENVIRONMENT_INITIALIZATION=} != "true" ]]; then