diff --git a/dev/breeze/src/airflow_breeze/params/shell_params.py b/dev/breeze/src/airflow_breeze/params/shell_params.py index 1fff8ad1e045c..88dc6b9e301f6 100644 --- a/dev/breeze/src/airflow_breeze/params/shell_params.py +++ b/dev/breeze/src/airflow_breeze/params/shell_params.py @@ -595,6 +595,13 @@ def postgres_driver(self) -> str: return "psycopg2" return "psycopg" + @property + def postgres_data_volume_path(self) -> str: + """The ``VOLUME`` the postgres image declares; it moved from ``data/`` to its parent in 18.""" + if self.backend == "postgres" and int(self.postgres_version) >= 18: + return "/var/lib/postgresql" + return "/var/lib/postgresql/data" + @property def env_variables_for_docker_commands(self) -> dict[str, str]: """ @@ -718,6 +725,7 @@ def env_variables_for_docker_commands(self) -> dict[str, str]: _set_var(_env, "NUM_RUNS", self.num_runs) _set_var(_env, "ONLY_MIN_VERSION_UPDATE", self.only_min_version_update) _set_var(_env, "DISTRIBUTION_FORMAT", self.distribution_format) + _set_var(_env, "POSTGRES_DATA_VOLUME_PATH", self.postgres_data_volume_path) _set_var(_env, "POSTGRES_DRIVER", self.postgres_driver) _set_var(_env, "POSTGRES_HOST_PORT", None, POSTGRES_HOST_PORT) _set_var(_env, "POSTGRES_VERSION", self.postgres_version) diff --git a/dev/breeze/tests/test_shell_params.py b/dev/breeze/tests/test_shell_params.py index ec50a8d638042..6eb5e89e51738 100644 --- a/dev/breeze/tests/test_shell_params.py +++ b/dev/breeze/tests/test_shell_params.py @@ -266,6 +266,24 @@ def test_worktree_label_path_is_derived_from_checkout(tmp_path, monkeypatch, lin {"POSTGRES_DRIVER": "psycopg"}, id="POSTGRES_DRIVER stays psycopg when installing from a GitHub branch", ), + pytest.param( + {}, + {"backend": "postgres", "postgres_version": "17"}, + {"POSTGRES_DATA_VOLUME_PATH": "/var/lib/postgresql/data"}, + id="POSTGRES_DATA_VOLUME_PATH is the data directory up to Postgres 17", + ), + pytest.param( + {}, + {"backend": "postgres", "postgres_version": "18"}, + {"POSTGRES_DATA_VOLUME_PATH": "/var/lib/postgresql"}, + id="POSTGRES_DATA_VOLUME_PATH is its parent from Postgres 18", + ), + pytest.param( + {}, + {"backend": "none", "postgres_version": ""}, + {"POSTGRES_DATA_VOLUME_PATH": "/var/lib/postgresql/data"}, + id="POSTGRES_DATA_VOLUME_PATH ignores the empty version of non-postgres backends", + ), ], ) def test_shell_params_to_env_var_conversion( @@ -318,6 +336,16 @@ def test_pythonwarnings_is_forwarded_by_the_compose_base_file(): assert "PYTHONWARNINGS" in base_compose_file["services"]["airflow"]["environment"] +def test_postgres_data_volume_is_mounted_at_the_image_volume_path(): + backend_compose_file = yaml.safe_load( + (SCRIPTS_CI_DOCKER_COMPOSE_PATH / "backend-postgres.yml").read_text() + ) + assert ( + "postgres-data-volume:${POSTGRES_DATA_VOLUME_PATH:-/var/lib/postgresql/data}" + in backend_compose_file["services"]["postgres"]["volumes"] + ) + + @pytest.mark.parametrize( ("include_pycache_volume", "expected_prefix", "expected_dont_write"), [(True, PYCACHE_PREFIX_IN_CONTAINER, ""), (False, "", "true")], diff --git a/scripts/ci/docker-compose/backend-postgres.yml b/scripts/ci/docker-compose/backend-postgres.yml index ef6405862631c..8801c4d349d29 100644 --- a/scripts/ci/docker-compose/backend-postgres.yml +++ b/scripts/ci/docker-compose/backend-postgres.yml @@ -36,7 +36,7 @@ services: - POSTGRES_DB=airflow - POSTGRES_HOST_AUTH_METHOD=password volumes: - - postgres-data-volume:/var/lib/postgresql/{$POSTGRES_VERSION}/docker + - postgres-data-volume:${POSTGRES_DATA_VOLUME_PATH:-/var/lib/postgresql/data} healthcheck: test: ["CMD", "psql", "-h", "localhost", "-U", "postgres", "-c", "select 1", "airflow"] interval: 10s