Deploy to GCP Cloud Run

Cloud Run is a fully managed container platform that scales automatically. Gothic's GCP target runs on gothic deploy: one command provisions the stack through OpenTofu, builds the container, pushes it to Artifact Registry and deploys it. It uses your gcloud CLI credentials (ADC), so install gcloud and run gcloud auth application-default login first.

The stack provisions GCP services only: no third-party cache or storage is wired in. There is no Memorystore and no external Redis, and gothic.REDIS on GCP is a config error. The cloud's own centralized cache is Cloud CDN, available on the Load Balancer profile below.

Two serving profiles

Deploy.Providers.GCP.Serving picks how the site is served. The config load enforces which cache and static-file choices each profile can deliver:

Here is a gothic.config.go with the GCP block. The three Server* fields are written into the stack explicitly either way: the zero value means the platform minimum (512 MiB, 1 vCPU, 60 s), never a silent default.

import gothic "github.com/gothicframework/core/config"

var Config = gothic.Config{
	ProjectName: "my-app",
	Runtime: gothic.RuntimeConfig{
		CacheStrategy:    gothic.IN_MEMORY,   // Basic profile: per instance
		ServeStaticFiles: gothic.DISK,        // or gothic.EMBEDDED
	},
	Deploy: &gothic.DeployConfig{
		Target: gothic.GCP,
		Providers: gothic.Providers{
			GCP: gothic.GCPProvider{
				Project:       "my-app-prod",
				Region:        "southamerica-east1",
				Serving:       gothic.GCPCloudRunBasic, // or gothic.GCPCDNWithLoadBalancer
				ServerMemory:  1024,                    // MiB; 0 = platform minimum 512
				ServerCPUs:    2,                       // vCPUs; 0 = platform minimum 1
				ServerTimeout: 30,                      // s; 0 = platform minimum 60
				DNSZone:       "example-com",           // optional: a Cloud DNS zone you own
				Stages: map[string]gothic.GCPStage{
					"dev": {
						CustomDomain: gothic.Env("app.example.com"), // optional (required with the Load Balancer profile)
						ENV: map[string]gothic.EnvValue{
							"TABLE_NAME": gothic.Env("my-app-dev-items"),              // raw literal
							"API_KEY":    gothic.SecretsManager("my-app-dev-api-key"), // GCP Secret Manager: name only
						},
					},
				},
			},
		},
	},
}

Custom domains and DNS

On the Basic profile, a stage CustomDomain provisions a Cloud Run domain mapping with a Google-managed TLS certificate. On the Load Balancer profile, the certificate is issued for the stage domain and DNS points at the load balancer's reserved IP.

Stage ENV values are either raw gothic.Env("literal") values or gothic.SecretsManager("secret-name") entries, which name a secret in the deploy project's Secret Manager. The config carries only the name: Cloud Run reads the latest version at runtime, and the deploy grants the runtime service account roles/secretmanager.secretAccessor on the secret. Pass the bare secret name; a path, a version and .Get(...) are AWS forms that fail loudly here. gothic.SSMParam is AWS-only. A custom domain must be a raw value because the domain mapping takes no secret reference.

Important: Cloud Run domain mappings are a Preview API and are not accepted in every region. Where Google refuses them, the deploy fails with "Creating domain mappings is not allowed". Deploy a basic stage with a domain to us-central1, us-east1, us-east4, us-west1, europe-north1, europe-west1, europe-west4, asia-east1, asia-northeast1 or asia-southeast1, or serve that stage at its run.app URL.

Security Note: create the secret in Secret Manager before the deploy. The value never enters gothic.config.go or the OpenTofu state; rotate it in Secret Manager and redeploy to roll the new version.

Set DNSZone to a Cloud DNS zone you already own (in the same project) and the deploy writes the serving record itself. On the Load Balancer profile that is an A record at the load balancer IP. On the Basic profile it is the mapping's own apex A/AAAA records or its CNAME target, read from the mapping itself (Google dictates the exact record set for your domain shape). The zone is yours: Gothic never creates a zone or touches nameservers, and --action delete removes the record it wrote. Leave it empty when DNS lives outside Cloud DNS: the outputs tell you what to point where.

What a deploy finishes with

gothic deploy finishes only when the site URL actually answers over HTTPS. Google provisions the certificates asynchronously, so the deploy holds with a progress line every 30 seconds. "Deploy complete" means the site is live, the same promise the AWS path makes. Ctrl+C stops the wait; the resources are created either way. Changing a stage's CustomDomain is just a redeploy: the certificate is re-issued under a domain-keyed name and the edge keeps the same reserved IP.

Every GCP deploy also stamps its asset URLs with the build version: the stylesheet link and the per-page WASM fetch carry ?v=<build>. A redeploy that changes CSS or WASM changes the URL, so a plain browser reload shows the new content. Pages carry a revalidating Cache-Control: max-age=0, must-revalidate while the edge caches behind s-maxage, and stamped assets are served immutable as long as their URL exists. Targets that never inject the stamp (AWS, Binary, dev) keep their plain URLs and legacy headers.

On the Load Balancer profile, the run.app URL intentionally serves 404: the service's ingress setting accepts only load balancer traffic, so everything arrives through the edge you control. The deploy also invalidates the edge at the end of every deploy, so changed assets and ISR pages appear immediately. It prints the fixed costs and teardown instructions. The forwarding rule bills while standing: test, then --action delete.

gothic deploy --action deploy --stage dev   # provision / update
gothic deploy --action delete --stage dev   # tear the stack down

# The Load Balancer profile invalidates the edge at the end of every deploy:
# gcloud compute url-maps invalidate-cdn-cache <url_map> --path=/*

Important: a delete removes the stack but leaves the OpenTofu state bucket and the stage's GAR repository behind (they are per-project/per-stage). When retiring a project entirely, remove them with gcloud storage rm -r gs://<bucket> and gcloud artifacts repositories delete <repo> --location=<region>.

Ready to configure your deploys?