Artefact Upload Patterns
How a build’s output reaches its origin — wipe-and-replace, delete-aware sync, and append-only releases, each with an ordering, a failure story, and a verification step.
- Kind
- Orchestration
- Domain
- Build & Delivery
- Applies at
public/- Status
- Stable
- Source
scripts/deploy.sh
01 Defines
The family of patterns that move a build’s output files onto an origin so the published tree matches the build exactly: changed files are replaced, removed files disappear, and readers never see a mix of old and new.
02 Applies when
- A build produces a tree of files that must reach an origin exactly as built.
- Files removed from the build must disappear from the published site, not linger until someone cleans them.
- The same publish must run from a laptop and from CI against the same state.
03 Boundaries
- Uploading moves bytes; building them, provisioning the origin, and caching at the edge are separate steps.
- Coordinates and credentials come from the deployment’s own outputs and the environment, never from the script.
- Versioned package repositories that append releases rather than replace a tree are a different problem.
Expected behaviour
- 01The upload starts from a clean origin, so a file removed from the build cannot survive the publish.
- 02Files upload one at a time; the storage API creates parent paths as it goes.
- 03Any unexpected response fails the run loudly instead of silently leaving a partial tree.
- 04The CDN is purged after the upload, and the published address is verified from the outside.
- 05A repeat publish of the same build converges on the same published state.
Behaviour#
A build produces a fresh tree; publishing is the problem of making the origin match it. Three questions decide which pattern fits: is the published thing one current tree or a history of releases, what must happen to files the new build no longer contains, and how do readers get moved from old bytes to new ones without ever seeing a mix.
This repository publishes a current tree — public/, the output of
Static Websites
— to a Bunny.net storage zone behind a pull
zone CDN. Its answer to the three questions is wipe and replace: empty the
origin, upload every file of the new build, purge the CDN, verify from
outside. The whole sequence is one command, make deploy, driven by
Static Site Delivery
.
-
01
Build
make check.hugorenderspublic/ - 02 Provision Terraform applies the sandbox root and its coordinates are read from the module output
-
03
Wipe
DELETEon the zone root — 200, 400, and 404 all mean “empty” -
04
Upload
One
PUTper file in sorted order; parent paths are created as it goes -
05
Purge
POSTthe pull zone purge, so edges stop serving the previous build - 06 Verify CI polls the published address until it answers 200
Wipe and replace#
The pattern exists because the storage API has no delete-aware sync: a page removed from the build would linger at the origin until something removed it. Wiping the zone root first makes deletion part of the publish itself.
The wipe is a single DELETE request. The API answers 200 for an emptied
zone, 404 for one that was already empty, and 400 in some edge states — all
three mean “nothing left”, so all three count as success. Anything else is a
failed publish.
The upload is deliberately one file at a time: one PUT per file, the
storage password as an AccessKey header, --data-binary for exact bytes,
and 201 as the success code. There is no batching to track and no
parent-directory bookkeeping, because the API creates paths as files arrive.
Files go up in sorted order, so the sequence is deterministic and a rerun
prints the same story.
A failed PUT exits immediately, naming the file and the unexpected status.
The zone may hold a partial tree after a failed publish — the run is red, and
the next green publish wipes and replaces it. What the pattern refuses is the
opposite failure: an upload that pretends to succeed while dropping files.
Delete-aware sync#
For origins that can compare source and destination — S3 and its relatives —
the same job can be a single aws s3 sync --delete pass. The tool uploads
changed files, skips identical ones, and deletes keys the build no longer
contains. It scales better than wipe-and-replace for large trees, because
identical files cost nothing and only the diff moves.
The trap is the filter: sync’s --exclude and --include apply to the
destination as well as the source, so a --delete behind a filter removes
everything outside it. The safe forms are an unfiltered delete, or two passes
with deletion left to the one that sees the whole tree — the shape described
by
Fingerprinted Cache Tiers
.
Append-only releases#
The opposite shape suits versioned artefacts instead of a current tree: each release is uploaded under a content-hashed or versioned name and nothing is ever deleted. History is preserved, a rollback is a pointer to an older name, and concurrent publishes cannot corrupt each other.
What the pattern gives up is the notion of “the current site”. Nothing in it answers what the live address should serve, which is why it backs release archives and package registries rather than a website origin.
Verification is part of the upload#
“Uploaded” only means the origin holds the bytes; readers meet them at the edge. The purge that follows the upload propagates asynchronously, so CI polls the published address after every publish — twelve attempts, five seconds apart — and fails the run if it never answers 200. A publish without that check can go green while readers still see the previous build.
The same steps run from a laptop and from CI against the same Terraform state. Provisioning is idempotent — a repeat apply reports no changes — and the publish is repeatable, so “deploy again” is the recovery for any interrupted run.
Examples#
The wipe and the upload loop from this repository’s deploy script:
# Wipe the zone root before uploading, so a removed page is gone from the
# site rather than lingering until a manual clean. The API answers 200 for an
# emptied zone, 404 for one already empty, and 400 in some edge states.
status="$(curl -sS -o /dev/null -w '%{http_code}' \
-X DELETE "https://$host/$zone/" -H "AccessKey: $password")"
[ "$status" = "200" ] || [ "$status" = "400" ] || [ "$status" = "404" ] || {
printf 'error: wiping the storage zone failed (HTTP %s)\n' "$status" >&2
exit 1
}
# One PUT per file; the storage API creates parent paths as it goes and
# answers 201 on success.
count=0
while IFS= read -r file; do
rel="${file#public/}"
status="$(curl -sS -o /dev/null -w '%{http_code}' \
-X PUT "https://$host/$zone/$rel" -H "AccessKey: $password" \
--data-binary "@$file")"
[ "$status" = "201" ] || {
printf 'error: uploading %s failed (HTTP %s)\n' "$rel" "$status" >&2
exit 1
}
count=$((count + 1))
done < <(find public -type f | sort)
printf 'uploaded %s files\n' "$count"
Locally, the whole publish runs through the vault so the API key is never set by hand:
secrets exec -- make deploy
Connections