add sandbox network auto-create and restore dind compose
This commit is contained in:
parent
43bd4bcbff
commit
06271db003
4 changed files with 65 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import asyncio
|
||||
from collections.abc import Awaitable, Callable
|
||||
|
||||
from docker.errors import NotFound
|
||||
from fastapi import FastAPI
|
||||
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
||||
|
||||
|
|
@ -47,6 +48,19 @@ def create_app(config: AppConfig | None = None) -> FastAPI:
|
|||
raise
|
||||
|
||||
|
||||
def _ensure_sandbox_network(container: AppContainer) -> None:
|
||||
client = container._docker_client
|
||||
network_name = container.config.sandbox.network_name
|
||||
try:
|
||||
client.networks.get(network_name)
|
||||
except NotFound:
|
||||
client.networks.create(network_name)
|
||||
container.observability.logger.info(
|
||||
'sandbox_network_created',
|
||||
attrs={'network': network_name},
|
||||
)
|
||||
|
||||
|
||||
def _build_startup_handler(
|
||||
app: FastAPI,
|
||||
container: AppContainer,
|
||||
|
|
@ -56,6 +70,7 @@ def _build_startup_handler(
|
|||
if task is not None and not task.done():
|
||||
return
|
||||
|
||||
await asyncio.to_thread(_ensure_sandbox_network, container)
|
||||
await asyncio.to_thread(container.sandbox_reconciler.execute)
|
||||
|
||||
stop_event = asyncio.Event()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue