MCPcopy Create free account
hub / github.com/hunvreus/devpush / update_traefik_config

Method update_traefik_config

app/services/deployment.py:250–389  ·  view source on GitHub ↗

Update Traefik config for a project including domains.

(
        self,
        project: Project,
        db: AsyncSession,
        settings: Settings,
        *,
        include_deployment_ids: set[str] | None = None,
    )

Source from the content-addressed store, hash-verified

248 logger.error("Failed to setup environment id alias: %s", exc)
249
250 async def update_traefik_config(
251 self,
252 project: Project,
253 db: AsyncSession,
254 settings: Settings,
255 *,
256 include_deployment_ids: set[str] | None = None,
257 ) -> None:
258 """Update Traefik config for a project including domains."""
259 path = os.path.join(settings.traefik_dir, f"project_{project.id}.yml")
260
261 # Get aliases
262 include_ids = include_deployment_ids or set()
263 if include_ids:
264 where_clause = or_(
265 Deployment.conclusion == "succeeded",
266 Deployment.id.in_(list(include_ids)),
267 )
268 else:
269 where_clause = Deployment.conclusion == "succeeded"
270
271 result = await db.execute(
272 select(Alias)
273 .join(Deployment, Alias.deployment_id == Deployment.id)
274 .filter(
275 Deployment.project_id == project.id,
276 where_clause,
277 )
278 )
279 aliases = result.scalars().all()
280
281 # Get active domains
282 domains_result = await db.execute(
283 select(Domain).where(
284 Domain.project_id == project.id, Domain.status == "active"
285 )
286 )
287 domains = domains_result.scalars().all()
288
289 # Remove config if no aliases or domains
290 if not aliases and not domains and os.path.exists(path):
291 os.remove(path)
292 return
293
294 routers = {}
295 services = {}
296 middlewares = {}
297
298 # Aliases
299 for a in aliases:
300 router_config = {
301 "rule": f"Host(`{a.subdomain}.{settings.deploy_domain}`)",
302 "service": f"deployment-{a.deployment_id}@docker",
303 "entryPoints": ["web", "websecure"]
304 if settings.url_scheme == "https"
305 else ["web"],
306 }
307 if settings.url_scheme == "https":

Callers 3

rollbackMethod · 0.95
project_settingsFunction · 0.95
finalize_deploymentFunction · 0.80

Calls 2

setFunction · 0.85
nextFunction · 0.85

Tested by

no test coverage detected