Deploy guide

Palace Server on Google Cloud (Terraform, Cloud Run + Cloud SQL)

Two terraform apply runs create a VPC, a Cloud SQL for PostgreSQL database with a private IP only, Palace Server on Cloud Run behind a global HTTPS load balancer with a Google-managed certificate, the secrets in Secret Manager and the DNS record in Cloud DNS. In between you run one database setup command; at the end, one bootstrap command.

At a glance

WhatValue
Good forTeams that already run on Google Cloud and want managed containers and a managed database
Time to deployAbout 30 minutes, most of it waiting for Cloud SQL and the certificate
CostFrom $225.59/month in us-central1 (see below)
Not yet applied to a real Google Cloud project

The Terraform passes validation and parts of it were run locally, but a full apply against a real Google Cloud project has not been run yet. The Tested section below lists what was and was not checked.

What this sets up

  • A VPC with one subnet. Cloud Run sends traffic for private addresses into it (Direct VPC egress, private ranges only); Cloud SQL sits on a private IP reached through Private Service Access. There is no NAT gateway: the monthly license check leaves Cloud Run directly, the same way it would without a VPC.
  • Cloud SQL for PostgreSQL 17, Enterprise edition, db-custom-1-3840 (1 dedicated vCPU, 3.75 GB, 100 connections), single zone by default, SSD storage that grows on its own, daily backups kept 7 days, point-in-time recovery, deletion protection. No public IP, and the instance refuses unencrypted connections. Palace connects as palace_app over TLS (sslmode=verify-ca with the instance's own CA, see below), and that role cannot bypass row-level security. The built-in postgres user gets a random password, used only by the setup job.
  • Cloud Run: a service with two instances that always run and keep their CPU between requests (instance-based billing), because Palace runs an embedding worker in the background. Each instance has two containers:
    • an nginx proxy (nginxinc/nginx-unprivileged, non-root) that is the only container receiving traffic. /metrics always returns 404. /bootstrap returns 404 unless bootstrap is enabled and the request carries the bootstrap token. Everything else goes to Palace on localhost:8080. Its config is proxy/default.conf.template ↗.
    • Palace Server (1 vCPU, 1 GiB) as UID 10001, started first; the proxy waits until Palace answers /readyz.

    Cloud Run has no setting for a read-only filesystem or for dropping Linux capabilities, so unlike the other setups those two are not applied here. Palace writes nothing to disk, and each instance runs in Cloud Run's sandbox.

    The service accepts traffic only from the load balancer: its run.app URL is closed to the internet.

  • Secret Manager for the license key, JWT secret, bootstrap token, both database passwords, the full database URL, the database's CA certificate and the proxy config. Cloud Run reads them when an instance starts. Two service accounts with no project roles can each read only their own secrets.
  • A global external Application Load Balancer with a static IP, a Google-managed certificate, TLS 1.2 and 1.3 only, HTTP to HTTPS redirect and HSTS.
  • An A record in an existing Cloud DNS zone (optional), and a Cloud Run job that prepares the database.

Why verify-ca and not verify-full

verify-full checks that the server certificate names the host you connected to. Cloud SQL's server certificate (per-instance CA, the default) names the instance, not its private IP, so verify-full against the IP always fails. verify-ca still checks that the server presents a certificate signed by this instance's own CA, which Terraform reads from the instance and mounts as a file. Together with the private network, that rules out anyone else answering on that address.

Why a load balancer

It is the supported way to put a custom domain with a managed certificate in front of Cloud Run in every region. Cloud Run's own domain mapping is free but Google marks it as preview and not recommended for production, and it is not offered in europe-west3. Firebase Hosting would work too, but adds another product to run. The load balancer costs a flat $18.25/month for its forwarding rules.

Costs

Prices checked 2026-11-29, USD per month (730 hours) before tax, read from Google's pricing pages with the region selector set to each region: Cloud Run ↗, Cloud SQL ↗, Cloud Load Balancing and IP addresses ↗, Secret Manager ↗, Cloud DNS ↗. The Google-managed certificate is free.

Small (default): 2 instances, each Palace 1 vCPU / 1 GiB plus the proxy 0.5 vCPU / 256 MiB, db-custom-1-3840, 10 GB SSD. Medium: 2 instances, each Palace 2 vCPU / 2 GiB plus the proxy, db-custom-2-7680 (2 vCPU, 7.5 GB), 50 GB SSD.

LineSmall us-central1Small europe-west3Medium us-central1Medium europe-west3
Cloud Run CPU, always allocated$141.91$170.29$236.52$283.82
Cloud Run memory$13.14$15.77$23.65$28.38
Cloud SQL vCPU and memory, single zone$49.31$59.20$98.62$118.41
Cloud SQL SSD storage$1.70$2.04$8.50$10.20
Cloud SQL backups (10 GB / 50 GB assumed)$0.80$0.96$4.00$4.80
Load balancer forwarding rules$18.25$18.25$18.25$18.25
Load balancer data processed (10 GiB / 50 GiB each way assumed)$0.16$0.20$0.80$1.00
Static IP (attached to the load balancer)$0.00$0.00$0.00$0.00
Secret Manager (8 versions, 6 free)$0.12$0.12$0.12$0.12
Cloud DNS managed zone$0.20$0.20$0.20$0.20
Total$225.59$267.03$390.66$465.18

Rates used (us-central1 / europe-west3):

Itemus-central1europe-west3
Cloud Run, instance-based billing, per vCPU-second$0.000018$0.0000216
Cloud Run, instance-based billing, per GiB-second$0.000002$0.0000024
Cloud SQL Enterprise, general purpose, per vCPU-hour$0.0413$0.0496
Cloud SQL Enterprise, general purpose, per GiB-hour of memory$0.007$0.0084
Cloud SQL SSD storage per GiB-hour (per GB-month)$0.000232877 ($0.17)$0.000279452 ($0.204)
Cloud SQL backups per GiB-hour (per GB-month)$0.000109589 ($0.08)$0.000131507 ($0.096)
Cloud SQL db-f1-micro (shared core) per hour$0.0105$0.0126
Global forwarding rules, first 5, per hour$0.025$0.025
Load balancer data processed per GiB, inbound / outbound$0.008 / $0.008$0.01 / $0.01
Static IP attached to a forwarding ruleNo chargeNo charge
Secret Manager per active version-month (first 6 free)$0.06$0.06
Cloud DNS managed zone per month (first 25)$0.20$0.20

Cloud Run is most of the bill: an instance that keeps its CPU is billed for every second it runs, and Palace needs that for its background worker. The proxy sidecar is about $25/month per instance of it (us-central1). Ways to pay less:

  • min_instances = 1 halves the Cloud Run lines, at the cost of no spare instance during a restart or a zone outage.
  • A one-year Cloud Run committed use discount lowers the CPU and memory rates by about 17% ($0.00001494 per vCPU-second in us-central1).
  • db_tier = "db-f1-micro" costs $7.67/month in us-central1 instead of $49.31, but Google excludes shared-core machine types from the Cloud SQL SLA and says not to use them in production. It allows only 25 connections, so also set max_instances = 2.

Not included: data transfer out to the internet, Cloud Logging beyond the free allowance (the load balancer logs every request), Secret Manager access operations beyond 10,000 a month, DNS queries ($0.40 per million) and the Cloud Run free tier (240,000 vCPU-seconds and 450,000 GiB-seconds a month per billing account). Skip the DNS zone line if you already pay for it. db_availability_type = "REGIONAL" adds a standby in a second zone and doubles the Cloud SQL lines. Load balancer data and backup sizes depend on use: the amounts above are assumptions, not measurements. Your Palace license is billed separately.

Steps

01

Prepare

  • A Google Cloud project with billing enabled, and the gcloud CLI ↗ logged in twice: gcloud auth login and gcloud auth application-default login.
  • Owner on the project, or enough roles to enable APIs and create networks, Cloud SQL, Cloud Run, Secret Manager secrets, service accounts and load balancers.
  • A Cloud DNS managed zone that contains your domain, for example a zone named yourco-com for palace.yourco.com. Or set manage_dns = false and create the A record yourself from the lb_ip output.
  • A license key from palacememory.com.
  • Terraform 1.6+ or OpenTofu.
02

Configure

Get the recipe
git clone https://github.com/AncientiCe/palace-server-examples.git
cd palace-server-examples/gcp
cp terraform.tfvars.example terraform.tfvars   # edit it
export TF_VAR_license_key='your-license-key'

Terraform state holds the generated secrets (database passwords, JWT secret, bootstrap token). For anything beyond a trial, keep state in an encrypted remote backend such as a private Cloud Storage bucket.

03

Deploy

Palace cannot start until the database has its extensions and the palace_app role, so the first apply leaves out the Cloud Run service:

First apply, without the service
terraform init
terraform apply -var deploy_service=false

Then prepare the database once. This runs a short Cloud Run job as the postgres user: it creates the vector and pgcrypto extensions and the palace_app role (db-setup.sh ↗), and is safe to run again.

Prepare the database
eval "$(terraform output -raw db_setup_command)"

It waits for the job and reports that the execution completed successfully. Then create the service:

Second apply
terraform apply

The certificate is issued once your domain points at the load balancer. That takes 15 to 60 minutes after the A record exists; until then HTTPS fails with a certificate error. Check its state with gcloud compute ssl-certificates list, then open https://<your domain>/readyz.

04

Create the first admin

Bootstrap runs from your machine through the load balancer. The proxy forwards /bootstrap only with the right X-Bootstrap-Token header.

Bootstrap the first admin
terraform output -raw bootstrap_command   # edit the three values, then run it

Save the api_key and org_id. Then turn bootstrap off, which removes the token from both containers:

Turn bootstrap off
# in terraform.tfvars
enable_bootstrap = false

terraform apply

After that /bootstrap returns 404 from the proxy. It would return 409 from Palace anyway, because bootstrap works only once.

05

Connect your team

Follow Connect clients with your URL.

Upgrade

Set the new tag and apply. Cloud Run starts a new revision and moves traffic to it only once Palace passes its startup check.

Upgrade
# in terraform.tfvars
palace_version = "<new version>"

terraform apply

To go back, send traffic to the previous revision: gcloud run services update-traffic palace --region <region> --to-revisions <previous revision>=100, then set the old tag in terraform.tfvars.

Restore

The simplest restore puts a backup back onto the same instance, which keeps its private IP and CA, so nothing else changes (guide ↗):

Restore a backup
gcloud sql backups list --instance <instance>
gcloud sql backups restore <backup id> --restore-instance <instance>

For a point in time, Cloud SQL clones to a new instance (guide ↗). The clone has a new IP and its own CA: put its IP in the database-url secret and its CA certificate in the db-server-ca secret as new versions, then point the palace container at those versions in the Cloud Run console (Edit and deploy new revision). Terraform still tracks the old instance; bring the code in line before your next apply.

Tested

The Terraform passes terraform fmt -check and terraform validate (Terraform 1.9.8, Google provider 6.50.0). terraform test with mocked providers planned and applied it with bootstrap on and off and with deploy_service = false, checking that the token reaches both containers only while bootstrap is on and that the database URL is built as described.

The proxy config ran locally in the same nginx-unprivileged:1.27-alpine image, sharing a network namespace with a stand-in upstream on port 8080 (the way Cloud Run containers share localhost): /readyz and other paths were proxied; /metrics, /metrics/x, /metrics/, //metrics, /%6Detrics and /foo/../metrics returned 404; POST /bootstrap returned 404 without the header, with a wrong or empty header and for /bootstrap/x, and was proxied with the right token; with the token empty, /bootstrap returned 404 even with a header.

db-setup.sh was run twice against a local pgvector/pgvector:pg17 container with TLS on, from the postgres:17 image the job uses, with sslmode=verify-ca and a server certificate that names an instance instead of the IP: the second run changes nothing, palace_app has rolsuper = f and rolbypassrls = f, both extensions exist, and palace_app can connect with verify-ca and create tables. verify-full against the IP failed as expected.

Not tested yet

A full apply against a real Google Cloud project has not been run yet. Not tested: the load balancer and certificate, Cloud Run accepting the 0.5 vCPU proxy next to Palace with CPU always allocated, the startup order, secret files on Cloud Run, the job on Cloud SQL (where postgres is a member of cloudsqlsuperuser, not a superuser), the license check without NAT, and the restore steps. If something fails, open an issue ↗.

Troubleshooting

  • The second apply fails on the Cloud Run service: the revision did not become ready. Check the setup job ran, then the logs with eval "$(terraform output -raw logs_command)". An expired or wrong license stops startup. Run terraform apply again once fixed.
  • Cloud Run rejects the proxy's CPU: set proxy_cpu = "1" (and proxy_memory = "512Mi") and apply. It costs about $25/month more per instance in us-central1.
  • HTTPS fails with a certificate error: the managed certificate is still provisioning. gcloud compute ssl-certificates describe palace-cert --global shows its state; it needs the A record to point at lb_ip.
  • The setup job cannot reach the database: an organization policy may restrict Direct VPC egress (run.allowedVPCEgress) or Cloud SQL private IP. See the job's logs in the Cloud Run console.
  • The license check fails on a monthly plan: an organization policy or firewall may block internet egress from Cloud Run. Palace needs to reach api.palacememory.com over HTTPS.
  • /bootstrap returns 404: check the token header and that enable_bootstrap is still true. After the first admin exists it returns 409.
  • terraform destroy fails on the database: set db_deletion_protection = false, apply, then destroy.
  • Something else? Open an issue ↗

View on GitHub ↗

Running something different?

Nomad, Hetzner, OpenShift, another IaC tool? Request a setup ↗. Never paste license keys, passwords, tokens or database URLs in an issue.

Other setups

Docker Compose on one machine · DigitalOcean (Terraform) · AWS (Terraform, ECS Fargate + RDS) · Azure (Terraform, Container Apps + PostgreSQL Flexible Server) · Kubernetes (Helm) · Kubernetes (plain kubectl) · Air-gapped (no internet) · Linux without Docker (systemd)

Put your knowledge to work

Give your next session
a head start.

Start your team trial

60 days · 10 seats · No credit card