@@ -7,13 +7,17 @@ RED='\033[0;31m'
77ARCH=amd64
88BUCKET=packages.o1test.net
99
10+ # Forcing upload debian even if it exists already
11+ FORCE=0
12+
1013while [[ " $# " -gt 0 ]]; do case $1 in
1114 -n|--names) DEB_NAMES=" $2 " ; shift ;;
1215 -a|--arch) ARCH=" $2 " ; shift ;;
1316 -r|--release) DEB_RELEASE=" $2 " ; shift ;;
1417 -v|--version) DEB_VERSION=" $2 " ; shift ;;
1518 -c|--codename) DEB_CODENAME=" $2 " ; shift ;;
1619 -b|--bucket) BUCKET=" $2 " ; shift ;;
20+ -f|--force) FORCE=1;;
1721 -s|--sign) SIGN=" $2 " ; shift ;;
1822 * ) echo " ❌ Unknown parameter passed: $1 " ; exit 1;;
1923esac ; shift ; done
@@ -34,6 +38,45 @@ function usage() {
3438 exit 1
3539}
3640
41+ # Invalidate CloudFront cache for the given bucket or CNAME and paths
42+ # This is to ensure that after uploading new debs, users don't get stale
43+ # package lists from CloudFront cache
44+ # Usage: invalidate_cache [bucket-or-cname] codename
45+ # Example: invalidate_cache nightly.apt.packages.minaprotocol.com bookworm
46+ function invalidate_cache() {
47+ BUCKET_OR_CNAME=" ${1:- nightly.apt.packages.minaprotocol.com} "
48+ PATHS_TO_INVALIDATE=" /dists/$2 /*"
49+
50+ echo " 🔎 Resolving ${BUCKET_OR_CNAME} ..."
51+ CF_DOMAIN=$( dig +short CNAME " ${BUCKET_OR_CNAME} " | sed ' s/\.$//' )
52+ CF_DOMAIN=$( dig +short CNAME " ${BUCKET_OR_CNAME} " | sed ' s/\.$//' )
53+
54+ if [[ -z " $CF_DOMAIN " ]]; then
55+ echo " ❌ Could not resolve ${BUCKET_OR_CNAME} to a CloudFront domain."
56+ exit 1
57+ fi
58+
59+ echo " ✅ Found CloudFront domain: ${CF_DOMAIN} "
60+
61+ echo " 📋 Searching for distribution ID in CloudFront..."
62+ DIST_ID=$( aws cloudfront list-distributions \
63+ --query " DistributionList.Items[?DomainName=='${CF_DOMAIN} '].Id" \
64+ --output text)
65+
66+ if [[ -z " $DIST_ID " ]]; then
67+ echo " ❌ No CloudFront distribution found for domain ${CF_DOMAIN} "
68+ exit 1
69+ fi
70+
71+ echo " ✅ Found CloudFront distribution ID: ${DIST_ID} "
72+
73+ echo " 🚀 Creating invalidation for paths: ${PATHS_TO_INVALIDATE} "
74+ aws cloudfront create-invalidation \
75+ --distribution-id " ${DIST_ID} " \
76+ --paths " ${PATHS_TO_INVALIDATE} "
77+ }
78+
79+
3780if [[ -z " $DEB_NAMES " ]]; then usage " ❌ Debian(s) to upload are not set!" ; fi ;
3881if [[ -z " $DEB_VERSION " ]]; then usage " ❌ Version is not set!" ; fi ;
3982if [[ -z " $DEB_CODENAME " ]]; then usage " ❌ Codename is not set!" ; fi ;
5598 GPG_OPTS=(" --gpg-options=\" --batch" " --pinentry-mode=loopback" " --yes" )
5699fi
57100
58-
59-
60101echo " Publishing debs: ${DEB_NAMES} to Release: ${DEB_RELEASE} and Codename: ${DEB_CODENAME} "
61102# Upload the deb files to s3.
62103# If this fails, attempt to remove the lockfile and retry.
@@ -69,18 +110,20 @@ for _ in {1..10}; do (
69110# >> Attempting to obtain a lock
70111# /var/lib/gems/2.3.0/gems/deb-s3-0.10.0/lib/deb/s3/lock.rb:24:in `throw': uncaught throw #"Unable to obtain a lock after 60, giving up."
71112deb-s3 upload $BUCKET_ARG $S3_REGION_ARG \
72- -- fail-if-exists \
113+ " $( [ " $FORCE " -eq 0 ] && echo " -- fail-if-exists" ) " \
73114 --lock \
74115 --arch $ARCH \
75116 --preserve-versions \
76- --cache-control=max-age=120 \
117+ --cache-control " no-store,no-cache,must-revalidate " \
77118 $SIGN_ARG \
78119 --component " ${DEB_RELEASE} " \
79120 --codename " ${DEB_CODENAME} " \
80121 " ${GPG_OPTS[@]} " \
81122 " ${DEB_NAMES} "
82123) && break || (MINA_DEB_BUCKET=${BUCKET} scripts/debian/clear-s3-lockfile.sh); done
83124
125+ invalidate_cache " $BUCKET " " $DEB_CODENAME "
126+
84127for deb in $DEB_NAMES
85128do
86129 # extracting name from debian package path. E.g:
0 commit comments