#!/bin/bash set -x set -e source scripts/config.sh || exit 1 SITE_FOLDER="dist" # Setup the website aws s3 website "s3://$S3_BUCKET" \ --index-document "$INDEX_DOCUMENT" \ --error-document "$ERROR_DOCUMENT" # Upload the raw files aws s3 sync \ --acl public-read \ --sse \ --delete \ "$SITE_FOLDER" "s3://$S3_BUCKET" # Copy all *.html files to proper locations using a trimmed filename and proper content-type. find "$SITE_FOLDER" -type f ! -iname 'index.html' -iname '*.html' -print0 | while read -d $'\0' f; do # mkdir -p "${f%.html}" # mv "$f" "${f%.html}/index.html" NAME=${f#*/} NAME_WITHOUT_EXTENSION=${NAME%.html} echo "Uploading $f as s3://$S3_BUCKET/$NAME_WITHOUT_EXTENSION" aws s3 cp \ "$f" \ "s3://$S3_BUCKET/$NAME_WITHOUT_EXTENSION" \ --content-type "text/html" \ --metadata-directive REPLACE done # Add cache-control headers for poster images # This instructs s3/cloudfront to send Cache-Control headers. aws s3 cp \ "s3://$S3_BUCKET/img/headers/" \ "s3://$S3_BUCKET/img/headers/" \ --metadata-directive REPLACE \ --recursive \ --cache-control max-age=31536000 # Update content types of shell scripts aws s3 cp \ "s3://$S3_BUCKET/scripts/" \ "s3://$S3_BUCKET/scripts/" \ --content-type "text/plain" \ --metadata-directive REPLACE \ --recursive \ --exclude "*" \ --include "*.sh" # Update content types of shell scripts aws s3 cp \ "s3://$S3_BUCKET/scripts/" \ "s3://$S3_BUCKET/scripts/" \ --content-type "text/plain" \ --metadata-directive REPLACE \ --recursive \ --exclude "*" \ --include "*.sh" # Add cache-control headers for astro resource dir since they're cached aws s3 cp \ "s3://$S3_BUCKET/_assets/" \ "s3://$S3_BUCKET/_assets/" \ --metadata-directive COPY \ --recursive \ --cache-control max-age=31536000 \ --metadata cache-control=max-age=31536000,upload-date=$(date +%s) # Invalidate Edge Caches aws cloudfront create-invalidation \ --distribution-id "$DISTRIBUTION_ID" \ --paths /\*