// apps/cli/src/templates/cloudrun.ts

/** Generate a cloudbuild.yaml for Google Cloud Run */
export const cloudRunYamlTemplate = (
  agentName: string,
  projectId: string = "YOUR_PROJECT_ID",
  region: string = "us-central1",
) => `# Google Cloud Build + Cloud Run — raxd agent
# Generated by: rax deploy up --target cloudrun
# Docs: https://cloud.google.com/run/docs
#
# Deploy manually:
#   gcloud run deploy raxd-${agentName} \\
#     --source . \\
#     --region ${region} \\
#     --allow-unauthenticated \\
#     --set-env-vars PORT=3000

steps:
  - name: "gcr.io/cloud-builders/docker"
    args:
      - "build"
      - "-t"
      - "gcr.io/${projectId}/raxd-${agentName}"
      - "."

  - name: "gcr.io/cloud-builders/docker"
    args:
      - "push"
      - "gcr.io/${projectId}/raxd-${agentName}"

  - name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
    entrypoint: gcloud
    args:
      - "run"
      - "deploy"
      - "raxd-${agentName}"
      - "--image"
      - "gcr.io/${projectId}/raxd-${agentName}"
      - "--region"
      - "${region}"
      - "--platform"
      - "managed"
      - "--port"
      - "3000"
      - "--memory"
      - "512Mi"
      - "--timeout"
      - "300"
      - "--allow-unauthenticated"

images:
  - "gcr.io/${projectId}/raxd-${agentName}"
`;

/** Simpler gcloud deploy command reference */
export const cloudRunDeployNote = (
  agentName: string,
  region: string = "us-central1",
) => `# Quick deploy to Cloud Run (without Cloud Build):
#
#   gcloud run deploy raxd-${agentName} \\
#     --source . \\
#     --region ${region} \\
#     --allow-unauthenticated \\
#     --set-env-vars PORT=3000,LLM_PROVIDER=anthropic \\
#     --set-secrets ANTHROPIC_API_KEY=anthropic-key:latest
#
# Cloud Run auto-detects the Dockerfile in your project directory.
# Use Secret Manager for API keys:
#   gcloud secrets create anthropic-key --data-file=- <<< "sk-ant-..."
`;
