You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2020/12/23 20:08:59 UTC

[airflow] branch master updated: Compile assets automatically when needed at Breeze entry (#13292)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a1e06ac  Compile assets automatically when needed at Breeze entry (#13292)
a1e06ac is described below

commit a1e06ac7a65dddfee26e39b4191766d9c840c1fe
Author: Jarek Potiuk <ja...@polidea.com>
AuthorDate: Wed Dec 23 21:08:47 2020 +0100

    Compile assets automatically when needed at Breeze entry (#13292)
    
    We are storing md5 sum of all relevant files to know when we need
    to recompile the assets.
    
    Fixes #12262
---
 airflow/www/compile_assets_if_needed.sh | 36 +++++++++++++++++++++++++++++++++
 scripts/in_container/entrypoint_ci.sh   | 21 +------------------
 2 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/airflow/www/compile_assets_if_needed.sh b/airflow/www/compile_assets_if_needed.sh
new file mode 100755
index 0000000..154381b
--- /dev/null
+++ b/airflow/www/compile_assets_if_needed.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -e
+
+cd "$( dirname "${BASH_SOURCE[0]}" )"
+
+MD5SUM_FILE="static/dist/sum.md5"
+readonly MD5SUM_FILE
+
+md5sum=$(find package.json yarn.lock static/css static/js -type f | sort  | xargs md5sum)
+old_md5sum=$(cat "${MD5SUM_FILE}" 2>/dev/null || true)
+if [[ ${old_md5sum} != "${md5sum}" ]]; then
+    echo
+    echo "The assets need to be recompiled because some of the www source files changed"
+    echo
+    ./compile_assets.sh
+    echo "${md5sum}" > "${MD5SUM_FILE}"
+else
+    echo "No need to recompile www assets"
+fi
diff --git a/scripts/in_container/entrypoint_ci.sh b/scripts/in_container/entrypoint_ci.sh
index 28a412c..6f5cece 100755
--- a/scripts/in_container/entrypoint_ci.sh
+++ b/scripts/in_container/entrypoint_ci.sh
@@ -75,26 +75,7 @@ if [[ -z ${INSTALL_AIRFLOW_VERSION=} ]]; then
     echo
     echo "Using already installed airflow version"
     echo
-    if [[ ! -d "${AIRFLOW_SOURCES}/airflow/www/node_modules" ]]; then
-        echo
-        echo "Installing node modules as they are not yet installed (Sources mounted from Host)"
-        echo
-        pushd "${AIRFLOW_SOURCES}/airflow/www/" &>/dev/null || exit 1
-        yarn install --frozen-lockfile
-        echo
-        popd &>/dev/null || exit 1
-    fi
-    if [[ ! -d "${AIRFLOW_SOURCES}/airflow/www/static/dist" ]]; then
-        pushd "${AIRFLOW_SOURCES}/airflow/www/" &>/dev/null || exit 1
-        echo
-        echo "Building production version of JavaScript files (Sources mounted from Host)"
-        echo
-        echo
-        yarn run prod
-        echo
-        echo
-        popd &>/dev/null || exit 1
-    fi
+    "${AIRFLOW_SOURCES}/airflow/www/compile_assets_if_needed.sh"
     # Cleanup the logs, tmp when entering the environment
     sudo rm -rf "${AIRFLOW_SOURCES}"/logs/*
     sudo rm -rf "${AIRFLOW_SOURCES}"/tmp/*