You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2025/09/15 21:20:52 UTC

(airflow) 01/02: fix(docker/entrypoint_prod.sh): prevent the script from code 2 after db migrate success (#52928)

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

kaxilnaik pushed a commit to branch v3-1-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 3c4af224c7d5be20f8e6bf3adeae6dd45f14aac1
Author: Creative Ataraxia <10...@users.noreply.github.com>
AuthorDate: Tue Sep 16 03:20:11 2025 +0800

    fix(docker/entrypoint_prod.sh): prevent the script from code 2 after db migrate success (#52928)
    
    * fix(docker): prevent airflow-init from failing after db migrate where no command is passed-in
    
    * docs(docker-stack-docs/entrypoint.rst): container clean exit behavior with _AIRFLOW_DB_MIGRATE and no command
    
    * chore: update inlined Dockerfile after entrypoint.sh script change
    
    ---------
    
    Co-authored-by: Roy M. <ro...@gmail.com>
    (cherry picked from commit 90f9c7026a8ca41a238125fdc7adaa1e49d189de)
---
 Dockerfile                        | 5 +++++
 docker-stack-docs/entrypoint.rst  | 9 ++++++---
 scripts/docker/entrypoint_prod.sh | 6 ++++++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 1b6d02a68e8..113bed816e7 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1619,6 +1619,11 @@ if [[ ${AIRFLOW_COMMAND} =~ ^(scheduler|celery)$ ]] \
     wait_for_celery_broker
 fi
 
+if [[ "$#" -eq 0 && "${_AIRFLOW_DB_MIGRATE}" == "true" ]]; then
+    echo "[INFO] No commands passed and _AIRFLOW_DB_MIGRATE=true. Exiting script with code 0."
+    exit 0
+fi
+
 exec "airflow" "${@}"
 EOF
 
diff --git a/docker-stack-docs/entrypoint.rst b/docker-stack-docs/entrypoint.rst
index bcfde3e7053..a1d6e894cde 100644
--- a/docker-stack-docs/entrypoint.rst
+++ b/docker-stack-docs/entrypoint.rst
@@ -318,9 +318,12 @@ Upgrading Airflow DB
 If you set :envvar:`_AIRFLOW_DB_MIGRATE` variable to a non-empty value, the entrypoint will run
 the ``airflow db migrate`` command right after verifying the connection. You can also use this
 when you are running Airflow with internal SQLite database (default) to upgrade the db and create
-admin users at entrypoint, so that you can start the webserver immediately. Note - using SQLite is
-intended only for testing purpose, never use SQLite in production as it has severe limitations when it
-comes to concurrency.
+admin users at entrypoint, so that you can start the webserver immediately. If no command is
+provided to the container and :envvar:`_AIRFLOW_DB_MIGRATE` is set, the container will exit
+cleanly after completing the database migration. This allows one-off init containers
+(such as ``airflow-init``) to perform setup without requiring a placeholder command to suppress
+CLI errors. Note - using SQLite is intended only for testing purpose, never use SQLite in
+production as it has severe limitations when it comes to concurrency.
 
 Creating admin user
 ...................
diff --git a/scripts/docker/entrypoint_prod.sh b/scripts/docker/entrypoint_prod.sh
index cd7a600641f..88135c145c1 100755
--- a/scripts/docker/entrypoint_prod.sh
+++ b/scripts/docker/entrypoint_prod.sh
@@ -337,4 +337,10 @@ if [[ ${AIRFLOW_COMMAND} =~ ^(scheduler|celery)$ ]] \
     wait_for_celery_broker
 fi
 
+# Exit cleanly if the init was only intended to migrate DB
+if [[ "$#" -eq 0 && "${_AIRFLOW_DB_MIGRATE}" == "true" ]]; then
+    echo "[INFO] No commands passed and _AIRFLOW_DB_MIGRATE=true. Exiting script with code 0."
+    exit 0
+fi
+
 exec "airflow" "${@}"