1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-12-22 09:13:19 +01:00

purge Cloudflare cache upon live deployments

This commit is contained in:
Matthias Kretschmann 2019-03-30 13:19:02 +01:00
parent 2791d28ac6
commit bd0793c128
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 29 additions and 6 deletions

View File

@ -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

View File

@ -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 "