From e7476d916dfab33cc3b4b4ca3f042e300835e2d7 Mon Sep 17 00:00:00 2001 From: Koen Date: Wed, 28 Jun 2023 10:15:01 +0200 Subject: [PATCH] Added automatic deploy with cache purge. --- website/.gitlab-ci.yml | 4 +++- website/deploy.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 website/deploy.sh diff --git a/website/.gitlab-ci.yml b/website/.gitlab-ci.yml index 5226eb8..3267760 100644 --- a/website/.gitlab-ci.yml +++ b/website/.gitlab-ci.yml @@ -1,5 +1,7 @@ deployWebsite: stage: deployWebsite + before_script: + - cd website script: - - wrangler pages deploy website --project-name=fcast --branch=main + - sh deploy.sh when: manual \ No newline at end of file diff --git a/website/deploy.sh b/website/deploy.sh new file mode 100644 index 0000000..7495d08 --- /dev/null +++ b/website/deploy.sh @@ -0,0 +1,27 @@ +#!/bin/sh +DOCUMENT_ROOT=/var/www/fcast + +# Take site offline +echo "Taking site offline..." +touch $DOCUMENT_ROOT/maintenance.file + +# Swap over the content +echo "Deploying content..." +cp index.html $DOCUMENT_ROOT/ +cp privacy-policy.html $DOCUMENT_ROOT/ +cp favicon.png $DOCUMENT_ROOT/ +cp -r css $DOCUMENT_ROOT/ +cp -r images $DOCUMENT_ROOT/ +cp -r js $DOCUMENT_ROOT/ +cp -r vendor $DOCUMENT_ROOT/ + +# Notify Cloudflare to wipe the CDN cache +echo "Purging Cloudflare cache..." +curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/purge_cache" \ + -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ + -H "Content-Type: application/json" \ + --data '{"purge_everything":true}' + +# Take site back online +echo "Bringing site back online..." +rm $DOCUMENT_ROOT/maintenance.file \ No newline at end of file