Module 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.

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: Request body

{ "container_id": "uuid" }

Returns

200 - Success with container details

Returns

400 - Missing container_id

Returns

401 - Missing authorization header

Returns

404 - Container not found or access denied

Returns

500 - Internal server error