CTF API Frontend (FastAPI)

This API allows you to deploy and redeploy Capture The Flag (CTF) instances to Google Cloud Run.

Interactive API Documentation

Visit /docs for Swagger UI or /redoc for ReDoc documentation.

Endpoints

POST /deploy

Deploy a new CTF instance with custom questions.

Request Body:

{
  "service_name": "my-ctf-game",
  "project_id": "my-gcp-project",
  "region": "us-central1",
  "questions": [
    {
      "question": "What is 2+2?",
      "choices": ["3", "4", "5"],
      "answer": "4"
    }
  ],
  "tec_analytics_endpoint": "https://analytics.example.com"
}

POST /redeploy

Redeploy an existing CTF instance using data stored in Cloud Storage FUSE mount.

Request Body:

{
  "service_name": "my-ctf-game",
  "project_id": "my-gcp-project",
  "region": "us-central1",
  "tec_analytics_endpoint": "https://analytics.example.com"
}

Behavior: Rebuilds and redeploys the container. Database persists in Cloud Storage at gs://ctf-quiz-storage/{QUIZ_ID}/ctf_data.db via FUSE mount.

POST /destroy

Destroy a Cloud Run quiz instance while preserving database for future redeployment.

Request Body:

{
  "service_name": "my-ctf-game",
  "project_id": "my-gcp-project",
  "region": "us-central1",
  "preserve_data": true
}

Behavior: Deletes Cloud Run service. If preserve_data=true (default), database remains in Cloud Storage and can be reused on redeploy.

GET /status/{deployment_id}

Check the status of a deployment or redeploy operation.

GET /deployments

List all quizzes and their deployment history. Shows quiz_id, current status, service URLs, and deployment counts.

Example Redeploy Usage

curl -X POST http://localhost:8000/redeploy   -H "Content-Type: application/json"   -d '{
    "service_name": "my-ctf-game",
    "project_id": "my-gcp-project",
    "region": "us-central1",
    "tec_analytics_endpoint": "https://analytics.example.com"
  }'