Cache for a longer time on Fastly
This commit is contained in:
parent
9de8545875
commit
c348c23da5
|
@ -28,11 +28,8 @@ if ! command -v "s3cmd" >/dev/null 2>&1; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get the parent directory of where this script is and change into our website
|
# Get the parent directory of where this script is and cd there
|
||||||
# directory
|
DIR="$(cd "$(dirname "$(readlink -f "$0")")/.." && pwd)"
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
|
||||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
|
||||||
DIR="$(cd -P "$( dirname "$SOURCE" )/.." && pwd)"
|
|
||||||
|
|
||||||
# Delete any .DS_Store files for our OS X friends.
|
# Delete any .DS_Store files for our OS X friends.
|
||||||
find "$DIR" -type f -name '.DS_Store' -delete
|
find "$DIR" -type f -name '.DS_Store' -delete
|
||||||
|
@ -51,6 +48,9 @@ if [ -z "$NO_UPLOAD" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Set browser-side cache-control to ~4h, but tell Fastly to cache for much
|
||||||
|
# longer. We manually purge the Fastly cache, so setting it to a year is more
|
||||||
|
# than fine.
|
||||||
s3cmd \
|
s3cmd \
|
||||||
--quiet \
|
--quiet \
|
||||||
--delete-removed \
|
--delete-removed \
|
||||||
|
@ -59,6 +59,7 @@ if [ -z "$NO_UPLOAD" ]; then
|
||||||
--acl-public \
|
--acl-public \
|
||||||
--recursive \
|
--recursive \
|
||||||
--add-header="Cache-Control: max-age=14400" \
|
--add-header="Cache-Control: max-age=14400" \
|
||||||
|
--add-header="x-amz-meta-surrogate-control: max-age=31536000" \
|
||||||
--add-header="x-amz-meta-surrogate-key: site-$PROJECT" \
|
--add-header="x-amz-meta-surrogate-key: site-$PROJECT" \
|
||||||
sync "$DIR/build/" "s3://hc-sites/$PROJECT/latest/"
|
sync "$DIR/build/" "s3://hc-sites/$PROJECT/latest/"
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ if [ -z "$NO_UPLOAD" ]; then
|
||||||
modify "s3://hc-sites/$PROJECT/latest/"
|
modify "s3://hc-sites/$PROJECT/latest/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Perform a soft-purge of the surrogate key.
|
# Perform a purge of the surrogate key.
|
||||||
if [ -z "$NO_PURGE" ]; then
|
if [ -z "$NO_PURGE" ]; then
|
||||||
echo "Purging Fastly cache..."
|
echo "Purging Fastly cache..."
|
||||||
curl \
|
curl \
|
||||||
|
@ -102,13 +103,19 @@ if [ -z "$NO_PURGE" ]; then
|
||||||
--request "POST" \
|
--request "POST" \
|
||||||
--header "Accept: application/json" \
|
--header "Accept: application/json" \
|
||||||
--header "Fastly-Key: $FASTLY_API_KEY" \
|
--header "Fastly-Key: $FASTLY_API_KEY" \
|
||||||
--header "Fastly-Soft-Purge: 1" \
|
|
||||||
"https://api.fastly.com/service/$FASTLY_SERVICE_ID/purge/site-$PROJECT"
|
"https://api.fastly.com/service/$FASTLY_SERVICE_ID/purge/site-$PROJECT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Warm the cache with recursive wget.
|
# Warm the cache with recursive wget.
|
||||||
if [ -z "$NO_WARM" ]; then
|
if [ -z "$NO_WARM" ]; then
|
||||||
echo "Warming Fastly cache..."
|
echo "Warming Fastly cache..."
|
||||||
|
echo ""
|
||||||
|
echo "If this step fails, there are likely missing or broken assets or links"
|
||||||
|
echo "on the website. Run the following command manually on your laptop, and"
|
||||||
|
echo "search for \"ERROR\" in the output:"
|
||||||
|
echo ""
|
||||||
|
echo "wget --recursive --delete-after https://$PROJECT_URL/"
|
||||||
|
echo ""
|
||||||
wget \
|
wget \
|
||||||
--recursive \
|
--recursive \
|
||||||
--delete-after \
|
--delete-after \
|
||||||
|
|
Loading…
Reference in New Issue