Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • gitlab-tests/pages-test
  • gitlab-tests/subgroup-1/pages-test
  • gitlab-tests/subgroup-1/subgroup-1.1/pages-test
3 results
Select Git revision
Show changes
Commits on Source (7)
...@@ -38,9 +38,10 @@ setup: ...@@ -38,9 +38,10 @@ setup:
- echo $ROOT_RELATIVE_NAMESPACE - echo $ROOT_RELATIVE_NAMESPACE
- test "$ROOT_RELATIVE_NAMESPACE" == "${CI_PROJECT_NAMESPACE#$CI_PROJECT_ROOT_NAMESPACE}" || { echo "ROOT_RELATIVE_NAMESPACE is not set correctly" ; exit 1 ; } - test "$ROOT_RELATIVE_NAMESPACE" == "${CI_PROJECT_NAMESPACE#$CI_PROJECT_ROOT_NAMESPACE}" || { echo "ROOT_RELATIVE_NAMESPACE is not set correctly" ; exit 1 ; }
script: script:
- find src/ -type f -name '*.html' - find src/ -type f \( -iname '*.html' -or -iname 'sitemap.xml' \)
-exec sed -i -exec sed -i
-e "s|%%BRANCH%%|${CI_COMMIT_BRANCH}|g" -e "s|%%BRANCH%%|${CI_COMMIT_BRANCH}|g"
-e "s|%%BASE_URL%%|${CI_PAGES_URL}|g"
-e "s|%%COMMIT_SHA%%|${CI_COMMIT_SHORT_SHA}|g" -e "s|%%COMMIT_SHA%%|${CI_COMMIT_SHORT_SHA}|g"
-e "s|%%COMMIT_TIMESTAMP%%|${CI_COMMIT_TIMESTAMP}|g" -e "s|%%COMMIT_TIMESTAMP%%|${CI_COMMIT_TIMESTAMP}|g"
-e "s|%%JOB_ID%%|${CI_JOB_ID}|g" -e "s|%%JOB_ID%%|${CI_JOB_ID}|g"
...@@ -71,8 +72,13 @@ pages: ...@@ -71,8 +72,13 @@ pages:
rules: rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Purge all of this site's URLs from the Cloudflare cache # Create a list of URLs that need to be purged from the cache after GitLab Pages
create-purge-json: # deployment. Each real file/directory has multiple URLs because the router for
# GitLab Pages fudges paths for better user experience. The fudging rules are:
# - Directories can be accessed with or without a trailing slash
# - Files can be accessed with or without a trailing slash
# - Files with the '.html' extension can be accessed with or without .html
create-purge-list:
stage: deploy stage: deploy
rules: rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
...@@ -80,31 +86,27 @@ create-purge-json: ...@@ -80,31 +86,27 @@ create-purge-json:
tags: tags:
- docker - docker
script: script:
# Add the index-less homepage
- echo "$CI_PAGES_URL" > purge-list.txt
# Add all the HTML files and HTML symlinks, with and without .html extension
- |- - |-
echo -en "{\n \"files\": [" > purge.json for f in $(find public/* \( -type f -or -type l \) -iname '*.html'); do
# Add the index-less homepage, with and without trailing slash f="${f#public/}"
echo -en "\n \"$CI_PAGES_URL\"" >> purge.json echo "$CI_PAGES_URL/$f" >> purge-list.txt
echo -en ",\n \"$CI_PAGES_URL/\"" >> purge.json echo "$CI_PAGES_URL/${f%.html}" >> purge-list.txt
# Add all the directories, non-HTML files and non-HTML symlinks; with and
# without trailing slash
for f in $(find public \( -type d -or -type f -or -type l \) -not -iname '*.html'); do
echo -en ",\n \"$CI_PAGES_URL/${f#public/}\"" >> purge.json
echo -en ",\n \"$CI_PAGES_URL/${f#public/}/\"" >> purge.json
done done
# Add all the HTML files and HTML symlinks, with and without trailing # Add everything else
# slash. First with file extension, then without - |-
for f in $(find public \( -type f -or -type l \) -iname '*.html'); do for f in $(find public/* \( -type d -or -type f -or -type l \) -not -iname '*.html'); do
echo -en ",\n \"$CI_PAGES_URL/${f#public/}\"" >> purge.json echo "$CI_PAGES_URL/${f#public/}" >> purge-list.txt
echo -en ",\n \"$CI_PAGES_URL/${f#public/}/\"" >> purge.json
f="${f%.html}"
echo -en ",\n \"$CI_PAGES_URL/${f#public/}\"" >> purge.json
echo -en ",\n \"$CI_PAGES_URL/${f#public/}/\"" >> purge.json
done done
echo -e "\n ]\n}" >> purge.json # Remove any duplicate URLs
- cat purge.json - sort -u -o purge-list.txt purge-list.txt
# Duplicate each line, adding a trailing slash to the duplicates
- sed -i 'p;s|$|/|' purge-list.txt
artifacts: artifacts:
paths: paths:
- purge.json - purge-list.txt
trigger-cache-purge: trigger-cache-purge:
stage: .post stage: .post
...@@ -114,6 +116,7 @@ trigger-cache-purge: ...@@ -114,6 +116,7 @@ trigger-cache-purge:
include: purge-cache.gitlab-ci.yml include: purge-cache.gitlab-ci.yml
variables: variables:
PARENT_PIPELINE_ID: $CI_PIPELINE_ID PARENT_PIPELINE_ID: $CI_PIPELINE_ID
CF_PURGE_CACHE_CHUNK_SIZE: 20
# vi: set ts=2 sw=2 et ft=yaml: # vi: set ts=2 sw=2 et ft=yaml:
# Purge the Cloudflare cache using the request body contained in purge.json # Purge the URLs contained in purge-list.txt from the Cloudflare cache
# #
# We delay this job to give the pages:deploy job time to finish. If we don't # 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 # delay, then the cache might refill with old pages before the new pages are
...@@ -12,14 +12,40 @@ purge-cache: ...@@ -12,14 +12,40 @@ purge-cache:
start_in: 3 minutes start_in: 3 minutes
needs: needs:
- pipeline: $PARENT_PIPELINE_ID - pipeline: $PARENT_PIPELINE_ID
job: create-purge-json job: create-purge-list
before_script:
# Make sure the purge-list.txt file is readable, else exit
- test -r purge-list.txt || { echo "purge-list.txt not found" ; exit 1 ; }
- echo "Purge list has $(cat purge-list.txt | wc -l) URLs"
# Default to chunks of 30 URLs because Cloudflare only allows 30 URLs per
# purge request on free accounts
- echo "Chunk size of ${CF_PURGE_CACHE_CHUNK_SIZE:=30}"
script: script:
- cat purge.json # Split the purge list into chunks named 'purge-chunk-[aaa,aab,...]'
- >- - split -l $CF_PURGE_CACHE_CHUNK_SIZE -a 3 purge-list.txt purge-chunk-
wget -qO- "https://api.cloudflare.com/client/v4/zones/$CF_PURGE_CACHE_ZONE/purge_cache" - chunks=$(find . -type f -name 'purge-chunk-*' | wc -l)
--header "Content-Type: application/json" # Loop over the chunks, creating a purge request for each
--header "Authorization: Bearer $CF_PURGE_CACHE_TOKEN" - |-
--post-file purge.json counter=0
for chunk in purge-chunk-* ; do
echo -e "\nChunk $((++counter))/$chunks"
# Create the purge request body
echo -en "{\n \"files\": [" > purge.json
unset comma # This needs to be unset for the first line in each chunk
while read path; do
echo -en "$comma\n \"$path\"" >> purge.json
comma=','
done < $chunk
echo -e "\n ]\n}" >> purge.json
cat purge.json
# Make the API request to Cloudflare to purge the URLs from cache
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
# Rate limit ourselves to 1 request per second
sleep 1
done
# vi: set ts=2 sw=2 et ft=yaml: # vi: set ts=2 sw=2 et ft=yaml:
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <base href="%%BASE_URL%%/">
<meta name="generator" content="GitLab Pages">
<title>Cache Test | %%PROJECT_TITLE%%</title> <title>Cache Test | %%PROJECT_TITLE%%</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="gitlab-favicon.png"> <link rel="shortcut icon" href="gitlab-favicon.png">
<link rel="canonical" href="cache-test.html">
<link rel="preload" href="style.css" as="style"> <link rel="preload" href="style.css" as="style">
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<style> <style>
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <base href="%%BASE_URL%%/">
<meta name="generator" content="GitLab Pages">
<title>%%PROJECT_TITLE%%</title> <title>%%PROJECT_TITLE%%</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="gitlab-favicon.png"> <link rel="shortcut icon" href="gitlab-favicon.png">
<link rel="canonical" href="./">
<link rel="preload" href="style.css" as="style"> <link rel="preload" href="style.css" as="style">
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
</head> </head>
......
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>%%BASE_URL%%/</loc>
</url>
<url>
<loc>%%BASE_URL%%/cache-test.html</loc>
</url>
<url>
<loc>%%BASE_URL%%/sub/</loc>
</url>
</urlset>
<!-- vi: set ts=2 sw=2 et ft=xml: -->
...@@ -2,18 +2,19 @@ ...@@ -2,18 +2,19 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <base href="%%BASE_URL%%/">
<meta name="generator" content="GitLab Pages">
<title>Subdirectory | %%PROJECT_TITLE%%</title> <title>Subdirectory | %%PROJECT_TITLE%%</title>
<link rel="shortcut icon" href="../gitlab-favicon.png"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preload" href="../style.css" as="style"> <link rel="shortcut icon" href="gitlab-favicon.png">
<link rel="stylesheet" href="../style.css"> <link rel="canonical" href="sub/">
<link rel="preload" href="style.css" as="style">
<link rel="stylesheet" href="style.css">
</head> </head>
<body> <body>
<header> <header>
<a href="../">Homepage</a> <a href="./">Homepage</a>
<a href="../cache-test.html">Cache Test</a> <a href="cache-test.html">Cache Test</a>
<a href="./">Subdirectory</a> <a href="sub/">Subdirectory</a>
<a href="%%PROJECT_URL%%">Repository</a> <a href="%%PROJECT_URL%%">Repository</a>
</header> </header>
<main> <main>
......