digital-identity-platform-docs
digital-identity-platform-docs / supabase/functions/deprovision_container
supabase/functions/deprovision_container
Fileoverview
Deprovision Container Edge Function
Handles the complete deletion of an SGTM container and all associated resources including infrastructure, custom domains, sites, and data.
Cloudflare Architecture Context
| Attribute | Value |
|---|---|
| Classification | 🔵 BACKEND-ONLY |
| Position | App Backend (cleanup orchestration) |
| Receives Public Traffic | No (dashboard only) |
| Latency Sensitive | No |
| Safe to Retry | Partial (some steps are idempotent) |
| Failure Behavior | Best-effort cleanup, continues on errors |
KV Cleanup: This function calls sync-edge-config with DELETE operation to remove:
- EDGE_CONFIG entries
- LOADER_TOKEN_MAP entries
- SITE_REGISTRY entries
Note: ROUTING_MAP cleanup is handled by the infra-provisioner.
Endpoint
POST /deprovision_container
Auth
Required - JWT in Authorization header
Remarks
This is a destructive operation that performs the following cleanup steps:
- Fetch and delete all custom domains (with Caddy vhost removal)
- Call infrastructure provisioner to deprovision container infrastructure
- Release allocated ports back to the port_pool
- Delete container subscription
- Delete associated sites
- Delete associated site_domains
- Delete access logs (required before container deletion due to FK)
- Delete usage daily records
- Delete the container record itself
Tables touched:
- sgtm_containers (read/delete)
- custom_domains (read/delete)
- sgtm_container_subscriptions (delete)
- sites (delete)
- site_domains (delete)
- sgtm_access_logs (delete)
- sgtm_usage_daily (delete)
- port_pool (update - release ports)
External services:
- Infrastructure Provisioner (INFRA_PROVISIONER_URL) for Caddy cleanup
Example
json
{ "container_id": "uuid" }