anfra docsAlpha
Self-hostCloud providers

Self-host on Google Cloud Run

Self-host anfra on Google Cloud Run from the console or the gcloud CLI.

Set up with a coding agent

Paste this prompt into your coding agent, and it helps you set this up.
Self-host this anfra project on Google Cloud Run. Follow https://anfra.ai/docs/self-host/cloud-run.md. Do the steps you can, and tell me which ones I need to do.

You need your project on GitHub (how) and a Google Cloud account.

Cloud Run builds the Dockerfile with Cloud Build and runs it as a service.

Cloud Run needs three pieces of configuration the other platforms don't: one instance that stays up (Cloud Run scales to zero and up to many instances by default), memory (the project's files sit in memory, so give it 1 GiB), and PUBLIC_URL (Cloud Run doesn't tell the container its address). Your credentials go in Secret Manager, mounted as a file.

1. Add a Dockerfile to your project

From your project's folder, run:

curl -fsSL -O https://raw.githubusercontent.com/holistics/anfra-hosting/main/Dockerfile \
  -O https://raw.githubusercontent.com/holistics/anfra-hosting/main/.dockerignore
git add Dockerfile .dockerignore
git commit -m "Add Dockerfile"
git push

2. Store your credentials in Secret Manager

Your database credentials

Git leaves .anfra/data_sources.yml out, so this is how Cloud Run gets your database credentials. If your project only uses a DuckDB file in the repo, skip this step and the --set-secrets line in step 3.

gcloud secrets create anfra-data-sources --data-file=.anfra/data_sources.yml
gcloud secrets add-iam-policy-binding anfra-data-sources \
  --member=serviceAccount:<project-number>[email protected] \
  --role=roles/secretmanager.secretAccessor

The second command lets the service read the secret. gcloud projects describe <project-id> --format='value(projectNumber)' prints your project number.

3. Deploy

Add a .gcloudignore, so your credentials are not uploaded with the source:

.gcloudignore
.git
#!include:.gitignore

Write the variables to a file outside the project folder:

~/anfra-env.yaml
LOGIN_USERS: 'maria:a-long-password,agent:another-long-password'
PUBLIC_URL: https://anfra-<project-number>.<region>.run.app

Then deploy:

gcloud run deploy anfra --source . --region <region> \
  --port 8080 --memory 1Gi --min 1 --max 1 \
  --allow-unauthenticated \
  --env-vars-file ~/anfra-env.yaml \
  --set-secrets /etc/secrets/data_sources.yml=anfra-data-sources:latest

To let people sign in with Google or GitHub instead, or to use your own login such as Tailscale or Cloudflare Access, see Authentication.

4. Check that it works

Open https://anfra-<project-number>.<region>.run.app. You see a login page. Sign in with a user from LOGIN_USERS, and open one of your Data Apps: it shows your data.

If it doesn't start, read the logs with gcloud run services logs read anfra --region <region>. The last line starting with start.sh: says what to fix, see Troubleshooting. If your apps show errors instead of data, anfra can't reach your database: check your database credentials, and your database's IP allowlist.

5. Connect your coding agent

In Claude Code, with your address and the agent user's password:

claude mcp add --transport http anfra https://anfra-<project-number>.<region>.run.app/mcp \
  --header "Authorization: Basic $(printf 'agent:<agent-password>' | base64 | tr -d '\n')"

Ask it to list your datasets and run a small query. For other agents, see Coding agents with MCP.

Updates

Your anfra project

When you change your project, such as a new or edited Data App, model or dataset, commit it and push it:

git add .
git commit -m "Add the sales dashboard"
git push

If you connected the repo in the console, Cloud Run deploys it on its own. Otherwise, run the gcloud run deploy command from step 3 again.

anfra

Your Dockerfile pins the anfra version. To move to the latest one, download it again from your project's folder, and push it:

curl -fsSL -O https://raw.githubusercontent.com/holistics/anfra-hosting/main/Dockerfile
git add Dockerfile
git commit -m "Update anfra"
git push

It deploys like any change to your project. Run anfra update too, so your CLI matches.

On this page