How This Site Is Deployed: from git push to Cloud Run in five minutes
A static Astro site, an nginx container, Cloud Run, Terraform and keyless GitHub Actions: every piece, why it was chosen, and what happens on each push.
The problem
A personal blog is a small project with an awkward set of requirements:
- It should cost close to nothing when nobody is reading it, which is most of the time.
- It should be boring to operate: no servers to patch, no certificates to renew.
- Publishing should be one action: merge to
mainand walk away. - And because I write about data and ML platforms, I wanted it to run on the same building blocks I use at work: containers, infrastructure as code, CI/CD with no long-lived secrets.
The usual answer is a static host (Netlify, Vercel, GitHub Pages). That works, but it hides every interesting part. This post walks through the setup this site actually uses, why each piece exists, and what happens between git push and the new page being live.
A VM you SSH into, rsync files onto, and patch by hand. It costs money 24/7, the TLS
certificate is your problem, and a JSON service-account key sits in CI forever.
A container that scales to zero, with TLS and HTTPS handled by Cloud Run. All infrastructure is declared in Terraform, and CI authenticates with short-lived tokens (no stored keys).
Real-world analogy
The key decision is that all the work happens at build time. Diagrams, syntax highlighting, social images and the resume PDF are all generated once, during the build. The server’s only job is to hand out files.
Architecture
A push to main triggers GitHub Actions, which builds the site, builds a container image, pushes it to Artifact Registry and deploys a new Cloud Run revision.
There are two clearly separated owners:
| Owner | Owns | Changes when |
|---|---|---|
| Terraform | APIs, Artifact Registry, Cloud Run service config, service accounts, IAM, WIF, budget alert | I change infrastructure |
| GitHub Actions | Which image the Cloud Run service runs | Every push to main |
This split matters. If both tools managed the image, every terraform apply would try to roll the service back to whatever image was in the Terraform config. The service resource therefore tells Terraform to ignore the image:
lifecycle {
ignore_changes = [
template[0].containers[0].image, # CI owns the image
client,
client_version,
]
}
The pieces
1. Astro builds static HTML. Posts are MDX files. At build time, Astro renders every page to HTML. Mermaid diagrams become inline SVG (rendered in headless Chromium), code is highlighted with Shiki, and Open Graph images are drawn with satori. Pages ship zero JavaScript unless they contain an interactive diagram, and then only that diagram is hydrated, when it scrolls into view.
2. nginx serves the files from a tiny container. The image is just nginx-unprivileged plus the dist/ folder:
FROM nginxinc/nginx-unprivileged:1.30.6-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY dist/ /usr/share/nginx/html/
EXPOSE 8080
The site is built outside the image. The build needs a headless browser, and keeping Chromium out of the Docker build keeps the runtime image small (around 60 MB) and the build fast. The unprivileged variant runs as a non-root user and listens on 8080, which is Cloud Run’s default port.
3. Cloud Run runs the container. It’s configured for a static site:
min_instance_count = 0: no traffic means no instances, which means (almost) no bill.cpu_idle = true: CPU is only allocated while a request is being handled.- 1 vCPU and 256 MiB, with up to 80 concurrent requests per instance: nginx serving files barely notices.
max_instance_count = 3: a cost guardrail in case a post goes viral or someone points a load test at it.
4. Terraform declares all of it. There are two stacks. A tiny bootstrap stack creates the GCS bucket that stores Terraform state (it can’t store its own state remotely, a chicken-and-egg problem). The main stack creates everything else and keeps its state in that bucket.
Walkthrough
Here is one push, end to end. Step through it or press play.
1/8A merge to main fires the Deploy workflow. A concurrency group makes sure two deploys never overlap.
All steps (text version)
- A merge to main fires the Deploy workflow. A concurrency group makes sure two deploys never overlap.
- The runner installs dependencies and headless Chromium (cached), then runs npm run build. The output is a dist/ folder of static files.
- The runner asks GitHub for an OIDC token, a signed JWT that says "repository X, branch main". It sends the token to Google, which checks the claims against the WIF provider.
- Google returns short-lived credentials for the deployer service account. They expire in about an hour, and no key is stored anywhere.
- The runner builds the nginx image, tags it with the commit SHA and pushes it to Artifact Registry.
- The runner asks Cloud Run for a new revision that uses the new image tag.
- Cloud Run pulls the image, starts the revision, waits for it to listen on port 8080, then moves 100% of traffic to it. The old revision stays around for instant rollback.
- A smoke test fetches /, /rss.xml and /resume.pdf from the live URL. If any fails, the workflow goes red.
Keyless auth, in more detail
Step 3 is the part most worth understanding, because it replaces the classic “paste a service-account JSON key into GitHub secrets” pattern.
GitHub issues an OIDC token, Google STS validates it against the provider's condition, then the runner impersonates the deployer service account.
The provider only trusts tokens whose claims match this repository and refs/heads/main:
attribute_condition = "assertion.repository == \"${var.github_repository}\" && assertion.ref == \"refs/heads/${var.deploy_branch}\""
A workflow on a feature branch, a pull request from a fork, or any other repository gets a valid GitHub token that Google simply rejects.
Least privilege for the deployer
Even with valid credentials, the deployer can do very little:
| Role | Scoped to | Why |
|---|---|---|
artifactregistry.writer |
the site repository |
push images |
run.developer |
the one Cloud Run service | deploy new revisions, but not change who can invoke |
iam.serviceAccountUser |
the runtime SA only | a revision runs as the runtime SA |
iam.workloadIdentityUser |
from the GitHub pool | lets the federated identity impersonate it |
The runtime service account itself has no roles at all. The container serves files and never calls a Google API.
Failure modes & trade-offs
Caching is split by how often content changes:
| Path | Cache-Control | Why |
|---|---|---|
HTML (/) |
no-cache |
revalidate, so a new deploy shows immediately |
/_astro/* |
public, max-age=31536000, immutable |
filenames contain a content hash |
/og/* |
public, max-age=86400 |
social images rarely change |
When not to do this. If you just want a blog online, a managed static host is less work, and that’s a perfectly good choice. This setup earns its keep when you want control over headers and caching, want to practice the same patterns you’d use for a real service, or plan to add a server-side component later (the container can grow into one without changing the pipeline).
Test yourself
Why use Workload Identity Federation instead of a service-account key in CI?easy
A JSON key is a long-lived secret: if it leaks (logs, a compromised action, a fork), it’s valid until someone notices and revokes it. With WIF, CI exchanges a short-lived, signed OIDC token for credentials that expire in about an hour, and you can restrict which repository and branch are trusted. There’s no secret to store or rotate.
Terraform and CI both touch the Cloud Run service. How do you stop them fighting?medium
Give each a clear area of ownership. Terraform owns configuration (scaling, resources, IAM); CI
owns the image. In Terraform, lifecycle.ignore_changes on the image field means terraform apply never reverts a deploy, and CI’s deploy never touches the config Terraform manages.
What does `min_instances = 0` trade away, and when would you change it?medium
It trades latency for cost: the service costs nothing when idle, but the first request after an idle period pays a cold start. Raise it to 1 or more for latency-sensitive services, or when startup is slow (large images, JVM warm-up, model loading).
Why build the site outside the Docker image?hard
The build needs headless Chromium (Mermaid diagrams, resume PDF). Building inside a multi-stage
Dockerfile would work but makes image builds slow and couples them to a browser install. Building
on the runner (with a cached browser) and copying only dist/ into an nginx image keeps the image
small and the artifact identical to what CI tested. The trade-off: the image depends on a
pre-built dist/ being present, so a bare docker build on a clean checkout fails.