x
This commit is contained in:
+66
-63
@@ -6,6 +6,7 @@ import threading
|
||||
import traceback
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
|
||||
from secondary import SecondaryManager
|
||||
from utils import sigchld_handler
|
||||
from dotenv import load_dotenv
|
||||
|
||||
@@ -22,74 +23,75 @@ load_dotenv("local.env")
|
||||
load_dotenv('/run/secrets/brencher-secrets')
|
||||
|
||||
|
||||
def build_environments(cli_env_ids_str: str, dry_run: bool = False) -> Dict[str, Environment]:
|
||||
import configs.brencher
|
||||
import configs.brencher2
|
||||
import configs.brencher_local2
|
||||
import configs.brencher_local1
|
||||
import configs.torrserv_proxy
|
||||
import configs.immich
|
||||
import configs.registry
|
||||
import configs.gmail_mcp
|
||||
environments_l: List[Environment] = [
|
||||
configs.brencher.brencher,
|
||||
configs.brencher2.brencher2,
|
||||
configs.brencher_local2.brencher_local2,
|
||||
configs.brencher_local1.brencher_local1,
|
||||
configs.torrserv_proxy.torrserv_proxy,
|
||||
configs.immich.immich,
|
||||
configs.registry.registry,
|
||||
configs.gmail_mcp.gmail_mcp,
|
||||
]
|
||||
environments: Dict[str, Environment] = {e.id: e for e in environments_l}
|
||||
|
||||
logger.info(f"cli_env_ids {cli_env_ids_str}")
|
||||
if len(cli_env_ids_str) > 0 and cli_env_ids_str[0] == '-':
|
||||
cli_env_ids = cli_env_ids_str[1:].split(',')
|
||||
cli_env_ids = [x for x in cli_env_ids if len(x) > 0]
|
||||
logger.info(f"cli_env_ids (minus) {cli_env_ids}")
|
||||
if cli_env_ids and len(cli_env_ids) > 0:
|
||||
environments = {k: e for k, e in environments.items() if k not in cli_env_ids}
|
||||
else:
|
||||
cli_env_pairs = {x[0]: x[1] if len(x) > 1 else None for x in [x.split(":")
|
||||
for x in cli_env_ids_str.split(',')
|
||||
if len(x) > 0
|
||||
]
|
||||
}
|
||||
logger.info(f"cli_env_ids {cli_env_pairs}")
|
||||
if cli_env_pairs and len(cli_env_pairs) > 0:
|
||||
environments = {k: e for k, e in environments.items() if k in cli_env_pairs.keys()}
|
||||
for k, v in cli_env_pairs.items():
|
||||
if v is not None:
|
||||
if k in environments:
|
||||
env = environments[k]
|
||||
for step in env.pipeline:
|
||||
resolve_step = step
|
||||
if isinstance(step, CachingStep):
|
||||
resolve_step = step._step
|
||||
if isinstance(resolve_step, SharedStateHolder):
|
||||
resolve_step.set_branches([(v, 'HEAD')])
|
||||
logger.info(f"Overriding environment {k} branches to {(v, 'HEAD')}")
|
||||
else:
|
||||
logger.warning(f"Environment {k} not found to override branches")
|
||||
else:
|
||||
logger.info(f"No branch override for environment {k}")
|
||||
if dry_run:
|
||||
for e in environments.values():
|
||||
e.state.set_dry(True)
|
||||
|
||||
logger.info(f"Resulting profiles {environments.keys()}")
|
||||
|
||||
return environments
|
||||
|
||||
|
||||
class App:
|
||||
|
||||
def __init__(self, cli_env_ids_str: str, dry_run: bool = False) -> None:
|
||||
|
||||
self.environments: Dict[str, Environment] = {}
|
||||
def __init__(self, environments: Dict[str, Environment]) -> None:
|
||||
self.environments: Dict[str, Environment] = {id: wrap_in_cached(e) for id, e in environments.items()}
|
||||
self.state_lock = threading.Lock()
|
||||
self.environment_update_event = threading.Event()
|
||||
self.emit_callback: Optional[Callable[[], None]] = None
|
||||
|
||||
import configs.brencher
|
||||
import configs.brencher2
|
||||
import configs.brencher_local2
|
||||
import configs.brencher_local1
|
||||
import configs.torrserv_proxy
|
||||
import configs.immich
|
||||
import configs.registry
|
||||
import configs.gmail_mcp
|
||||
environments_l: List[Environment] = [
|
||||
configs.brencher.brencher,
|
||||
configs.brencher2.brencher2,
|
||||
configs.brencher_local2.brencher_local2,
|
||||
configs.brencher_local1.brencher_local1,
|
||||
configs.torrserv_proxy.torrserv_proxy,
|
||||
configs.immich.immich,
|
||||
configs.registry.registry,
|
||||
configs.gmail_mcp.gmail_mcp,
|
||||
]
|
||||
self.environments = {e.id: e for e in environments_l}
|
||||
|
||||
logger.info(f"cli_env_ids {cli_env_ids_str}")
|
||||
if len(cli_env_ids_str) > 0 and cli_env_ids_str[0] == '-':
|
||||
cli_env_ids = cli_env_ids_str[1:].split(',')
|
||||
cli_env_ids = [x for x in cli_env_ids if len(x) > 0]
|
||||
logger.info(f"cli_env_ids (minus) {cli_env_ids}")
|
||||
if cli_env_ids and len(cli_env_ids) > 0:
|
||||
self.environments = {k: e for k, e in self.environments.items() if k not in cli_env_ids}
|
||||
else:
|
||||
cli_env_pairs = {x[0]: x[1] if len(x) > 1 else None for x in [x.split(":")
|
||||
for x in cli_env_ids_str.split(',')
|
||||
if len(x) > 0
|
||||
]
|
||||
}
|
||||
logger.info(f"cli_env_ids {cli_env_pairs}")
|
||||
if cli_env_pairs and len(cli_env_pairs) > 0:
|
||||
self.environments = {k: e for k, e in self.environments.items() if k in cli_env_pairs.keys()}
|
||||
for k, v in cli_env_pairs.items():
|
||||
if v is not None:
|
||||
if k in self.environments:
|
||||
env = self.environments[k]
|
||||
for step in env.pipeline:
|
||||
resolve_step = step
|
||||
if isinstance(step, CachingStep):
|
||||
resolve_step = step._step
|
||||
if isinstance(resolve_step, SharedStateHolder):
|
||||
resolve_step.set_branches([(v, 'HEAD')])
|
||||
logger.info(f"Overriding environment {k} branches to {(v, 'HEAD')}")
|
||||
else:
|
||||
logger.warning(f"Environment {k} not found to override branches")
|
||||
else:
|
||||
logger.info(f"No branch override for environment {k}")
|
||||
if dry_run:
|
||||
for id, e in self.environments.items():
|
||||
e.state.set_dry(True)
|
||||
|
||||
logger.info(f"Resulting profiles {self.environments.keys()}")
|
||||
|
||||
self.environments = {id: wrap_in_cached(e) for id, e in self.environments.items()}
|
||||
|
||||
def get_local_envs_to_emit(self) -> Dict[str, Dict[str, Any]]:
|
||||
env_dtos: Dict[str, Dict[str, Any]] = {}
|
||||
for env in self.environments.values():
|
||||
@@ -186,7 +188,8 @@ if __name__ == '__main__':
|
||||
cli_env_ids_str = cli_env_ids_list[0]
|
||||
|
||||
signal.signal(signal.SIGCHLD, sigchld_handler)
|
||||
app1 = App(cli_env_ids_str, 'dry' in sys.argv[1:])
|
||||
environments = build_environments(cli_env_ids_str, 'dry' in sys.argv[1:])
|
||||
app1 = App(environments)
|
||||
|
||||
if 'noweb' in sys.argv[1:]:
|
||||
app1.runHeadless()
|
||||
|
||||
@@ -48,7 +48,6 @@ class WebApp:
|
||||
|
||||
self.ws_connections: Dict[WebSocket, Dict[str, Any]] = {}
|
||||
self._event_loop: Optional[asyncio.AbstractEventLoop] = None
|
||||
self.secondaryManager: Optional[SecondaryManager] = None
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(fastapi_app: FastAPI) -> AsyncIterator[None]:
|
||||
|
||||
@@ -8,6 +8,7 @@ import docker
|
||||
import pytest
|
||||
import requests
|
||||
from app import App
|
||||
from configs import brencher_local1
|
||||
from .conftest import EventuallyFn
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
@@ -34,7 +35,7 @@ class TestDockerContainer:
|
||||
async def test_start(self, eventually: EventuallyFn) -> None:
|
||||
logger.info(f"Starting")
|
||||
|
||||
app = App(cli_env_ids_str="brencher_local1")
|
||||
app = App({"brencher_local1": brencher_local1.brencher_local1})
|
||||
# app.runWeb(5001)
|
||||
processing = threading.Thread(target=lambda: app.runWeb(5001), daemon=True)
|
||||
processing.start()
|
||||
|
||||
@@ -8,6 +8,7 @@ import requests
|
||||
from playwright.sync_api import Page, sync_playwright
|
||||
from app import App
|
||||
from .conftest import EventuallyFn
|
||||
from configs import brencher_local1
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -42,7 +43,7 @@ class TestDryRunPlaywright:
|
||||
def test_dry_run_prevents_deploy_until_disabled(self, eventually: EventuallyFn) -> None:
|
||||
# Start app with brencher_local1 with main branch pre-selected.
|
||||
# App starts with dry=True by default (SharedStateHolderInMemory default).
|
||||
app = App(cli_env_ids_str=f"{ENV_ID}:main")
|
||||
app = App({"brencher_local1": brencher_local1.brencher_local1})
|
||||
server_thread = threading.Thread(target=lambda: app.runWeb(APP_PORT), daemon=True)
|
||||
server_thread.start()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user