> ## Documentation Index
> Fetch the complete documentation index at: https://docs.backtale.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy Backtale on Google Cloud

> Apply the GCP Terraform pack: Cloud Run pulls the public digest and Cloud SQL for PostgreSQL is reached over the built-in socket.

The Google Cloud pack lives at `deploy/terraform/gcp` on `main` of the product repository, and in the license zip. Cloud Run pulls public `ghcr.io/rahilp/backtale` by digest (no GHCR login) and reaches Cloud SQL over the built-in unix socket. The service is public HTTPS, minimum one instance, CPU always allocated.

## Before apply

* `gcloud` authenticated to a project that can enable APIs and create Cloud Run, Cloud SQL, and Secret Manager
* Terraform 1.5 or later
* The digest and `cosign.pub`. [Verify the image](https://docs.backtale.app/install/verify.md) first.

## Apply

**1. Set variables**

```bash theme={null}
cp terraform.tfvars.example terraform.tfvars
```

```hcl theme={null}
project_id   = "your-gcp-project"
image_digest = "sha256:a4b6216589d14bd4be4deb7db4ed2f81ad28f65b76475135d741bab4c0d8721a"
app_base_url = "https://backtale.example.com"
```

**2. Create the resources**

```bash theme={null}
terraform init
terraform plan
terraform apply
```

Set `app_base_url` to the `cloud_run_url` output, or to your custom domain, and apply again.

**3. Enable pgvector**

```bash theme={null}
gcloud sql connect <instance> --user=backtale --database=backtale
```

```sql theme={null}
CREATE EXTENSION IF NOT EXISTS vector;
```

**4. Finish setup**

Open `<cloud_run_url>/setup` with `terraform output -raw auth_setup_token`. Store `terraform output -raw token_encryption_key` outside Google Cloud. After [First run](https://docs.backtale.app/install/first-run.md), remove `AUTH_SETUP_TOKEN` from the Cloud Run env and its Secret Manager binding, then redeploy.

## Upgrade

Back up Cloud SQL, verify the new digest, set `image_digest`, and `terraform apply`. Read [Upgrade by digest](https://docs.backtale.app/install/upgrade.md) before you change an existing database.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.