diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ed066fba4730877c4166c84810501b32a3fd6e16..9210749186fdb6cd4258af78992f9354e24f9934 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -71,26 +71,28 @@ pages:
- if: $CI_COMMIT_BRANCH == 'custom-domain'
# Purge all of this site's URLs from the Cloudflare cache
-purge-cache:
- stage: .post
+create-purge-json:
+ stage: deploy
+ needs: ['pages']
tags:
- docker
- rules:
- - if: $CF_PURGE_CACHE_ZONE && $CF_PURGE_CACHE_TOKEN
script:
- >-
- FILES="{ \"files\": [\"$CI_PAGES_URL/\"";
- for d in $(find public/* -type d); do FILES="$FILES,\"$CI_PAGES_URL/${d#public/}/\""; done;
- for f in $(find public -type f); do FILES="$FILES,\"$CI_PAGES_URL/${f#public/}\""; done;
- FILES="$FILES] }"
- - echo $FILES
- - sleep 180s # Give pages:deploy time to finish so the old pages don't get re-cached
- - >-
- wget -qO- "https://api.cloudflare.com/client/v4/zones/$CF_PURGE_CACHE_ZONE/purge_cache"
- --header "Content-Type: application/json"
- --header "Authorization: Bearer $CF_PURGE_CACHE_TOKEN"
- --post-data "$FILES"
+ echo -en "{\n \"files\": [\n \"$CI_PAGES_URL/\"" > purge.json;
+ for d in $(find public/* -type d); do echo -en ",\n \"$CI_PAGES_URL/${d#public/}/\"" >> purge.json; done;
+ for f in $(find public -type f); do echo -en ",\n \"$CI_PAGES_URL/${f#public/}\"" >> purge.json; done;
+ echo -e "\n ]\n}" >> purge.json
+ - cat purge.json
+ artifacts:
+ paths:
+ - purge.json
+trigger-cache-purge:
+ stage: .post
+ trigger:
+ include: purge-cache.gitlab-ci.yml
+ variables:
+ PARENT_PIPELINE_ID: $CI_PIPELINE_ID
# vi: set ts=2 sw=2 et ft=yaml:
diff --git a/purge-cache.gitlab-ci.yml b/purge-cache.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..cfe4a2417724684e9b0c96d97925c1ca6b72ab98
--- /dev/null
+++ b/purge-cache.gitlab-ci.yml
@@ -0,0 +1,25 @@
+# Purge the Cloudflare cache using the request body contained in purge.json
+#
+# We delay this job to give the pages:deploy job time to finish. If we don't
+# delay, then the cache might refill with old pages before the new pages are
+# finished deploying.
+purge-cache:
+ tags:
+ - docker
+ rules:
+ - if: $CF_PURGE_CACHE_ZONE && $CF_PURGE_CACHE_TOKEN
+ when: delayed
+ start_in: 3 minutes
+ needs:
+ - pipeline: $PARENT_PIPELINE_ID
+ job: create-purge-json
+ script:
+ - cat purge.json
+# - >-
+# wget -qO- "https://api.cloudflare.com/client/v4/zones/$CF_PURGE_CACHE_ZONE/purge_cache"
+# --header "Content-Type: application/json"
+# --header "Authorization: Bearer $CF_PURGE_CACHE_TOKEN"
+# --post-file purge.json
+
+
+# vi: set ts=2 sw=2 et ft=yaml: