Skip to content

Commit

Permalink
Merge branch 'issue-490' of https://github.com/kashyab12/python-on-wh…
Browse files Browse the repository at this point in the history
…ales into issue-490
  • Loading branch information
kashyab12 committed Nov 4, 2023
2 parents 513d32a + f41ada7 commit 495cec5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
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
1 change: 1 addition & 0 deletions python_on_whales/components/context/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,4 @@ def use(self, context: ValidContext):
"""
full_cmd = self.docker_cmd + ["context", "use", context]
run(full_cmd)
return self.inspect(context)
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
4 changes: 4 additions & 0 deletions tests/python_on_whales/components/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def test_use_context():
docker.context.use("default")


def test_use_context_returns():
assert docker.context.use("default") == docker.context.inspect("default")


def test_remove_empty_context_list():
all_contexts = set(docker.context.list())
docker.context.remove([])
Expand Down

0 comments on commit 495cec5

Please sign in to comment.