Hello, world: how this site is built
I’m Martin, a platform engineer in Ljubljana. I spend my days building developer platforms on Kubernetes and the cloud, and this is where I’ll write about that, and about the side projects I’m building.
Since infrastructure is my job, the first post is about the infrastructure of this site. The goal was simple: cheap, fast, and no clicking around in dashboards.
The stack
| Piece | Choice | Cost |
|---|---|---|
| Site | Astro, Markdown posts | free |
| Hosting | Cloudflare Pages | free |
| Infrastructure | OpenTofu, state in Cloudflare R2 | free |
| Deploys | GitHub Actions | free |
| Domain | bergamasco.dev via Cloudflare Registrar |
~$12/year |
The whole thing costs the price of the domain.
Everything in code
Apart from buying the domain and creating the bucket that holds the state, every Cloudflare resource is declared in OpenTofu: the Pages project, the custom domain, the DNS record and Web Analytics.
resource "cloudflare_pages_project" "blog" {
account_id = var.account_id
name = "blog"
production_branch = "main"
}
resource "cloudflare_dns_record" "apex" {
zone_id = data.cloudflare_zone.site.id
name = var.domain
type = "CNAME"
content = cloudflare_pages_project.blog.subdomain
proxied = true
ttl = 1
}
State lives in an R2 bucket through the S3 backend. A small OpenTofu nicety: since 1.8 the backend block can use variables, so the account-specific R2 endpoint doesn’t have to be hard-coded.
Secrets in the repo, encrypted
I wanted the secrets next to the code, so they’re encrypted with SOPS and age. There are two files and two keys:
creation_rules:
# Deploy token only (Pages: Edit), so CI can decrypt it
- path_regex: ^\.github/deploy\.enc\.env$
age: [*me, *ci]
# OpenTofu admin token + R2 state keys: never readable by CI
- path_regex: ^infra/secrets\.enc\.env$
age: [*me]
CI holds its own age key and can only decrypt a token that uploads to Pages. The token that can touch DNS never leaves my machine. Secrets reach the tools as environment variables and are never written to disk:
sops exec-env infra/secrets.enc.env 'tofu apply'
Deploys
A push to main builds the site and uploads it with wrangler pages deploy. Any other branch gets its own preview URL.
What’s next
Posts about platform engineering, and write-ups of a couple of side projects once they’re ready to show.