Build, (re)create, and start the named services. Delegates to `docker compose up`. See that command's help for details. Args: services: The names of services in the composition. detach: Run containers in the background. wait: Wait for health chec
(
self,
*services: str | Service,
detach: bool = True,
wait: bool = True,
max_tries: int = 8,
)
| 1209 | return False |
| 1210 | |
| 1211 | def up( |
| 1212 | self, |
| 1213 | *services: str | Service, |
| 1214 | detach: bool = True, |
| 1215 | wait: bool = True, |
| 1216 | max_tries: int = 8, |
| 1217 | ) -> None: |
| 1218 | """Build, (re)create, and start the named services. |
| 1219 | |
| 1220 | Delegates to `docker compose up`. See that command's help for details. |
| 1221 | |
| 1222 | Args: |
| 1223 | services: The names of services in the composition. |
| 1224 | detach: Run containers in the background. |
| 1225 | wait: Wait for health checks to complete before returning. |
| 1226 | Implies `detach` mode. |
| 1227 | max_tries: Number of tries on failure. |
| 1228 | """ |
| 1229 | idle = set( |
| 1230 | [ |
| 1231 | service.name |
| 1232 | for service in services |
| 1233 | if isinstance(service, Service) and service.idle |
| 1234 | ] |
| 1235 | ) |
| 1236 | old_compose = None |
| 1237 | if idle: |
| 1238 | old_compose = copy.deepcopy(self.compose) |
| 1239 | for service_name, service in self.compose["services"].items(): |
| 1240 | if service_name in idle: |
| 1241 | service["entrypoint"] = ["sleep", "infinity"] |
| 1242 | service["command"] = [] |
| 1243 | service.pop("depends_on", None) |
| 1244 | service.pop("healthcheck", None) |
| 1245 | self._invalidate_compose_files() |
| 1246 | |
| 1247 | service_names = [ |
| 1248 | service.name if isinstance(service, Service) else service |
| 1249 | for service in services |
| 1250 | ] |
| 1251 | |
| 1252 | try: |
| 1253 | self.capture_logs() |
| 1254 | self.invoke( |
| 1255 | "up", |
| 1256 | *(["--detach"] if detach else []), |
| 1257 | *(["--wait"] if wait else []), |
| 1258 | *(["--quiet-pull"] if ui.env_is_truthy("CI") else []), |
| 1259 | *service_names, |
| 1260 | max_tries=300 if os.getenv("CI_WAITING_FOR_BUILD") else max_tries, |
| 1261 | build=os.getenv("CI_WAITING_FOR_BUILD"), |
| 1262 | ) |
| 1263 | finally: |
| 1264 | # Restore even on failure: otherwise the next test in the same |
| 1265 | # composition would inherit the sleep-infinity entrypoint. |
| 1266 | if old_compose is not None: |
| 1267 | self.compose = old_compose # type: ignore |
| 1268 | self._invalidate_compose_files() |