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 2022/07/27 21:00:20 UTC
[airflow] branch main updated: Add possibility to specify command to run at Breeze entry via env var (#25288)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 7e295b7d99 Add possibility to specify command to run at Breeze entry via env var (#25288)
7e295b7d99 is described below
commit 7e295b7d992f4ed13911e593f15fd18e0d4c16f6
Author: Jarek Potiuk <ja...@polidea.com>
AuthorDate: Wed Jul 27 23:00:12 2022 +0200
Add possibility to specify command to run at Breeze entry via env var (#25288)
Breeze environment can be easily customized by specifying your own
init.sh file in files/airflow-breeze-config/init.sh. However, there
are certain scenarios (for example GitHub Codespaces), where you cannot
do that, but you can easily specify an environment variable to set
when you enter Breeze container - and you need to customize your
environment there, becasue you need to make your airflow code
re-linked from Github default "/workspace/airflow" to "/opt/airflow").
In such case it is much more convenient to provide the command to run
via environment variable and eval the command at entering the image.
This PR implements such a possibility.
---
BREEZE.rst | 6 ++++++
dev/breeze/src/airflow_breeze/global_constants.py | 1 +
dev/breeze/src/airflow_breeze/utils/docker_command_utils.py | 1 +
scripts/ci/docker-compose/_docker.env | 1 +
scripts/ci/docker-compose/base.yml | 1 +
scripts/ci/docker-compose/devcontainer.env | 1 +
scripts/in_container/run_init_script.sh | 4 ++++
7 files changed, 15 insertions(+)
diff --git a/BREEZE.rst b/BREEZE.rst
index 8ad8ba5c50..2cecbe827e 100644
--- a/BREEZE.rst
+++ b/BREEZE.rst
@@ -335,6 +335,12 @@ You can also add ``files/airflow-breeze-config/init.sh`` and the script will be
when you enter Breeze. For example you can add ``pip install`` commands if you want to install
custom dependencies - but there are no limits to add your own customizations.
+You can override the name of the init script by setting ``INIT_SCRIPT_FILE`` environment variable before
+running the breeze environment.
+
+You can also customize your environment by setting ``BREEZE_INIT_COMMAND`` environment variable. This variable
+will be evaluated at entering the environment.
+
The ``files`` folder from your local sources is automatically mounted to the container under
``/files`` path and you can put there any files you want to make available for the Breeze container.
diff --git a/dev/breeze/src/airflow_breeze/global_constants.py b/dev/breeze/src/airflow_breeze/global_constants.py
index dba556b331..5426c96281 100644
--- a/dev/breeze/src/airflow_breeze/global_constants.py
+++ b/dev/breeze/src/airflow_breeze/global_constants.py
@@ -184,6 +184,7 @@ LOAD_DEFAULT_CONNECTIONS = False
PRESERVE_VOLUMES = False
CLEANUP_CONTEXT = False
INIT_SCRIPT_FILE = ""
+BREEZE_INIT_COMMAND = ""
DRY_RUN_DOCKER = False
INSTALL_AIRFLOW_VERSION = ""
SQLITE_URL = "sqlite:////root/airflow/airflow.db"
diff --git a/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py b/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
index 99d98268b2..5f0de41fbc 100644
--- a/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
+++ b/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
@@ -550,6 +550,7 @@ def update_expected_environment_variables(env: Dict[str, str]) -> None:
set_value_to_default_if_not_set(env, 'AIRFLOW_EXTRAS', "")
set_value_to_default_if_not_set(env, 'ANSWER', "")
set_value_to_default_if_not_set(env, 'BREEZE', "true")
+ set_value_to_default_if_not_set(env, 'BREEZE_INIT_COMMAND', "")
set_value_to_default_if_not_set(env, 'CI', "false")
set_value_to_default_if_not_set(env, 'CI_BUILD_ID', "0")
set_value_to_default_if_not_set(env, 'CI_EVENT_TYPE', "pull_request")
diff --git a/scripts/ci/docker-compose/_docker.env b/scripts/ci/docker-compose/_docker.env
index b33cfea360..97fbe8e288 100644
--- a/scripts/ci/docker-compose/_docker.env
+++ b/scripts/ci/docker-compose/_docker.env
@@ -20,6 +20,7 @@ AIRFLOW_CONSTRAINTS_REFERENCE
ANSWER
BACKEND
BREEZE
+BREEZE_INIT_COMMAND
CI
CI_BUILD_ID
CI_JOB_ID
diff --git a/scripts/ci/docker-compose/base.yml b/scripts/ci/docker-compose/base.yml
index c1285eda88..156b4061b5 100644
--- a/scripts/ci/docker-compose/base.yml
+++ b/scripts/ci/docker-compose/base.yml
@@ -33,6 +33,7 @@ services:
- ANSWER=${ANSWER}
- BACKEND=${BACKEND}
- BREEZE=${BREEZE}
+ - BREEZE_INIT_COMMAND=${BREEZE_INIT_COMMAND}
- CI=${CI}
- CI_BUILD_ID=${CI_BUILD_ID}
- CI_JOB_ID=${CI_JOB_ID}
diff --git a/scripts/ci/docker-compose/devcontainer.env b/scripts/ci/docker-compose/devcontainer.env
index ae51b20443..6bd92ba203 100644
--- a/scripts/ci/docker-compose/devcontainer.env
+++ b/scripts/ci/docker-compose/devcontainer.env
@@ -20,6 +20,7 @@ ANSWER=
PYTHON_MAJOR_MINOR_VERSION="3.7"
AIRFLOW_EXTRAS=
BREEZE="true"
+BREEZE_INIT_COMMAND=""
CI="false"
CI_BUILD_ID=
CI_JOB_ID=
diff --git a/scripts/in_container/run_init_script.sh b/scripts/in_container/run_init_script.sh
index 48f7716f7c..125f192bb2 100755
--- a/scripts/in_container/run_init_script.sh
+++ b/scripts/in_container/run_init_script.sh
@@ -38,3 +38,7 @@ if [[ -d "${AIRFLOW_BREEZE_CONFIG_DIR}" && \
source "${INIT_SCRIPT_FILE}"
popd >/dev/null 2>&1 || exit 1
fi
+
+if [[ "${BREEZE_INIT_COMMAND=}" != "" ]]; then
+ eval "${BREEZE_INIT_COMMAND}"
+fi