#!/usr/bin/env bash # Build the site (web/scripts/build.sh) and push it to a ref-named path in # infra's site bucket. # # web/scripts/push.sh # # BUCKET overrides the bucket; the default is the name infra builds from # -web-bucket--, all of which are fixed. # # The push changes nothing the site serves. CloudFront serves whatever path # infra's site_origin_path points at; to serve this build, set that variable # to the path this script prints, apply, and invalidate the distribution # (infra's site_distribution_id output). set -euo pipefail BUCKET="${BUCKET:-lance-blue-web-bucket-prod-179302349187}" : "${AWS_PROFILE:?set AWS_PROFILE; default credentials are almost never the right account}" cd "$(dirname "$0")/../.." BUILD_REF="$(scripts/build-ref.sh)" export BUILD_REF prefix="releases/$BUILD_REF" web/scripts/build.sh cd web # Hashed assets never change under their names, so browsers may keep them # forever. Everything else keeps its URL across deploys and must not be # cached by browsers at all. aws s3 sync dist/assets "s3://$BUCKET/$prefix/assets" --delete \ --cache-control "public, max-age=31536000, immutable" aws s3 sync dist "s3://$BUCKET/$prefix" --delete --exclude "assets/*" \ --cache-control "no-cache" # CloudFront looks for index.html at the root and nowhere else, so every # prerendered page needs a second copy under the address the site links to: # dist/blog/index.html is also the key "blog". Skipping this does not produce a # missing page, it produces the wrong one - both 403 and 404 come back as the # app's own index.html with a 200. # # The content type has to be given. These keys have no extension for the CLI to # guess from, and what it guesses instead is a download. while IFS= read -r page; do key="${page#dist/}" aws s3 cp "$page" "s3://$BUCKET/$prefix/${key%/index.html}" \ --content-type "text/html; charset=utf-8" \ --cache-control "no-cache" done < <(find dist -mindepth 2 -name index.html) # The feed does have an extension, and what the CLI guesses from it is # application/xml. Readers take that, but it is not what the on every # page says the document is, and the two disagreeing is the sort of thing that # is only ever noticed by whichever reader is strict about it. if [ -f dist/atom.xml ]; then aws s3 cp dist/atom.xml "s3://$BUCKET/$prefix/atom.xml" \ --content-type "application/atom+xml; charset=utf-8" \ --cache-control "no-cache" fi # The same fix for the standard.site key, which has no extension either and # has to arrive as text rather than as a download. Absent until `sequoia init` # writes it, so this is a no-op until the publication record exists. wellknown="dist/.well-known/site.standard.publication" if [ -f "$wellknown" ]; then aws s3 cp "$wellknown" "s3://$BUCKET/$prefix/${wellknown#dist/}" \ --content-type "text/plain; charset=utf-8" \ --cache-control "no-cache" fi echo echo "Pushed to s3://$BUCKET/$prefix" echo "To serve it: set site_origin_path = \"/$prefix\" in infra, apply," echo "then invalidate CloudFront."