This guide covers the initial setup required to deploy CITB4 to your own Google Cloud Platform project.
- Google Cloud Platform account with billing enabled
gcloudCLI installed and authenticated- Python 3.13
uvpackage manager (or standardpip)
Create OAuth 2.0 credentials in Google Cloud Console:
- Go to Google Cloud Console → APIs & Services → Credentials
- Create OAuth 2.0 Client ID (Web application type)
- Add authorized redirect URIs:
- DEV:
https://citb4-dev-<PROJECT_NUMBER>.<REGION>.run.app/authorize - PROD:
https://citb4-<PROJECT_NUMBER>.<REGION>.run.app/authorize
- DEV:
- Download the client secret JSON
Set these as Cloud Run environment variables:
OAUTH_CLIENT_ID=<your-client-id>.apps.googleusercontent.com
OAUTH_CLIENT_SECRET=<your-client-secret>
SECRET_KEY=<random-secret-key-for-flask-sessions>To generate a secure SECRET_KEY:
python -c "import os; print(os.urandom(24).hex())"# Your GCP project ID
export GCP_PROJECT=your-project-id
# Environment (DEV or PROD)
export ENV=DEV # or PROD
# Optional: override default region (defaults to europe-west4)
export BATCH_REGION=europe-west4gcloud services enable \
run.googleapis.com \
batch.googleapis.com \
cloudbuild.googleapis.com \
storage.googleapis.com \
compute.googleapis.com \
iam.googleapis.com# Development bucket
gsutil mb -l europe-west4 gs://citb4-projects-dev
# Production bucket (when ready)
gsutil mb -l europe-west4 gs://prod-projectsVerify bucket locations:
gsutil ls -L -b gs://citb4-projects-dev | grep location
gsutil ls -L -b gs://prod-projects | grep locationGrant Cloud Batch service account access to storage:
# Get your project number
PROJECT_NUMBER=$(gcloud projects describe $GCP_PROJECT --format='value(projectNumber)')
# Grant storage admin role to Compute Engine service account (used by Cloud Batch)
gcloud projects add-iam-policy-binding $GCP_PROJECT \
--member="serviceAccount:${PROJECT_NUMBER}-compute@developer.gserviceaccount.com" \
--role="roles/storage.objectAdmin"
# Grant Cloud Run service account storage access
gcloud projects add-iam-policy-binding $GCP_PROJECT \
--member="serviceAccount:${PROJECT_NUMBER}-compute@developer.gserviceaccount.com" \
--role="roles/iam.serviceAccountTokenCreator"Option A: Using gcloud CLI
# For DEV environment
gcloud run services update citb4-dev \
--region=europe-west1 \
--update-env-vars=OAUTH_CLIENT_ID=<your-client-id>,OAUTH_CLIENT_SECRET=<your-client-secret>,SECRET_KEY=<your-secret-key>
# For PROD environment
gcloud run services update citb4 \
--region=europe-west1 \
--update-env-vars=OAUTH_CLIENT_ID=<your-client-id>,OAUTH_CLIENT_SECRET=<your-client-secret>,SECRET_KEY=<your-secret-key>Option B: Using Google Cloud Console
- Navigate to Cloud Run → Select service (citb4-dev or citb4)
- Click "Edit & Deploy New Revision"
- Go to "Variables & Secrets" tab
- Add environment variables:
OAUTH_CLIENT_IDOAUTH_CLIENT_SECRETSECRET_KEY
CITB4 uses high-CPU machines for processing. Check and request quota increases:
# Check current quotas
gcloud compute project-info describe --project=$GCP_PROJECT
# Request increases via: https://console.cloud.google.com/iam-admin/quotasRequired quotas for europe-west4:
CPUS_ALL_REGIONS: 128+ (for n2-highmem-128 instances)N2_CPUS: 128+ (region-specific)GPUS_ALL_REGIONS: 2 (optional, for future GPU support)
The repository is configured for automatic deployment via Cloud Build:
-
Fork or clone the repository
-
Configure GitHub → Google Cloud Build integration:
- Go to Cloud Build → Triggers
- Connect your GitHub repository
- Create trigger for
mainbranch (DEV) andreleasebranch (PROD)
-
Push to trigger deployment:
git push origin main # Deploys to DEV (citb4-dev) git push origin release # Deploys to PROD (citb4)
# Build and deploy manually
gcloud builds submit --config cloudbuild.yaml .Using uv (recommended):
# Install uv if not already installed
pip install uv
# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -r requirements.txtUsing standard pip:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtgit submodule update --init --recursive
git submodule update --remote DES_thermal_simulation
# Linux case-sensitivity fix for Rust imports
cd DES_thermal_simulation/src
ln -sf Interpolator.rs interpolator.rs
cd ../..Using direnv (optional, recommended):
# .envrc is already configured
direnv allowOr manually activate:
source .venv/bin/activate# Run Flask UI
python app.py
# Or using podman/docker
podman build -t citb4 .
podman run -p 5000:5000 -e MODE=ui citb4Access at: http://localhost:5000
# Get service URL
gcloud run services describe citb4-dev --region=europe-west1 --format='value(status.url)'
# Test health endpoint
curl https://citb4-dev-<PROJECT_NUMBER>.europe-west1.run.app/healthVisit the Cloud Run URL and click "Login with Google". You should be redirected to Google sign-in.
-
Upload a test project with required input files:
rust_code_input/conductivity.csvrust_code_input/sp_heat_cap_data.csvrust_code_input/Input_file.txtrust_code_input/wall.gcode
-
Click "Run Simulation" and verify Cloud Batch job is created
-
Check job status:
gcloud batch jobs list --location=europe-west4
# Cloud Run logs
gcloud logging read "resource.type=cloud_run_revision AND resource.labels.service_name=citb4-dev" --limit 50 --format=json
# Cloud Batch logs
gcloud logging read "resource.type=cloud_batch_job" --limit 50 --format=jsonError: "redirect_uri_mismatch"
- Fix: Add the exact Cloud Run URL to OAuth authorized redirect URIs in Google Cloud Console
Error: "CODE_VOLUME_INVALID_ARGUMENT"
- Fix: Ensure GCS bucket path has NO trailing slash in
cloudbuild.yaml
Error: "PERMISSION_DENIED"
- Fix: Grant service account permissions (see IAM setup above)
Files >32MB require direct GCS upload (handled automatically by the app). Ensure:
- Service account has
storage.objectAdminrole - OAuth is properly configured for signed URL generation
All data remains in Europe:
- Cloud Storage:
europe-west4(Netherlands) - Cloud Batch:
europe-west4 - Cloud Run:
europe-west1(Belgium) (This is not consistent because some machines weren't available in some regions)
For issues specific to CITB4 deployment:
- Check DEPLOYMENT.md for detailed architecture documentation
- Review CLAUDE.md for development notes
- Check Cloud Run and Cloud Batch logs for error details
For GCP-specific issues: