diff --git a/scripts/saltbox_docker_controller.py b/scripts/saltbox_docker_controller.py index 7d1ee2bf63..5f544408ce 100644 --- a/scripts/saltbox_docker_controller.py +++ b/scripts/saltbox_docker_controller.py @@ -296,19 +296,28 @@ def stop_containers_in_dependency_order(graph: DependencyGraph): @asynccontextmanager async def lifespan(app: FastAPI): global app_ready - try: - # Initialization - client = docker.from_env() - docker_version = client.version() - logging.info(f"Using Docker version: {docker_version['Components'][0]['Version']}") - - # Initialize DependencyGraph - global graph # Declare graph as global if it's used elsewhere outside this context - graph = DependencyGraph() - app_ready = True # Indicate that the app is now ready + retry_attempts = 10 + retry_delay = 5 - except Exception as e: - logging.error(f"An error occurred during application initialization: {e}") + for attempt in range(1, retry_attempts + 1): + try: + client = docker.from_env() + docker_version = client.version() + logging.info(f"Using Docker version: {docker_version['Components'][0]['Version']}") + + # Initialize DependencyGraph + global graph # Declare graph as global if it's used elsewhere outside this context + graph = DependencyGraph() + app_ready = True # Indicate that the app is now ready + break # Exit the loop if successful + + except Exception as e: + logging.error(f"Attempt {attempt} - An error occurred during Docker initialization: {e}") + if attempt < retry_attempts: + await asyncio.sleep(retry_delay) + else: + logging.critical("Failed to initialize Docker after multiple attempts. Exiting.") + raise SystemExit("Failed to initialize Docker. Exiting.") yield logging.info("Application shutdown complete") diff --git a/scripts/saltbox_docker_controller_requirements.txt b/scripts/saltbox_docker_controller_requirements.txt index 08881708dc..eaa6c73626 100644 --- a/scripts/saltbox_docker_controller_requirements.txt +++ b/scripts/saltbox_docker_controller_requirements.txt @@ -1,3 +1,4 @@ -docker~=7.0.0 -uvicorn~=0.25.0 -fastapi~=0.108.0 +docker==7.0.0 +uvicorn==0.29.0 +fastapi==0.111.0 +requests==2.31.0