Skip to content

Commit b88ce3a

Browse files
committed
WORKAROUND for apt mirror issue
1 parent 3bf4b77 commit b88ce3a

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

scripts/publish-apt-packages.sh

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ GORELEASER_PACKAGES_FOLDER="dist/"
1717
# This can be done by removing "use-keyboxd" from ~/.gnupg/common.conf (see https://github.com/gpg/gnupg/blob/master/README)
1818
echo -n >~/.gnupg/common.conf
1919

20-
# Create a local mirror of the current state of the remote APT repository
21-
printf ">>> Creating mirror \n"
22-
curl ${PACKAGES_BUCKET_URL}/${PUBLIC_KEY_FILE_PATH} >public.asc
23-
gpg --no-default-keyring --keyring=${CUSTOM_KEYRING_FILE} --import public.asc
24-
aptly mirror create -config "${APTLY_CONFIG_FILE_PATH}" -keyring="${CUSTOM_KEYRING_FILE}" current "${PACKAGES_BUCKET_URL}/${APT_REPO_PATH}" ${DISTRIBUTION}
25-
26-
# Update the mirror to the latest state
27-
printf "\n>>> Updating mirror \n"
28-
aptly mirror update -keyring="${CUSTOM_KEYRING_FILE}" -max-tries=5 current
20+
BOOTSTRAP_ONLY=0
2921

30-
# Create a snapshot of the mirror
31-
printf "\n>>> Creating snapshop from mirror \n"
32-
aptly snapshot create current-snapshot from mirror current
22+
# Try to create a local mirror of the current remote APT repository
23+
printf ">>> Creating mirror (if remote exists)\n"
24+
curl -fsSL ${PACKAGES_BUCKET_URL}/${PUBLIC_KEY_FILE_PATH} -o public.asc
25+
gpg --no-default-keyring --keyring=${CUSTOM_KEYRING_FILE} --import public.asc
26+
if aptly mirror create -config "${APTLY_CONFIG_FILE_PATH}" -keyring="${CUSTOM_KEYRING_FILE}" current "${PACKAGES_BUCKET_URL}/${APT_REPO_PATH}" ${DISTRIBUTION}; then
27+
printf "\n>>> Updating mirror \n"
28+
aptly mirror update -keyring="${CUSTOM_KEYRING_FILE}" -max-tries=5 current
29+
printf "\n>>> Creating snapshot from mirror \n"
30+
aptly snapshot create current-snapshot from mirror current
31+
else
32+
printf "\n>>> No existing remote repository found (bootstrap)\n"
33+
BOOTSTRAP_ONLY=1
34+
fi
3335

3436
# Create a new fresh local APT repo
3537
printf "\n>>> Creating fresh local repo \n"
@@ -43,10 +45,16 @@ aptly repo add new-repo ${GORELEASER_PACKAGES_FOLDER}
4345
printf "\n>>> Creating snapshot of local repo \n"
4446
aptly snapshot create new-snapshot from repo new-repo
4547

46-
# Merge new-snapshot into current-snapshot creating a new snapshot updated-snapshot
47-
printf "\n>>> Merging snapshots \n"
48-
aptly snapshot pull -no-remove -architectures="amd64,i386,arm64" current-snapshot new-snapshot updated-snapshot ${DISTRIBUTION}
48+
UPDATED_SNAPSHOT="new-snapshot"
49+
if [ "$BOOTSTRAP_ONLY" -eq 0 ]; then
50+
# Merge new-snapshot into current-snapshot creating a new snapshot updated-snapshot
51+
printf "\n>>> Merging snapshots \n"
52+
aptly snapshot pull -no-remove -architectures="amd64,i386,arm64" current-snapshot new-snapshot updated-snapshot ${DISTRIBUTION}
53+
UPDATED_SNAPSHOT="updated-snapshot"
54+
else
55+
printf "\n>>> Bootstrap mode: publishing new packages as initial snapshot \n"
56+
fi
4957

5058
# Publish the new snapshot to the remote repo
5159
printf "\n>>> Publishing updated snapshot \n"
52-
aptly publish snapshot -keyring="${CUSTOM_KEYRING_FILE}" -gpg-key="${GPG_PRIVATE_KEY_FINGERPRINT}" -passphrase "${GPG_PASSPHRASE}" -config "${APTLY_CONFIG_FILE_PATH}" updated-snapshot "s3:${APT_BUCKET_NAME}:${APT_REPO_PATH}"
60+
aptly publish snapshot -keyring="${CUSTOM_KEYRING_FILE}" -gpg-key="${GPG_PRIVATE_KEY_FINGERPRINT}" -passphrase "${GPG_PASSPHRASE}" -config "${APTLY_CONFIG_FILE_PATH}" "$UPDATED_SNAPSHOT" "s3:${APT_BUCKET_NAME}:${APT_REPO_PATH}"

0 commit comments

Comments
 (0)