@@ -4,6 +4,7 @@ import os
44import shutil
55{% - if dockerfile %}
66import sys
7+ import time
78from contextlib import contextmanager
89{% - endif %}
910from pathlib import Path
@@ -98,22 +99,6 @@ def _is_interactive() -> bool:
9899 return sys.stdin.isatty() and os.environ.get("CI", "").lower() != "true"
99100
100101
101- def _wait_for_dev_containers_start(ctx: Context) -> None:
102- """Start the dev containers and wait until they are fully up.
103-
104- This function triggers the `docker_start` duty with the `dev` profile,
105- then continuously checks the containers status until `{{ project_name }}-dev`
106- is running.
107- """
108- docker_start.run(env="dev")
109- while True:
110- output = ctx.run(
111- ["docker", "compose", "top"], silent=True, allow_overrides=False, capture=True
112- )
113- if "{{ project_name }}-dev" in output:
114- break
115-
116-
117102@contextmanager
118103def _setup_container(ctx: Context) -> Iterator[None]:
119104 """Ensure the dev Docker container is running for the duration of a context block.
@@ -129,13 +114,13 @@ def _setup_container(ctx: Context) -> Iterator[None]:
129114 )
130115 if build_docker_images:
131116 docker_build.run(env="dev")
132- _wait_for_dev_containers_start(ctx )
117+ docker_start.run(env="dev" )
133118 else:
134119 output = ctx.run(
135120 ["docker", "compose", "top"], silent=True, allow_overrides=False, capture=True
136121 )
137122 if "{{ project_name }}-dev" not in output:
138- _wait_for_dev_containers_start(ctx )
123+ docker_start.run(env="dev" )
139124 try:
140125 yield
141126 finally:
@@ -309,6 +294,14 @@ def docker_start(ctx: Context, env: str | None = None) -> None:
309294 ctx.run(
310295 ["docker", "compose", "--profile", "prod", "up", "-d"], title="Starting prod containers"
311296 )
297+ while True:
298+ output = ctx.run(
299+ ["docker", "compose", "top"], silent=True, allow_overrides=False, capture=True
300+ )
301+ service = "{{ project_name }}" if env == "prod" else "{{ project_name }}-dev"
302+ if service in output:
303+ break
304+ time.sleep(0.5)
312305
313306
314307@duty(
0 commit comments