Deployment

Deployment

Deploying production is five steps, and make deploy ENV=prod is all five:

  1. Build the Hugo site into public/.
  2. terraform init, with a backend key derived from this repository’s own identity.
  3. terraform apply — provisions the Bunny Storage zone, CDN pull zone, DNS record, and TLS hostname.
  4. Upload public/ to the storage zone.
  5. Purge the CDN.

That is the whole deployment model. It lives in scripts/deploy.sh and scripts/publish-bunny.sh, which are short enough to read before you run them.

Environments

Two Terraform roots, both served from Bunny.net.

ENVRootInstance
workspaceworkspaces/site/Your own sandbox copy (the default)
prodenv/prod/releaseProduction
make deploy                 # your own copy
make deploy ENV=prod

make deploy.plan            # preview, changes nothing
make deploy.destroy         # tear the instance down

workspace is the default so a bare make deploy can only touch your own copy, never production.

Your own copy

workspaces/site names each instance after the active Terraform workspace, which scripts/deploy.sh derives from your username locally or the branch name in CI. Each instance gets its own storage zone, pull zone, and hostname under the estate’s shared Bunny DNS sandbox zone:

iconsurfacedsc-<workspace>.sandbox002.dev.prosyon.ca

Override the workspace name with DEPLOY_WORKSPACE if you want more than one. Instances are disposable — make deploy.destroy removes everything. It has nothing to do with how production is served.

A state key of your own

Every Terraform root’s backend omits key: scripts/deploy.sh supplies it at terraform init time, derived from this repository’s own forge identity (scripts/derive-repo-identity.sh), not typed in by hand. The script reads GITEA_REPOSITORY in CI, or the origin git remote locally — both already set correctly the moment this repository exists, so no file needs editing for a repository made from this template to get a state key that is its own. It refuses to guess, rather than silently falling back to a key another repository could also fall back to, when it finds neither.

Prerequisites

A Terraform state bucket. Both roots commit their backend, pointing at one encrypted bucket, regardless of which provider each root deploys to:

aws s3api create-bucket --bucket org-terraform-state-220087710539 \
  --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2
aws s3api put-bucket-versioning --bucket org-terraform-state-220087710539 \
  --versioning-configuration Status=Enabled
aws s3api put-bucket-encryption --bucket org-terraform-state-220087710539 \
  --server-side-encryption-configuration \
  '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'

An existing Bunny DNS zone. env/prod/release provisions iconsurfacedsc.aureliasrs.ca as a record inside the existing aureliasrs.ca Bunny DNS zone; workspaces/site provisions its instance as a record inside the existing sandbox002.dev.prosyon.ca zone. Both look the zone up by name and neither creates it.

Credentials. Both roots read BUNNYNET_API_KEY from the environment — the estate’s ambient Bunny.net account key, supplied through the vault in CI and already present in the devcontainer locally. The backend needs AWS credentials too, for state only, which CI gets from infrastructure/setup-aws-credentials and the devcontainer gets from its ambient default profile.

Publishing and cache invalidation

scripts/publish-bunny.sh uploads every non-HTML asset first, then HTML pages other than the root index.html, then index.html last, so an in-flight reader never sees a page before the assets it references. It then purges the whole pull zone with one call to /pullzone/<id>/purgeCache.

This is not an atomic release switch, and it does not delete anything: a file removed from the build stays reachable on the CDN until something purges or removes it directly from the storage zone.

Continuous integration

Every pull request lints, builds, and validates. An ordinary push to main never deploys. Production is reached only by a manual dispatch with operation: apply.

Deployment is gated on the DEPLOYMENT_ENABLED repository variable; without it, no deployment step runs, and the workflow reports that deployment was skipped while staying green, so the source template’s default branch is never red for a variable only an instantiated copy is expected to set.

Recovery

Certificate issuance fails on a fresh apply. Bunny can reject the managed certificate until the new DNS record has propagated across its own network. The module waits 30 seconds for this before requesting the certificate; if it still fails, confirm the record exists in Bunny DNS, then re-run make deploy.

Stale content after a deploy. Confirm the purge actually ran — it is the last step of scripts/publish-bunny.sh — and that no browser cached the old HTML; Bunny purging the edge cannot invalidate a browser’s own cache.

Rolling back. Check out the previous commit and run make deploy again. Nothing is deleted from the storage zone automatically, so a prior deploy’s assets remain reachable even if a later page references ones that are gone.