Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dev/breeze/src/airflow_breeze/params/shell_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions dev/breeze/tests/test_shell_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")],
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/docker-compose/backend-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Comment thread
Andrushika marked this conversation as resolved.
healthcheck:
test: ["CMD", "psql", "-h", "localhost", "-U", "postgres", "-c", "select 1", "airflow"]
interval: 10s
Expand Down
Loading