Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds support for --renew-anon-volumes #487

Merged
merged 4 commits into from
Nov 2, 2023
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
4 changes: 4 additions & 0 deletions python_on_whales/components/compose/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ def up(
recreate: bool = True,
no_build: bool = False,
remove_orphans: bool = False,
renew_anon_volumes: bool = False,
color: bool = True,
log_prefix: bool = True,
start: bool = True,
Expand Down Expand Up @@ -704,6 +705,8 @@ def up(
`recreate=False` and `force_recreate=True` are incompatible.
no_build: Don't build an image, even if it's missing.
remove_orphans: Remove containers for services not defined in the Compose file.
renew_anon_volumes: Recreate anonymous volumes instead of retrieving
data from the previous containers.
color: If `False`, it will produce monochrome output.
log_prefix: If `False`, will not display the prefix in the logs.
start: Start the service after creating them.
Expand Down Expand Up @@ -733,6 +736,7 @@ def up(
full_cmd.add_flag("--no-log-prefix", not log_prefix)
full_cmd.add_flag("--no-start", not start)
full_cmd.add_flag("--remove-orphans", remove_orphans)
full_cmd.add_flag("--renew-anon-volumes", renew_anon_volumes)
full_cmd.add_simple_arg("--pull", pull)

if no_attach_services is not None:
Expand Down
8 changes: 8 additions & 0 deletions tests/python_on_whales/components/compose_anon_volumes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.9"

services:
busybox:
image: busybox:latest
command: sleep infinity
volumes:
- /hello-volume
36 changes: 36 additions & 0 deletions tests/python_on_whales/components/test_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,42 @@ def test_compose_multiple_profiles():
docker.compose.down(timeout=1)


def test_compose_anon_volumes_recreate_not_enabled():
docker = DockerClient(
compose_files=[
PROJECT_ROOT / "tests/python_on_whales/components/compose_anon_volumes.yml"
],
)
docker.compose.up(detach=True)

volume_name_before_recreate = docker.compose.ps()[0].mounts[0].name

docker.compose.up(detach=True, force_recreate=True)
volumes_name_after_recreate = docker.compose.ps()[0].mounts[0].name

assert volume_name_before_recreate == volumes_name_after_recreate

docker.compose.down(timeout=1)


def test_compose_anon_volumes_recreate_enabled():
docker = DockerClient(
compose_files=[
PROJECT_ROOT / "tests/python_on_whales/components/compose_anon_volumes.yml"
],
)
docker.compose.up(detach=True)

volume_name_before_recreate = docker.compose.ps()[0].mounts[0].name

docker.compose.up(detach=True, force_recreate=True, renew_anon_volumes=True)
volumes_name_after_recreate = docker.compose.ps()[0].mounts[0].name

assert volume_name_before_recreate != volumes_name_after_recreate

docker.compose.down(timeout=1)


def test_compose_port():
d = DockerClient(
compose_files=[
Expand Down
Loading