This guide describes gcp/ in the independent infra repository; run the commands in that checkout. After deployment, follow initial setup to create the administrator and workspace.
Run this folder from an independent infra checkout. This is an initial single-VM deployment, with one backend replica and no high availability. It supports the existing Compose stack, including LiveKit UDP/TURN. No nearby application source checkout is required to deploy already-built images. The commands below create billable resources or publish images only when explicitly run by an operator; CI only validates synthetic configuration.
Resources and defaults#
Terraform uses an existing billing-enabled project and enables Compute Engine, IAM, Artifact Registry, IAP and OS Login APIs. It creates a custom VPC/subnet, regional static IPv4, Ubuntu 24.04 amd64 VM (e2-standard-4, 30 GB boot disk), separate 100 GB balanced persistent data disk, daily snapshots at 04:00 UTC with 14-day retention, private Docker repository and a dedicated runtime service account. Its only application IAM grant is repository-scoped Artifact Registry reader. No service account keys or runtime secrets enter Terraform or VM metadata.
Iowa (us-central1, us-central1-a) is the configurable cost-oriented default. São Paulo is southamerica-east1 / southamerica-east1-a; change both before the first apply. Compare latency, data residency and the full bill, including network egress, IP, disks, snapshots and image storage. Region/zone/name changes after provisioning require a planned migration; protected resources intentionally block destructive replacement. See official VM pricing.
| Access | Inbound ports |
|---|---|
| Public HTTPS/ACME | TCP 443, 80 |
| LiveKit media and authenticated TURN | TCP 7881; UDP 7882, 3478 |
| Administration through IAP only | TCP 22 from 35.235.240.0/20 |
PostgreSQL, RustFS API, backend and SFU control port 7880 are private. Mailpit and RustFS consoles bind to VM loopback only. Documentation and recording are disabled by default. No federation or custody policy is enabled. The host-based SFU needs a public IPv4; this stack does not include TURN/TLS on 443 for networks blocking UDP and TCP 7881.
Authenticate and provision#
Install Terraform 1.9+ (CI uses 1.17.2), Google Cloud CLI and Docker with Compose v2. Use personal ADC or short-lived service-account impersonation, never downloaded JSON keys. The project administrator must grant the provisioning principal permissions to enable services, manage Compute resources and service accounts, act as the new VM account, and manage the repository and its IAM. These permissions are separate from the VM's read-only runtime role.
Human administrators need roles/iap.tunnelResourceAccessor, roles/compute.osAdminLogin, Compute read permissions for CLI discovery, and roles/iam.serviceAccountUser on the VM account. An organization policy may impose additional restrictions. Terraform intentionally does not grant users project-wide roles. See OS Login setup and IAP TCP forwarding.
cd gcp
gcloud auth login
gcloud auth application-default login
cp terraform.tfvars.example terraform.tfvars
# Edit project_id, region/zone and capacity; this file contains no credentials.
terraform init
terraform fmt -check -recursive
terraform validate
terraform plan -out=review.tfplan
# Inspect the plan privately. Only execute after reviewing the new resources/costs:
terraform apply review.tfplanState, plans and real tfvars are ignored, but still sensitive: protect local files and encrypted backups with restrictive permissions. For collaboration, configure an existing private versioned GCS bucket using a local ignored backend.tf copied from gcp/backend.tf.example and ignored backend.hcl copied from gcp/backend.hcl.example, with bucket and a dedicated prefix; run terraform init -migrate-state -backend-config=backend.hcl deliberately after backing up state. The module does not create a state bucket or migrate existing state automatically. Keep the versioned provider lock file.
The startup script formats only a blank data disk identified as google-sintonia-data. It refuses unknown signatures, other filesystems and a populated mount point. Existing ext4 disks are mounted without formatting. /srv/sintonia holds configuration, cryptographic keys and all application data. Docker requires that mount before starting; deploy additionally verifies its UUID. Existing data ownership is preserved. The boot disk and Docker image cache are not application backups.
Capture only public deployment coordinates:
GCP_PROJECT=$(terraform output -raw project_id)
GCP_ZONE=$(terraform output -raw zone)
GCP_VM=$(terraform output -raw instance_name)
GCP_IP=$(terraform output -raw public_ipv4)
IMAGE_PREFIX=$(terraform output -raw image_prefix)
gcloud compute ssh "$GCP_VM" --project "$GCP_PROJECT" --zone "$GCP_ZONE" --tunnel-through-iap
# On the VM, wait for this command to succeed, then exit the SSH session:
sudo test -f /srv/sintonia/bootstrap-readyIf bootstrap fails, inspect the google-startup-scripts.service journal on the VM. Repair the cause and rerun the two public scripts in order as root (mount-data.sh, then bootstrap-docker.sh); never format an existing disk or reset volumes to repair startup.
One-command release, including an Android APK#
After provisioning, prepare a separate GCP configuration and review domains, ACME email, SMTP and registration policy:
cd /absolute/path/to/infra/gcp
test -e .env.deploy || cp .env.example .env.deploy
chmod 600 .env.deploy
# Edit .env.deploy privately; the release command fills the four image references.Use Python 3.10+, Terraform, Google Cloud CLI, Docker/Buildx and Flutter/Dart (the app currently targets Flutter 3.50.1/Dart 3.14.0) on the workstation. Authenticate gcloud auth login; the publisher needs Artifact Registry writer on the provisioned repository, plus the human IAP/OS Login permissions above. Establish the IAP SSH connection once using --strict-host-key-checking=ask, verify the VM host-key fingerprint through a trusted GCP console/session and accept it. The release command then requires strict host verification for SSH and SCP. See gcloud SSH options.
The CLI mirrors the DigitalOcean release arguments. All checkout paths are explicit, so independent repository locations are supported. Example with APK build 42 (use your next distribution build number):
cd /Users/gnascimento/src/sintonia/app
flutter build apk --release --build-number=42
cd /Users/gnascimento/src/sintonia/infra/gcp
SINTONIA_ANDROID_APK="/Users/gnascimento/src/sintonia/app/build/app/outputs/flutter-apk/app-release.apk" \
bash scripts/release.sh .env.deploy 1.0.0-gcp.42 \
../../backend ../../app ../../documentation-site ../../recorderThe general signature is:
bash scripts/release.sh CONFIG_FILE RELEASE BACKEND_DIR APP_DIR DOCS_DIR RECORDER_DIR [--repair-docker]SINTONIA_ANDROID_APK is optional. When present, the app's public preparation tool verifies a signed, non-debug one.sintonia APK and embeds its manifest/checksum/download into the new web image. APK generation remains a prior explicit step using your release signing setup; signing files are excluded from temporary build contexts. To keep offering the APK in every web release, supply it for each release. The script does not enable the installation's Android-download policy.
The command reads only named public Terraform outputs from this GCP checkout, authenticates Docker with a short-lived token in temporary private configuration, and checks VM access, mount/bootstrap, existing credentials and managed files before compiling. Docker context metadata/TLS material is retained privately for the selected local builder; existing saved registry authentication is not reused or modified. Builds use disposable copies excluding private environments, keys, caches and existing builds. The app worker and web are rebuilt, the optional APK is prepared, and backend, web, documentation and recorder images are built/pushed for linux/amd64 with one release tag. A configured DOCS_DOMAIN also supplies the documentation image's canonical URL build argument.
After all four images are pushed, the script installs the reviewed public bundle through IAP and runs the mounted-VM deployment helper. Known managed scripts are updated with public-file backups under /srv/sintonia/.release-backups/; custom Caddy/Compose files are preserved with a review notice, while customized deployment scripts require manual review before replacement. The installer and deploy helper share one lock. Runtime settings cannot redirect Compose files/projects or the VM Docker connection; the VM helper uses its local Docker socket. Environment merging preserves established credentials, storage settings and INSTANCE_IDENTITY_ORIGIN; generated runtime secrets remain on the VM. Four image references are saved atomically to the local GCP config with mode 600 only after deployment succeeds. Source checkouts and existing local builds remain untouched. Private staging and temporary Docker authentication are cleaned up; a failed SSH cleanup reports the exact temporary VM directory for manual removal.
Provisioning and DNS remain prerequisites. Documentation publication and recording activation still require their explicit profiles and operator configuration; pushing their images alone does not enable either service. Never pass the DigitalOcean .env.deploy or the local infra/collection .env as the GCP configuration; the wrapper refuses those known paths. It does not apply Terraform, migrate existing data or enable federation/custody. --repair-docker explicitly permits Docker bootstrap repair on an already mounted data disk; it never formats or mounts a disk.
On build/auth/preflight/install failure, local configuration is retained. Already-pushed images remain in the registry, and a failed Compose update can leave some services updated and the VM environment referencing the attempted release. Review status and retry deliberately; this is not an atomic application/database rollback. If local config is edited during builds, installation is cancelled before the final VM step. Detected concurrent local edits after VM success are preserved with an error rather than overwritten. No real release was executed to prepare or test this wrapper.
Versioned images#
Use existing compatible linux/amd64 images or build with explicit component paths. The image publisher needs roles/artifactregistry.writer on this repository; the runtime VM does not. Authenticate Docker using short-lived credentials:
RELEASE=2026.12.01-1
GCP_REGION=$(terraform output -raw region)
gcloud auth configure-docker "$GCP_REGION-docker.pkg.dev"
# These paths are supplied explicitly; no sibling checkout layout is assumed.
BACKEND_DIR=/absolute/path/to/backend
APP_DIR=/absolute/path/to/app
DOCS_DIR=/absolute/path/to/documentation-site
# Prepare the web artifact using the app repository's documented build procedure.
# Its build/web directory must contain the complete worker-enabled web release.
docker buildx build --platform linux/amd64 --tag "$IMAGE_PREFIX/backend:$RELEASE" --push "$BACKEND_DIR"
docker buildx build --platform linux/amd64 --tag "$IMAGE_PREFIX/web:$RELEASE" --push "$APP_DIR"
# Optional: only build/push documentation when its publication is intended.
# docker buildx build --platform linux/amd64 --tag "$IMAGE_PREFIX/documentation:$RELEASE" --push "$DOCS_DIR"Image builds/pushes are explicit operator actions. See each component's README for build arguments, worker assets and artifact requirements. Use unique release tags; do not reuse latest. The Compose validator requires application images from the provisioned repository. Recording requires a separately built amd64 recorder image and extra capacity; see recording pools.
First application deployment — manual alternative#
Create .env from gcp/.env.example, restrict it to mode 600 and edit domains, ACME email and image references. Replace every your-gcp-project and RELEASE placeholder, including optional image references before enabling their profiles. Keep COMPOSE_PROFILES empty for the initial deployment. Invite-only registration is the default. Mailpit captures mail locally; configure real SMTP for delivery to external inboxes. Set DNS A records for app, API and RTC to GCP_IP; use sintonia.one only when you control its DNS and intend the cutover. Do not copy or edit the DigitalOcean .env.deploy automatically.
On a new empty installation, missing database, RustFS, LiveKit, admin bootstrap and recording credentials are generated privately on the VM. The stable identity origin is fixed to https://API_DOMAIN on the first run. For a migration, restore the original database, uploads/object data, instance keys, recording keys and environment first, and explicitly retain the previous INSTANCE_IDENTITY_ORIGIN. A new domain alone does not transfer old messages or client keys. Read infra/MIGRATION.md before cutting over; this module does not migrate data.
Build a public deployment bundle with an explicit file list, and transfer private configuration separately over IAP:
# Run locally in gcp/, with the public coordinates set above.
chmod 600 .env
# The archive contains no environment, state, tfvars or backups.
tar -czf /tmp/sintonia-gcp-bundle.tgz compose.yaml Caddyfile scripts/runtime.py scripts/validate-config.py scripts/deploy.sh scripts/mount-data.sh scripts/bootstrap-docker.sh
gcloud compute ssh "$GCP_VM" --project "$GCP_PROJECT" --zone "$GCP_ZONE" --tunnel-through-iap --command='umask 077; mkdir -p ~/sintonia-stage'
gcloud compute scp --project "$GCP_PROJECT" --zone "$GCP_ZONE" --tunnel-through-iap /tmp/sintonia-gcp-bundle.tgz "$GCP_VM:~/sintonia-stage/bundle.tgz"
gcloud compute scp --project "$GCP_PROJECT" --zone "$GCP_ZONE" --tunnel-through-iap .env "$GCP_VM:~/sintonia-stage/runtime.env"
gcloud compute ssh "$GCP_VM" --project "$GCP_PROJECT" --zone "$GCP_ZONE" --tunnel-through-iapOn the VM, first installation only:
# Refuse to overwrite an existing deployment; extract only the reviewed public bundle.
sudo test -f /srv/sintonia/bootstrap-ready
sudo test ! -e /srv/sintonia/compose.yaml && sudo tar -xzf ~/sintonia-stage/bundle.tgz -C /srv/sintonia --no-same-owner --keep-old-files
# Replace both public examples with the Terraform outputs, never secret values.
sudo bash /srv/sintonia/scripts/deploy.sh PUBLIC_IPV4 REGION-docker.pkg.dev/PROJECT/sintonia-images "$HOME/sintonia-stage/runtime.env"
# After a successful deployment remove only the temporary transferred configuration:
rm -- ~/sintonia-stage/runtime.envThe deploy script creates mode-600 runtime files, rejects credential/origin replacement, verifies resolved Compose without printing secrets, obtains a short-lived reader token from VM metadata, then pulls and starts services. Temporary Docker authentication is removed on exit. It never runs down, deletes volumes or exposes the admin token; retrieve the bootstrap token privately on the VM when needed and remove it from configuration after initial administrator setup.
For updates, back up first, extract the new public bundle into a separate staging directory and review diffs against /srv/sintonia, especially customized Caddy/Compose. Install only the reviewed public changes. Supply a private configuration file containing changed image/domain settings to deploy.sh, or omit its third argument to reuse the existing VM .env. Blank protected values preserve existing secrets; a different established credential, storage configuration or origin is refused. Keep project name sintonia-gcp and the fixed data paths. To deliberately disable an optional profile, edit the VM .env privately; blank incoming profiles preserve the existing selection. Restoring an older application image may require a database-compatible rollback strategy.
Documentation publication requires an explicit documentation profile, a versioned docs image and a reviewed Caddy virtual host forwarding the chosen domain to documentation:8080; the default Caddyfile does not publish it. Recording likewise requires explicit recording activation, a versioned recorder image and retained recording encryption credentials. Neither is enabled by provisioning.
Backups, restore and limitations#
Disk, static IP and repository use Terraform prevent_destroy; VM deletion protection is enabled. Removing protection or resource blocks is an operator migration decision, not an update procedure. Disk snapshots are retained if the source disk is deleted, but are crash-consistent, not coordinated database/object backups. See snapshot schedules.
Maintain encrypted off-VM, access-controlled backups of the database (logical PostgreSQL backup), RustFS objects, uploads, /srv/sintonia/.env, .secrets, instance identity/webhook keys and recording data/keys. Coordinate writes for a consistent recovery point; do not copy a live PostgreSQL data directory as a logical backup. Retention, separate failure domains and restoration drills remain operator responsibilities. Restore to a separate VM/disk, preserve the original credentials/origin, verify histories and media, then cut over DNS. Do not attach one writable disk to two running stacks or generate a new identity over restored data. Growing a cloud disk also requires an intentional ext4 filesystem expansion; no automatic shrink/format is performed.
No GCP account, billing, quotas, real boot, DNS/ACME, media connectivity, restore or capacity has been verified by the local checks. Region access and organization policies can prevent provisioning. This design has one zone/VM and needs external monitoring, capacity planning and a tested backup/recovery policy for production.
Local validation and CI#
From the infra checkout root:
python3 .ci/check_repository.py
python3 -m unittest discover -s gcp/scripts -p 'test_*.py'
terraform -chdir=gcp fmt -check -recursive
terraform -chdir=gcp init -backend=false -input=false -lockfile=readonly
terraform -chdir=gcp validate
terraform -chdir=gcp test
find gcp/scripts -name '*.sh' -exec bash -n {} \;Terraform tests use a mocked Google provider and plan only. Python tests use temporary synthetic settings and Compose rendering, without starting containers or reading operational environments. infra/CI.md runs these checks without cloud credentials, publication or deployment.