Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept: Bust cloudflare cache #333

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/public/sitemap*.xml
/storage/*.key
/vendor
/modified
.DS_Store
.env
.phpunit.result.cache
Expand Down
3 changes: 2 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Config;

class Kernel extends ConsoleKernel
{
Expand All @@ -26,7 +27,7 @@ protected function schedule(Schedule $schedule)
{
$schedule->command('sitemap:generate')->daily();
$schedule->exec('bash /home/forge/laravel.com/build/api.sh')->daily();
$schedule->exec('bash /home/forge/laravel.com/build/docs.sh')->everyFiveMinutes();
$schedule->exec('bash /home/forge/laravel.com/build/docs.sh', Config::get(['services.cloudflare.zone', 'services.cloudflare.token']))->everyFiveMinutes();
}

/**
Expand Down
44 changes: 32 additions & 12 deletions build/docs.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
#!/bin/bash

set -e

base=${base:-/home/forge/laravel.com}
docs=${base}/resources/docs

# cd ${docs}/5.5 && git pull origin 5.5
# cd ${docs}/5.8 && git pull origin 5.8
# cd ${docs}/6.0 && git pull origin 6.0
# cd ${docs}/6.x && git pull origin 6.x
# cd ${docs}/7.x && git pull origin 7.x
cd ${docs}/8.x && git pull origin 8.x
cd ${docs}/9.x && git pull origin 9.x
cd ${docs}/10.x && git pull origin 10.x
cd ${docs}/11.x && git pull origin 11.x
cd ${docs}/master && git pull origin master
versions=('8.x' '9.x' '10.x' '11.x' 'master')

for version in "${versions[@]}"
do
cd "${base}/resources/docs/${version}"
previousHash=$(git rev-parse "${version}")
git fetch origin "${version}"

if [[ "${previousHash}" == $(git rev-parse "origin/${version}") ]]; then
continue
fi

git pull origin "${version}"
git diff --name-only $previousHash HEAD | while read markdownFile; do
echo "https://laravel.com/docs/${version}/$(basename $markdownFile '.md')" >> "${base}/modified"
done
done

if [ ! -f "${base}/modified" ]; then
exit 0
fi

files=$(jq --raw-input --slurp 'split("\n") | map(select(. != "")) | unique' "${base}/modified")
curl -X POST --fail \
"https://api.cloudflare.com/client/v4/zones/${1}/purge_cache" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${2}" \
-d "{ \"files\": ${files} }"
rm "${base}/modified"
4 changes: 4 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@
'token' => env('WORKABLE_TOKEN'),
],

'cloudflare' => [
'zone' => env('CLOUDFLARE_ZONE'),
'token' => env('CLOUDFLARE_TOKEN'),
],
];