Skip to content

Commit d9bd61a

Browse files
authored
Allow to pull images before compose start (#73)
1 parent da691bd commit d9bd61a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

docs/compose.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Code
3030

3131
::
3232

33-
compose = DockerCompose("/home/project")
33+
compose = DockerCompose("/home/project", pull=True)
3434
with compose:
3535
host = compose.get_service_host("hub", 4444)
3636
port = compose.get_service_port("hub", 4444)

testcontainers/compose.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88

99

1010
class DockerCompose(object):
11-
def __init__(self, filepath, compose_file_name="docker-compose.yml"):
11+
def __init__(
12+
self,
13+
filepath,
14+
compose_file_name="docker-compose.yml",
15+
pull=False):
1216
self.filepath = filepath
1317
self.compose_file_name = compose_file_name
18+
self.pull = pull
1419

1520
def __enter__(self):
1621
self.start()
@@ -21,6 +26,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
2126

2227
def start(self):
2328
with blindspin.spinner():
29+
if self.pull:
30+
subprocess.call(["docker-compose", "-f", self.compose_file_name, "pull"],
31+
cwd=self.filepath)
2432
subprocess.call(["docker-compose", "-f", self.compose_file_name, "up", "-d"],
2533
cwd=self.filepath)
2634

tests/test_docker_compose.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ def test_can_spawn_service_via_compose():
1313
assert port == "4444"
1414

1515

16+
def test_can_pull_images_before_spawning_service_via_compose():
17+
with DockerCompose("tests", pull=True) as compose:
18+
host = compose.get_service_host("hub", 4444)
19+
port = compose.get_service_port("hub", 4444)
20+
assert host == "0.0.0.0"
21+
assert port == "4444"
22+
23+
1624
def test_can_throw_exception_if_no_port_exposed():
1725
with DockerCompose("tests") as compose:
1826
with pytest.raises(NoSuchPortExposed):

0 commit comments

Comments
 (0)