1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2025-02-14 21:10:41 +01:00

Merge pull request #105 from kremalicious/feature/cache-purge

purge Cloudflare cache upon live deployments
This commit is contained in:
Matthias Kretschmann 2019-03-30 13:34:30 +01:00 committed by GitHub
commit 4f5dbd939e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 "