Static Site Delivery
make deploy is the whole deployment model: build the site, provision the Bunny.net sandbox, publish public/ to its storage zone, and purge the CDN — with CI verifying the published address afterwards.
- Kind
- Orchestration
- Domain
- Build & Delivery
- Applies at
scripts/deploy.sh- Status
- Stable
- Source
scripts/deploy.sh
01 Defines
A single short script, reached through make deploy, that takes a static site from source to a live Bunny.net sandbox in five ordered steps: build, initialise and apply the Terraform root, publish with a wipe-and-replace upload, and purge the pull zone.
02 Applies when
- A repository publishes a static site to a Bunny.net storage zone behind a pull zone CDN.
- The same publish must run from a laptop and from CI against the same Terraform state.
- A page removed from the build must disappear from the site in the same deploy.
03 Boundaries
- The script runs the sandbox root; the infrastructure itself is defined by the published module the root composes.
- Coordinates and credentials come from the module’s outputs and the environment, never from the script.
- Building the site is delegated to
make check.hugo; the script does not know how Hugo is invoked.
Expected behaviour
- 01
make deploybuilds, provisions, publishes, and purges;deploy.plananddeploy.destroytouch infrastructure alone. - 02Provisioning is idempotent: a repeat apply against the same state reports no changes.
- 03The publish is a wipe-and-replace: the zone root is emptied, every file of
public/is uploaded, and the pull zone is purged. - 04The script reads its coordinates from
terraform output -json deploymentand prints the deployed URL on success. - 05Any unexpected upload or purge response fails the script loudly.
- 06CI verifies the published address answers 200 after the purge, and a run where any step fails is red.
Behaviour#
Deployment is five ordered steps, and make deploy is all five. They live in
one script that is short enough to read before running it, and the make
targets are one-line wrappers around its three subcommands.
-
01
Build
make check.hugorenders every site intopublic/Static Websites -
02
Init
terraform init -input=falseinenv/www - 03 Apply Provision the storage zone, pull zone, DNS, and TLS Pinned Module Composition
-
04
Publish
Wipe the zone root, then one
PUTper file inpublic/Artefact Upload Patterns -
05
Purge
POSTthe pull zone purge so edges drop the previous build
plan and destroy stop after init: plan prints the change set, and
destroy removes the sandbox, zone contents included. Only apply builds
and publishes — planning a deploy never uploads anything. CI adds one step
on top: it polls the published address until it answers 200, because the
purge propagates asynchronously and “uploaded” is not “served”.
The sandbox root#
env/www is the one deployable root. It composes the estate’s
static-website/bunnynet module at a pinned version, with the site’s domain
as its only input. The module’s deployment output carries the publishing
coordinates — storage hostname, zone, password, and pull zone id — so the
script reads them fresh each run and nothing is stored as a secret of its
own. See
Environments
for what the directory of deployable
roots is for.
Purging is safe for assets because their URLs are content-hashed: a fingerprinted file changes name when its content changes, so no reader can be pointed at stale bytes. The unhashed files — HTML above all — are exactly what the purge exists to refresh. See Fingerprinted Cache Tiers .
CI runs the same steps#
The workflow mirrors the script. Pull requests touching the site, the root,
or the workflow build with the sandbox baseURL and stop there — no
credentials, no publish, no contact with the sandbox. Pushes to main
additionally provision the root, publish the build with a wipe-and-replace
upload, purge, and then verify from the runner that the address answers 200;
a run where any of those fails is red.
The verify loop gives the purge time to propagate: twelve attempts, five seconds apart. “Uploaded” only means the origin holds the bytes; readers meet them at the edge, so the loop is the step that decides whether the deploy actually happened.
Examples#
The script’s apply path reads its coordinates from the module output and treats any unexpected response as failure:
deployment="$(terraform -chdir="$root" output -json deployment)"
host="$(printf '%s' "$deployment" | jq -r .storage_hostname)"
zone="$(printf '%s' "$deployment" | jq -r .storage_zone)"
password="$(printf '%s' "$deployment" | jq -r .storage_password)"
pullzone="$(printf '%s' "$deployment" | jq -r .pullzone_id)"
: "${BUNNYNET_API_KEY:?BUNNYNET_API_KEY is not set; run through the vault: secrets exec -- make deploy}"
Day to day, the make targets are the interface, always through the vault so the API key is never set by hand:
secrets exec -- make deploy # the whole publish
secrets exec -- make deploy.plan # preview infrastructure changes
secrets exec -- make deploy.destroy # tear the sandbox down
Rolling back is the same command run from an earlier commit: check it out and
make deploy again. The publish replaces the tree wholesale, so the previous
commit’s build comes back exactly as it was.
Connections
How Static Site Delivery relates to the library
Composed into
Relies on
- Artefact Upload Patterns How a build’s output reaches its origin — wipe-and-replace, delete-aware sync, and …
- Fingerprinted Cache Tiers Content-hashed CSS and JS are cached for a year as immutable; everything else is revalidated on …
- Pinned Module Composition Every deployable root composes the same published module at the same pinned version, so roots …
- Static Websites Each child of www/ is a self-contained site root whose content, layouts, assets, and …