This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow-site-archive.git
The following commit(s) were added to refs/heads/main by this push:
new f1adcd55e7 Add cache invalidation after syncing Github -> S3 (#24)
f1adcd55e7 is described below
commit f1adcd55e71625c28f865105cde03a8090647555
Author: Jarek Potiuk <[email protected]>
AuthorDate: Fri Oct 17 13:48:35 2025 +0200
Add cache invalidation after syncing Github -> S3 (#24)
---
scripts/github_to_s3.py | 4 +++-
scripts/transfer_utils.py | 27 +++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/scripts/github_to_s3.py b/scripts/github_to_s3.py
index c2c1d60165..27d63185ea 100644
--- a/scripts/github_to_s3.py
+++ b/scripts/github_to_s3.py
@@ -31,7 +31,8 @@ from pathlib import Path
from rich.console import Console
-from transfer_utils import CommonTransferUtils,
convert_short_name_to_full_package_name, sort_priority_packages
+from transfer_utils import CommonTransferUtils,
convert_short_name_to_full_package_name, \
+ sort_priority_packages, invalidate_cloudflare_cache
console = Console(width=200, color_system="standard")
@@ -159,3 +160,4 @@ if __name__ == "__main__":
console.print(f"[red] Invalid sync type {args.sync_type} with document
packages {document_packages} "
f"and commit ref {args.commit_ref}[/]")
sys.exit(1)
+ invalidate_cloudflare_cache(args.bucket_path)
diff --git a/scripts/transfer_utils.py b/scripts/transfer_utils.py
index 8ecef046a8..06e62aa1e4 100644
--- a/scripts/transfer_utils.py
+++ b/scripts/transfer_utils.py
@@ -1,3 +1,4 @@
+import os
import subprocess
import sys
import tempfile
@@ -167,3 +168,29 @@ def sort_priority_tuples(tuples: list[tuple[str, str]]) ->
list[tuple[str, str]]
sorted_tuples.append(tup)
tuples.remove(tup)
return sorted_tuples + sorted(tuples, key=lambda x: x[0])
+
+
+def get_cloudfront_distribution(destination_location: str):
+ if "live-docs" in destination_location:
+ return "E26P75MP9PMULE"
+ return "E197MS0XRJC5F3"
+
+def invalidate_cloudflare_cache(destination_location: str):
+ cloudfront_client = boto3.client("cloudfront")
+ distribution_id = get_cloudfront_distribution(destination_location)
+ console.print(
+ f"[info]Invalidating CloudFront cache for the uploaded files:
distribution id {distribution_id}\n"
+ )
+ cloudfront_client.create_invalidation(
+ DistributionId=distribution_id,
+ InvalidationBatch={
+ "Paths": {
+ "Quantity": 1,
+ "Items": ["/*"],
+ },
+ "CallerReference": str(int(os.environ.get("GITHUB_RUN_ID", 0))),
+ },
+ )
+ console.print(
+ f"[success]CloudFront cache request invalidated successfully:
{distribution_id}\n"
+ )