From bd0793c1283ccb264ae4e7ec2d7fdd5aaab20727 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sat, 30 Mar 2019 13:19:02 +0100 Subject: [PATCH] purge Cloudflare cache upon live deployments --- README.md | 9 ++++++++- scripts/deploy.sh | 26 +++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 16ac769..d9643b9 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,14 @@ The deploy command simply calls the [`scripts/deploy.sh`](scripts/deploy.sh) scr npm run deploy ``` -The deploymeng script can be used locally too, the branch checks are only happening for Travis builds, allowing to deploy any branch from local machine. +Upon live deployment, deploy script also purges the Cloudflare cache, and pings search engines. Travis requires the following environment variables to be setup for successful deployments: + +- `AWS_ACCESS_KEY_ID` +- `AWS_SECRET_ACCESS_KEY` +- `AWS_DEFAULT_REGION` +- `CLOUDFLARE_EMAIL` +- `CLOUDFLARE_ZONE` +- `CLOUDFLARE_KEY` ## 🏛 Licenses diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 6259418..5d3b93e 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -30,6 +30,24 @@ function s3sync { --acl public-read } +# purge full Cloudflare cache +# https://api.cloudflare.com/#zone-purge-all-files +function purge { + curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/purge_cache" \ + -H "X-Auth-Email: $CLOUDFLARE_EMAIL" \ + -H "X-Auth-Key: $CLOUDFLARE_KEY" \ + -H "Content-Type: application/json" \ + --data '{"purge_everything":true}' +} + +# ping search engines +# returns: HTTP_STATUSCODE URL +function ping { + curl -sL -w "%{http_code} %{url_effective}\\n" \ + "http://www.google.com/webmasters/tools/ping?sitemap=$SITEMAP_URL" -o /dev/null \ + "http://www.bing.com/webmaster/ping.aspx?siteMap=$SITEMAP_URL" -o /dev/null +} + ## ## check for pull request against master ## @@ -44,11 +62,9 @@ elif [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] | s3sync $AWS_S3_BUCKET - # ping search engines - # returns: HTTP_STATUSCODE URL - curl -sL -w "%{http_code} %{url_effective}\\n" \ - "http://www.google.com/webmasters/tools/ping?sitemap=$SITEMAP_URL" -o /dev/null \ - "http://www.bing.com/webmaster/ping.aspx?siteMap=$SITEMAP_URL" -o /dev/null + purge + + ping echo "---------------------------------------------" echo " ✓ done deployment "