Service Operating Environment and Deployment Methods
Last Updated: June 29, 2025
This document provides a comprehensive guide to the cloud infrastructure configuration, deployment, and CI/CD pipeline setup for the SurfAI project.
1. Overview
This service builds frontend and backend applications as separate Docker containers and deploys them to Google Cloud Run. CI/CD is automated through GitHub Actions, and authentication is securely handled using Workload Identity Federation.
2. Google Cloud Platform (GCP) Setup
A. Project and API Activation
- Project ID:
surfai-463212 - For deployment, the following APIs must be Enabled in your GCP project:
- Cloud Run API: Deploy and run applications
- Cloud Build API: Build
Dockerimages - Artifact Registry API: Store built
Dockerimages - IAM API (Identity and Access Management): Manage permissions
- IAM Service Account Credentials API: Generate authentication tokens
B. Service Account Setup
This is a dedicated "robot account" that GitHub Actions will use to perform deployment tasks.
- Create Service Account:
- Name:
github-actions-deployer - Email (auto-generated):
[email protected]
- Name:
- Grant Roles to Service Account:
- On the "IAM" page, find the
github-actions-deployeraccount and grant the following roles:Cloud Run AdminCloud Build EditorService Account User
- On the "IAM" page, find the
C. Workload Identity Federation (GitHub Actions Authentication)
Configures GitHub Actions to securely authenticate to GCP without secret keys.
- Create ID Pool:
- Name / Pool ID:
github-actions-pool
- Name / Pool ID:
- Add OIDC Provider:
- Provider ID:
github-actions-provider - Issuer (URL):
https://token.actions.githubusercontent.com - Attribute Condition:
assertion.repository_owner == 'jaytsol'
- Provider ID:
- Connect Service Account to External ID (Most Important):
- Go to the "Permissions" tab of the
github-actions-deployerservice account. - Click "+ Grant Access".
- New Principal:
principalSet://iam.googleapis.com/projects/781704308120/locations/global/workloadIdentityPools/github-actions-pool/attribute.repository_owner/jaytsol - Grant Roles: Add and save both of the following roles:
Workload Identity UserService Account Token Creator
- Go to the "Permissions" tab of the
3. Application Deployment (Cloud Run)
Frontend and backend are deployed as separate Cloud Run services.
A. Backend (surfai-backend)
- Deployment Region:
asia-northeast1(Taiwan) - Domain:
api.surfai.org - Required Environment Variables:
NODE_ENV:productionAPI_BASE_URL:https://api.surfai.orgFRONTEND_URL:https://surfai.orgROOT_DOMAIN:surfai.orgDB_HOST,DB_PORT,DB_USERNAME,DB_PASSWORD,DB_DATABASE: Production PostgreSQL (Supabase) informationJWT_SECRET,JWT_REFRESH_SECRET,JWT_REFRESH_EXPIRATION_TIMEGOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRETADMIN_EMAILS- ...other
R2,ComfyUIrelated keys
B. Frontend (surfai-frontend)
- Deployment Region:
asia-northeast1(Taiwan) - Domain:
surfai.org - Note: Frontend environment variables must be injected at build time, not runtime. (Passed via
substitutionsflag inGitHub Actionsworkflow)
4. CI/CD (GitHub Actions)
A. GitHub Repository Secrets
Set the following Secrets in "Settings" > "Secrets and variables" > "Actions" for each repository.
- Common Secrets (Both Frontend/Backend):
GCP_PROJECT_ID:surfai-463212GCP_WORKLOAD_IDENTITY_PROVIDER:projects/781704308120/...(Full name of Workload Identity provider)
- Frontend-Specific Secrets:
NEXT_PUBLIC_API_URL:https://api.surfai.orgNEXT_PUBLIC_WEBSOCKET_URL:wss://api.surfai.org/events
B. Workflow Files
- Place
deploy-backend.ymlanddeploy-frontend.ymlin the.github/workflows/folder of each repository. - These files will automatically execute whenever code is pushed to the
mainbranch, buildingDockerimages and deploying them toCloud Runby referencingcloudbuild.yaml.