Deploy to Google Cloud run (serverless/on demand)

Guide to Deploy to Google Cloud Run - Short Guide

For more detail refer my blog article at zettabitt.com/silverbullet-cloud-run-deployment-recipe-by-gemini-update-with-concise-guide

PREQUISITES

  • Google Cloud Account - Free & has free tier but billing must be enabled. I went into this in detail with Gemini - and check the original documentation and did calculation by hand - and for a single user note app I expect to remain with the free tier limites.
  • Start a new project in your account from the Cloud Console console.cloud.google.com

I. Provision Storage

  • Console GUI:

    1. Go to Cloud Storage > Buckets.
    2. Click “CREATE BUCKET”.
    3. Name: bucket-for-mynotes-app (or your unique name).
    4. Region: us-central1 (or us-east1, us-west1).
    5. Storage Class: Standard. Access Control: Uniform.
    6. Click “CREATE”.
    7. Go to the created buckehttps://zettabitt.com/silverbullet-cloud-run-deployment-recipe-by-gemini-update-with-concise-guidet’s PERMISSIONS tab.
    8. Click “GRANT ACCESS”.
    9. New principals: Enter your Cloud Run service account email (e.g., [email protected]).
    10. Role: Storage Object Admin.
    11. Click “SAVE”.
  • Cloud Shell CLI:

    Bash

    # Create GCS bucket
    gcloud storage buckets create gs://bucket-for-mynotes-app \
      --project=silverbullet-notes-app \
      --location=us-central1 \
      --uniform-bucket-level-access
    
    # Grant permissions to Cloud Run servichttps://zettabitt.com/silverbullet-cloud-run-deployment-recipe-by-gemini-update-with-concise-guidee account (replace YOUR_PROJECT_NUMBER)
    gcloud storage buckets add-iam-policy-binding gs://bucket-for-mynotes-app \
      --member="serviceAccount:[email protected]" \
      --role="roles/storage.objectAdmin" \
      --project=silverbullet-notes-app
    

II. Deploy Image & Service

  • Cloud Shell CLI (Recommended for initial setup with volume mounts and env vars):

    Bash

    # Enable Cloud Run API (if not already enabled)
    gcloud services enable run.googleapis.com
    
    # Deploy SilverBullet service
    gcloud run deploy silverbullet-notes \
      --image docker.io/zefhemel/silverbullet:latest \
      --project=silverbullet-notes-app \
      --region us-central1 \
      --platform managed \
      --allow-unauthenticated \
      --min-instances 0 \
      --max-instances 1 \
      --cpu 1 \
      --memory 512Mi \
      --add-volume name=silverbullet-data,type=cloud-storage,bucket=bucket-for-mynotes-app \
      --add-volume-mount volume=silverbullet-data,mount-path=/space \
      --set-env-vars SB_FOLDER=/space,SB_USER=your_username:your_password \
      --port 3000
    

    Replace your_username:your_password with your actual SilverBullet credentials.

  • Console GUI:

    1. Go to Cloud Run > Services.
    2. Click “CREATE SERVICE”.
    3. Container image URL: docker.io/zefhemel/silverbullet:latest.
    4. Service name: silverbullet-notes.
    5. Region: us-central1.
    6. Authentication: “Allow unauthenticated invocations”.
    7. Expand “Container(s), volumes, networking, security”.
    8. Container tab: CPU: 1 vCPU, Memory: 512 MiB. Min instances: 0, Max instances: 1. Container port: 3000.
    9. Volumes tab: Add Cloud Storage bucket volume (silverbullet-data → bucket-for-mynotes-app). Add Volume Mount (silverbullet-data → /space).
    10. Variables & Secrets tab: Add SB_FOLDER=/space and SB_USER=your_username:your_password.
    11. Click “CREATE”.

III. Monitor Usage & Costs

  • Console GUI:
    1. Go to Billing > Reports. Filter by Cloud Run and Cloud Storage.
    2. Go to Billing > Budgets & alerts.
    3. Click “CREATE BUDGET”. Set a low budget (e.g., $5) and alert thresholds for “All products”.

IV. Maintain Service & Image

  • Change or Upgrade Image Version (Redeploy):

    • **Cloud Shell CLI:**Bash

      gcloud run deploy silverbullet-notes \
        --image docker.io/zefhemel/silverbullet:[NEW_VERSION_TAG_OR_LATEST] \
        --project=silverbullet-notes-app \
        --region us-central1 \
        --platform managed \
        --allow-unauthenticated \
        --min-instances 0 \
        --max-instances 1 \
        --cpu 1 \
        --memory 512Mi \
        --add-volume name=silverbullet-data,type=cloud-storage,bucket=bucket-for-mynotes-app \
        --add-volume-mount volume=silverbullet-data,mount-path=/space \
        --set-env-vars SB_FOLDER=/space,SB_USER=mike:t1nkerB3ll3! \
        --port 3000
      

      Replace [NEW_VERSION_TAG_OR_LATEST] with the specific version or latest.

    • Console GUI:

      1. Go to Cloud Run > Services. Click silverbullet-notes.
      2. Click “Edit & Deploy new revision”.
      3. Update “Container image URL” with the new tag.
      4. Click “Deploy”.
  • Manually Stop Service (Delete Service Endpoint):

    • **Cloud Shell CLI:**Bash

      gcloud run services delete silverbullet-notes \
        --region us-central1 \
        --project silverbullet-notes-app \
        --quiet for Exploration
      
    • Console GUI:

      1. Go to Cloud Run > Services.
      2. Check the box next to silverbullet-notes.
      3. Click “DELETE” at the top.
      4. Confirm deletion. (Note: Deleting the service endpoint does NOT delete your GCS bucket or its data.)

Useful gcloud Cloud Shell CLI Commands

Bash

# General help for gcloud commands
gcloud COMMAND --help

# List your GCP projects
gcloud projects list

# Set the current project for subsequent commands (replace NAME)
gcloud config set project silverbullet-notes-app

# List your Cloud Storage buckets
gcloud storage buckets list

# List your Cloud Run services
gcloud run services list --region=us-central1 # Specify region

# List service accounts in your project
gcloud iam service-accounts list --project=silverbullet-notes-app

# Get details about a specific Cloud Run service
gcloud run services describe silverbullet-notes --region=us-central1
1 Like

** Gemini 2.5 (free) on Cloud run free-tier **
Checked and confirmed by human, 2025.05.24


Google Cloud Run Free Tier for SilverBullet

Cloud Run’s free tier is designed for low-usage applications and offers the following monthly allowances:

  • CPU Usage: First 180,000 vCPU-seconds per month.
  • Memory Usage: First 360,000 GiB-seconds per month.
  • Requests: First 2 million requests per month.
  • Networking (Egress): First 1 GB of outbound data transfer from North America per month.

How this applies to SilverBullet:

  • Pay-per-use: The key advantage of Cloud Run is that when your SilverBullet instance isn’t actively being used (i.e., you’re not accessing it), it scales down to zero instances, and you don’t pay for idle time. This is critical for keeping costs low.
  • CPU and Memory: SilverBullet is a lightweight application, so it likely won’t consume a lot of CPU or memory unless you’re constantly accessing it or performing heavy operations. For typical personal use (a few hours a day, occasional queries), you should easily stay within the free tier limits for CPU and memory.
  • Requests: 2 million requests per month is a huge allowance for a personal knowledge base. Each time you load a page, save a note, or run a query, it counts as a request. Unless you have extremely frequent automated processes or share it with a massive audience, you’ll stay well within this limit.
  • Networking (Egress): This is the data transfer out of Google Cloud. For a personal note-taking app, your egress will mostly be the text and any images you embed. 1 GB is generally sufficient for personal use. If you store many large images or frequently sync a massive local space, you might start to approach this limit.

Potential Cost Factors to Watch Out For:

  • Persistent Storage: SilverBullet stores its data as Markdown files. Cloud Run itself is stateless, meaning any data stored directly on the container instance will be lost when the instance scales down or is redeployed. To persist your notes, you’ll need a separate storage solution.
    • Cloud Storage: This is the most common and cost-effective option for file storage on Google Cloud. The free tier for Cloud Storage offers 5 GB-months of Standard Storage (in US regions), 5,000 Class A operations, and 50,000 Class B operations, and 100 GB of outbound data transfer from North America. This is usually plenty for personal notes. SilverBullet could be configured to use a Google Cloud Storage bucket for its “space” (where the Markdown files live).
    • Cloud SQL (or other databases): While SilverBullet doesn’t use a traditional relational database, if you were to consider other applications in the future that do, Cloud SQL would be a significant cost. The free tier for Cloud SQL is very limited.
  • Continuous Usage: If you were to configure Cloud Run to never scale down to zero (e.g., for very low latency access at all times), you would incur continuous charges for CPU and memory, which would quickly exceed the free tier. For a personal app, this is generally not necessary as SilverBullet’s “Local First PWA” design allows for offline use and synchronization.
  • Tier 2 Regions: Google Cloud regions are divided into pricing tiers. Tier 1 regions (like some in the US and Europe) are generally cheaper. If you deploy to a Tier 2 region (e.g., some in South America or Asia), costs beyond the free tier would be higher.
  • Serverless VPC Access: If you need to connect your Cloud Run service to resources within a Virtual Private Cloud (VPC), there might be additional compute charges for the Serverless VPC Access connector. For a basic SilverBullet setup, this is unlikely to be needed.

Prerequisites for Deployment

  1. Google Cloud Account: If you don’t have one, sign up for a Google Cloud account. New customers often get a $300 free credit, which is a great buffer while you get started.
  2. Enable Billing: Even for free tier services, you need to enable billing on your Google Cloud project. This allows Google to track your usage and apply the free tier credits automatically. You won’t be charged unless you exceed the free tier.

1 Like