From 660027f65d5333368aad7f16d3c927b9615e60ac Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Mon, 19 Jul 2021 19:52:15 +0200 Subject: [PATCH] Fixes UI assets compilation from PROD image built from sources (#17086) The #16577 change removed yarn.lock from installed packages and it removed the possibility of preparing assets after the package is installed - so far that was the way it was done in the PROD image built from sources. The asset compilation was supposed to work after the change but it was not performed in this case. The change fixes it by: * detecting properly if the PROD image is built from sources (INSTALLATION_METHOD) * compiling the assets from sources, not from package * installing airflow from sources AFTER assets were compiled Fixes #16939 --- Dockerfile | 11 ++++++----- scripts/docker/compile_www_assets.sh | 7 ++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8c3291324e52b..66c9649f8be49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -248,15 +248,16 @@ ENV ADDITIONAL_PYTHON_DEPS=${ADDITIONAL_PYTHON_DEPS} \ WORKDIR /opt/airflow # hadolint ignore=SC2086, SC2010 -RUN if [[ ${INSTALL_FROM_DOCKER_CONTEXT_FILES} == "true" ]]; then \ - bash /scripts/docker/install_from_docker_context_files.sh; \ - elif [[ ${INSTALL_FROM_PYPI} == "true" ]]; then \ - bash /scripts/docker/install_airflow.sh; \ - else \ +RUN if [[ ${AIRFLOW_INSTALLATION_METHOD} == "." ]]; then \ # only compile assets if the prod image is build from sources # otherwise they are already compiled-in bash /scripts/docker/compile_www_assets.sh; \ fi; \ + if [[ ${INSTALL_FROM_DOCKER_CONTEXT_FILES} == "true" ]]; then \ + bash /scripts/docker/install_from_docker_context_files.sh; \ + elif [[ ${INSTALL_FROM_PYPI} == "true" ]]; then \ + bash /scripts/docker/install_airflow.sh; \ + fi; \ if [[ -n "${ADDITIONAL_PYTHON_DEPS}" ]]; then \ bash /scripts/docker/install_additional_dependencies.sh; \ fi; \ diff --git a/scripts/docker/compile_www_assets.sh b/scripts/docker/compile_www_assets.sh index 01c54702e8a73..59a7017fd157f 100755 --- a/scripts/docker/compile_www_assets.sh +++ b/scripts/docker/compile_www_assets.sh @@ -28,7 +28,12 @@ function compile_www_assets() { md5sum_file="static/dist/sum.md5" readonly md5sum_file local www_dir - www_dir="$(python -m site --user-site)/airflow/www" + if [[ ${AIRFLOW_INSTALLATION_METHOD=} == "." ]]; then + # In case we are building from sources in production image, we should build the assets + www_dir="${AIRFLOW_SOURCES_TO}/airflow/www" + else + www_dir="$(python -m site --user-site)/airflow/www" + fi pushd ${www_dir} || exit 1 yarn install --frozen-lockfile --no-cache yarn run prod