Deploy: GCP

Deploy agents to Google Cloud Run using praisonai deploy

Deploy agents to Google Cloud Run using praisonai deploy run --type cloud --provider gcp.

Quick Start – CLI

  1. Install PraisonAI
    bash
    pip install praisonai
  2. Set Environment Variables
    bash
    export OPENAI_API_KEY="your-key"
    export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
  3. Initialize GCP Config
    bash
    praisonai deploy init --file agents.yaml --type cloud --provider gcp
  4. Check Readiness
    bash
    praisonai deploy doctor --provider gcp
  5. Deploy to GCP
    bash
    praisonai deploy run --file agents.yaml --type cloud --provider gcp

    Expected Output:

    🚀 Starting deployment...
    
    ☁️  Deploying to Google Cloud Run
      • Project: your-project-id
      • Region: us-central1
      • Service: praisonai-service
    
    📦 Building and pushing Docker image...
    🚀 Deploying to Cloud Run...
    
    ✅ Deployment successful!
    🔗 URL: https://praisonai-service-abc123-uc.a.run.app
    
    Metadata:
      • provider: gcp
      • project_id: your-project-id
      • region: us-central1
      • service: praisonai-service
  6. Verify
    bash
    curl https://praisonai-service-abc123-uc.a.run.app/health

Quick Start – SDK

  1. Create Deploy Script
    python
    from praisonai.deploy import Deploy, DeployConfig, DeployType, CloudProvider
    from praisonai.deploy.models import CloudConfig
    
    config = DeployConfig(
        type=DeployType.CLOUD,
        cloud=CloudConfig(
            provider=CloudProvider.GCP,
            region="us-central1",
            service_name="praisonai-service",
            project_id="your-project-id",
            cpu="1",
            memory="512",
            min_instances=0,
            max_instances=10
        )
    )
    
    deploy = Deploy(config, "agents.yaml")
    result = deploy.deploy()
    
    print(f"URL: {result.url}")
  2. Run
    bash
    python deploy_gcp.py

agents.yaml with GCP Config

yaml
framework: praisonai
topic: helpful assistant
roles:
  assistant:
    role: Assistant
    goal: Help users with their questions
    backstory: You are a helpful assistant
    tasks:
      help_task:
        description: Answer user questions
        expected_output: Helpful response

deploy:
  type: cloud
  cloud:
    provider: gcp
    region: "us-central1"
    service_name: "praisonai-service"
    project_id: "${GOOGLE_CLOUD_PROJECT}"
    cpu: "1"
    memory: "512"
    min_instances: 0
    max_instances: 10
    env_vars:
      OPENAI_API_KEY: "${OPENAI_API_KEY}"

GCP Cloud Config Options

FieldTypeDefaultDescription
providerstring–Must be gcp
regionstring–GCP region (e.g., us-central1)
service_namestring–Cloud Run service name
project_idstring–GCP project ID
cpustring1CPU allocation
memorystring512Memory in MB
min_instancesint0Minimum instances (0 = scale to zero)
max_instancesint10Maximum instances
env_varsdictnullEnvironment variables

Check Deployment Status

bash
praisonai deploy status --file agents.yaml

Destroy Deployment

bash
praisonai deploy destroy --file agents.yaml --yes

Troubleshooting

IssueFix
GCP credentialsgcloud auth login or set GOOGLE_APPLICATION_CREDENTIALS
Project not setAdd project_id to agents.yaml
Permission deniedCheck IAM permissions for Cloud Run
Deploy failedRun praisonai deploy doctor --provider gcp
Manual GCP CLI Deployment (Optional)

These commands are for manual deployment only. Use praisonai deploy for automated deployment.

bash
# Initialize and enable services
gcloud init
gcloud services enable run.googleapis.com
gcloud services enable containerregistry.googleapis.com
gcloud services enable cloudbuild.googleapis.com

# Set environment variables
export OPENAI_MODEL_NAME="gpt-4o"
export OPENAI_API_KEY="your-api-key"
export OPENAI_API_BASE="https://api.openai.com/v1"

# Configure Docker authentication
yes | gcloud auth configure-docker us-central1-docker.pkg.dev 
gcloud artifacts repositories create praisonai-repository --repository-format=docker --location=us-central1

# Build and push Docker image
PROJECT_ID=$(gcloud config get-value project)
TAG="latest"
docker build --platform linux/amd64 -t gcr.io/${PROJECT_ID}/praisonai-app:${TAG} .
docker tag gcr.io/${PROJECT_ID}/praisonai-app:${TAG} us-central1-docker.pkg.dev/${PROJECT_ID}/praisonai-repository/praisonai-app:${TAG}
docker push us-central1-docker.pkg.dev/${PROJECT_ID}/praisonai-repository/praisonai-app:${TAG}

# Create secure env vars file (NEVER use --set-env-vars for secrets)
cat > /tmp/praisonai-env.yaml <<EOF
OPENAI_MODEL_NAME: "${OPENAI_MODEL_NAME}"
OPENAI_API_KEY: "${OPENAI_API_KEY}"
OPENAI_API_BASE: "${OPENAI_API_BASE}"
EOF
chmod 600 /tmp/praisonai-env.yaml

# Deploy to Cloud Run with secure env vars file
gcloud run deploy praisonai-service \
    --image us-central1-docker.pkg.dev/${PROJECT_ID}/praisonai-repository/praisonai-app:${TAG} \
    --platform managed \
    --region us-central1 \
    --allow-unauthenticated \
    --env-vars-file /tmp/praisonai-env.yaml

# Clean up temp file
rm /tmp/praisonai-env.yaml

Security: How praisonai deploy Handles Secrets

The praisonai deploy run command automatically handles secrets securely:

Diagram

Agent

Deploy CLI

Secure Temp YAML
chmod 0600

gcloud –env-vars-file

Cloud Run

Temp file deleted

  • Creates temp YAML via tempfile.mkstemp() with mode 0600 (owner read/write only)
  • Passes secrets via --env-vars-file instead of command line arguments
  • Removes temp file in finally block, even if deployment fails
  • No secrets appear in ps, shell history, or CI logs

Validation Commands:

bash
# Verify GCP CLI
gcloud config get-value project

# List Cloud Run services
gcloud run services list

# Describe service
gcloud run services describe praisonai-service --region us-central1

# View logs
gcloud run services logs read praisonai-service --region us-central1

Related