Skip to content

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 ​

AttributeValue
Classification🔵 BACKEND-ONLY
PositionApp Backend (cleanup orchestration)
Receives Public TrafficNo (dashboard only)
Latency SensitiveNo
Safe to RetryPartial (some steps are idempotent)
Failure BehaviorBest-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:

  1. Fetch and delete all custom domains (with Caddy vhost removal)
  2. Call infrastructure provisioner to deprovision container infrastructure
  3. Release allocated ports back to the port_pool
  4. Delete container subscription
  5. Delete associated sites
  6. Delete associated site_domains
  7. Delete access logs (required before container deletion due to FK)
  8. Delete usage daily records
  9. 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" }

Interfaces ​

Released under proprietary license.