Skip to content

Commit 92e7ba9

Browse files
authored
Merge pull request #17782 from MinaProtocol/dkijania/debian_repo_cache_fix
[CI] Fix debian caching issue when publishing
2 parents 87966c4 + ac00ac4 commit 92e7ba9

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

buildkite/scripts/release/manager.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,9 @@ function publish_debian() {
402402
local __backend=$9
403403
local __debian_repo=${10}
404404
local __arch=${11:-DEFAULT_ARCHITECTURE}
405-
local __debian_sign_key=${12}
406-
local __new_artifact_name=${13:-""}
405+
local __force_upload_debians=${12:-0}
406+
local __debian_sign_key=${13}
407+
local __new_artifact_name=${14:-""}
407408

408409
get_cached_debian_or_download $__backend $__artifact $__codename "$__network" "$__arch"
409410
local __artifact_full_name
@@ -443,6 +444,7 @@ function publish_debian() {
443444
--names "$DEBIAN_CACHE_FOLDER/$__codename/${__new_artifact_name}_${__target_version}_${__arch}.deb" \
444445
--version $__target_version \
445446
--bucket $__debian_repo \
447+
"$(if [[ $__force_upload_debians == 1 ]]; then echo "--force"; fi)" \
446448
-c $__codename \
447449
-r $__channel \
448450
--arch $__arch \
@@ -604,6 +606,8 @@ function publish_help(){
604606
printf " %-25s %s\n" "--backend" "[string] backend to use for storage. e.g gs,hetzner. default: gs";
605607
printf " %-25s %s\n" "--debian-repo" "[string] debian repository to publish to. default: $DEBIAN_REPO";
606608
printf " %-25s %s\n" "--debian-sign-key" "[string] debian signing key to use. default: lack of presence = no signing";
609+
printf " %-25s %s\n" "--strip-network-from-archive" "[bool] strip network from archive name. E.g mina-archive-devnet -> mina-archive";
610+
printf " %-25s %s\n" "--force-upload-debians" "[bool] force upload debian packages even if they exist already in the repository";
607611
echo ""
608612
echo "Example:"
609613
echo ""
@@ -636,6 +640,7 @@ function publish(){
636640
local __debian_sign_key=""
637641
local __strip_network_from_archive=0
638642
local __arch=${DEFAULT_ARCHITECTURE}
643+
local __force_upload_debians=0
639644

640645
while [ ${#} -gt 0 ]; do
641646
error_message="❌ Error: a value is needed for '$1'";
@@ -711,6 +716,10 @@ function publish(){
711716
__arch=${2:?$error_message}
712717
shift 2;
713718
;;
719+
--force-upload-debians )
720+
__force_upload_debians=1
721+
shift 1;
722+
;;
714723
* )
715724
echo -e "${RED} !! Unknown option: $1${CLEAR}\n";
716725
echo "";
@@ -758,6 +767,7 @@ function publish(){
758767
echo " - Debian sign key: $__debian_sign_key"
759768
echo " - Strip network from archive: $__strip_network_from_archive"
760769
echo " - Architecture: $__arch"
770+
echo " - Force upload debians: $__force_upload_debians"
761771
echo ""
762772

763773
if [[ $__backend != "gs" && $__backend != "hetzner" && $__backend != "local" ]]; then
@@ -798,6 +808,7 @@ function publish(){
798808
$__backend \
799809
$__debian_repo \
800810
"$__arch" \
811+
"$__force_upload_debians" \
801812
"$__debian_sign_key"
802813
fi
803814

@@ -827,6 +838,7 @@ function publish(){
827838
$__backend \
828839
$__debian_repo \
829840
"$__arch" \
841+
"$__force_upload_debians" \
830842
"$__debian_sign_key" \
831843
"$new_name"
832844
fi
@@ -850,6 +862,7 @@ function publish(){
850862
$__backend \
851863
$__debian_repo \
852864
"$__arch" \
865+
"$__force_upload_debians" \
853866
"$__debian_sign_key"
854867
fi
855868

@@ -872,6 +885,7 @@ function publish(){
872885
$__backend \
873886
$__debian_repo \
874887
"$__arch" \
888+
"$__force_upload_debians" \
875889
"$__debian_sign_key"
876890
fi
877891

buildkite/src/Command/Packages/Publish.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ let publish
229229
++ "--target-version ${r.value} "
230230
++ "--codenames ${codenames} "
231231
++ "--only-dockers "
232+
++ "--force-upload-debians "
232233
)
233234
]
234235
, label = "Docker Packages Publishing"

scripts/debian/publish.sh

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ RED='\033[0;31m'
77
ARCH=amd64
88
BUCKET=packages.o1test.net
99

10+
# Forcing upload debian even if it exists already
11+
FORCE=0
12+
1013
while [[ "$#" -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;;
1923
esac; 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+
3780
if [[ -z "$DEB_NAMES" ]]; then usage "❌ Debian(s) to upload are not set!"; fi;
3881
if [[ -z "$DEB_VERSION" ]]; then usage "❌ Version is not set!"; fi;
3982
if [[ -z "$DEB_CODENAME" ]]; then usage "❌ Codename is not set!"; fi;
@@ -55,8 +98,6 @@ else
5598
GPG_OPTS=("--gpg-options=\"--batch" "--pinentry-mode=loopback" "--yes")
5699
fi
57100

58-
59-
60101
echo "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."
71112
deb-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+
84127
for deb in $DEB_NAMES
85128
do
86129
# extracting name from debian package path. E.g:

0 commit comments

Comments
 (0)