cleanups
This commit is contained in:
1 parent
60ec470f9f
commit
fe2ad1590d
9 files changed
+186
-19
No files matched your search
+46
-13
@@ -5,10 +5,21 @@ source /opt/rustbox-package-builder/scripts/lib.sh
|
||||
: "${SRC:?SRC required}"
|
||||
REPOSITORY="$DATA_DIR/repository"
|
||||
APTLY_CONF="$DATA_DIR/state/aptly.conf"
|
||||
OUT="$DATA_DIR/work/out"
|
||||
PKG="$DATA_DIR/work/package"
|
||||
rm -rf "$OUT" "$PKG"
|
||||
mkdir -p "$OUT" "$DATA_DIR/packages/deb" "$DATA_DIR/packages/rpm/x86_64" "$DATA_DIR/packages/suse/x86_64"
|
||||
BUILD_TMP_DIR=${BUILD_TMP_DIR:-/tmp/rustbox-package-builder}
|
||||
OUT="$BUILD_TMP_DIR/out"
|
||||
PKG="$BUILD_TMP_DIR/package"
|
||||
export CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-$BUILD_TMP_DIR/cargo-target}
|
||||
|
||||
cleanup_build_artifacts() {
|
||||
rm -rf -- "$OUT" "$PKG"
|
||||
if is_true "${CLEAN_BUILD_CACHE:-1}"; then
|
||||
rm -rf -- "$CARGO_TARGET_DIR"
|
||||
fi
|
||||
}
|
||||
trap cleanup_build_artifacts EXIT
|
||||
|
||||
rm -rf -- "$OUT" "$PKG"
|
||||
mkdir -p "$OUT" "$DATA_DIR/packages/deb" "$DATA_DIR/packages/rpm/x86_64" "$DATA_DIR/packages/suse/x86_64" "$CARGO_TARGET_DIR"
|
||||
|
||||
VERSION=$(python3.11 - "$SRC/Cargo.toml" <<'PY'
|
||||
import sys, tomllib
|
||||
@@ -78,7 +89,16 @@ cp -f "$DEB" "$DATA_DIR/packages/deb/"
|
||||
cp -f "$RPM" "$DATA_DIR/packages/rpm/x86_64/"
|
||||
cp -f "$SUSE" "$DATA_DIR/packages/suse/x86_64/"
|
||||
|
||||
aptly -config="$APTLY_CONF" repo add -force-replace rustbox "$DEB" >/dev/null
|
||||
package_retention=${PACKAGE_RETENTION:-10}
|
||||
prune_package_files "$DATA_DIR/packages/deb" 'rustbox_*.deb' "$package_retention"
|
||||
prune_package_files "$DATA_DIR/packages/rpm/x86_64" 'rustbox-*.x86_64.rpm' "$package_retention"
|
||||
prune_package_files "$DATA_DIR/packages/suse/x86_64" 'rustbox-*.suse.x86_64.rpm' "$package_retention"
|
||||
|
||||
# Keep the mutable aptly repository in exact sync with the retained DEB files.
|
||||
# Published snapshots are immutable, so rebuilding this repo does not disturb the
|
||||
# currently served repository until the new snapshot is switched in below.
|
||||
aptly -config="$APTLY_CONF" repo remove rustbox rustbox >/dev/null 2>&1 || true
|
||||
aptly -config="$APTLY_CONF" repo add -force-replace rustbox "$DATA_DIR/packages/deb" >/dev/null
|
||||
SNAPSHOT="rustbox-${VERSION}-${SHORT_SHA}-$(date +%s)"
|
||||
aptly -config="$APTLY_CONF" snapshot create "$SNAPSHOT" from repo rustbox >/dev/null
|
||||
APT_SIGN=(-batch -gpg-key="$GPG_KEY_ID")
|
||||
@@ -90,12 +110,28 @@ fi
|
||||
APT_PUBLIC="$DATA_DIR/aptly/public"
|
||||
[[ -f "$APT_PUBLIC/dists/$REPO_DISTRIBUTION/InRelease" ]] || fatal "APT InRelease missing"
|
||||
|
||||
# Once the new snapshot is live, old aptly snapshots no longer serve traffic.
|
||||
# Drop them and let aptly remove unreferenced pool objects.
|
||||
while IFS= read -r old_snapshot; do
|
||||
[[ -n "$old_snapshot" && "$old_snapshot" != "$SNAPSHOT" ]] || continue
|
||||
if ! aptly -config="$APTLY_CONF" snapshot drop "$old_snapshot" >/dev/null 2>&1; then
|
||||
log "WARN: could not drop old aptly snapshot $old_snapshot"
|
||||
fi
|
||||
done < <(aptly -config="$APTLY_CONF" snapshot list -raw | grep '^rustbox-' || true)
|
||||
if ! aptly -config="$APTLY_CONF" db cleanup >/dev/null 2>&1; then
|
||||
log "WARN: aptly database cleanup failed"
|
||||
fi
|
||||
|
||||
RELEASE_ID="$(date -u '+%Y%m%dT%H%M%SZ')-${SHORT_SHA}"
|
||||
RELEASE_DIR="$REPOSITORY/releases/$RELEASE_ID"
|
||||
mkdir -p "$RELEASE_DIR/apt" "$RELEASE_DIR/rpm/x86_64" "$RELEASE_DIR/suse/x86_64"
|
||||
rsync -a --delete "$APT_PUBLIC/" "$RELEASE_DIR/apt/"
|
||||
rsync -a --delete "$DATA_DIR/packages/rpm/x86_64/" "$RELEASE_DIR/rpm/x86_64/"
|
||||
rsync -a --delete "$DATA_DIR/packages/suse/x86_64/" "$RELEASE_DIR/suse/x86_64/"
|
||||
|
||||
# All paths are on the same persistent data volume. Hard-linking package and
|
||||
# repository files avoids multiplying identical package payloads for every
|
||||
# atomic release directory while preserving independent directory trees.
|
||||
cp -al "$APT_PUBLIC/." "$RELEASE_DIR/apt/"
|
||||
cp -al "$DATA_DIR/packages/rpm/x86_64/." "$RELEASE_DIR/rpm/x86_64/"
|
||||
cp -al "$DATA_DIR/packages/suse/x86_64/." "$RELEASE_DIR/suse/x86_64/"
|
||||
|
||||
for rpm_root in "$RELEASE_DIR/rpm/x86_64"; do
|
||||
rm -rf "$rpm_root/repodata"; createrepo_c --update "$rpm_root" >/dev/null
|
||||
@@ -135,9 +171,6 @@ printf '%s\n' "$SHA" | atomic_write "$DATA_DIR/state/last_commit"
|
||||
printf '%s\n' "$VERSION" | atomic_write "$DATA_DIR/state/last_version"
|
||||
printf '%s\n' "$RELEASE" | atomic_write "$DATA_DIR/state/last_package_release"
|
||||
|
||||
retention=${RELEASE_RETENTION:-10}
|
||||
if [[ "$retention" =~ ^[1-9][0-9]*$ ]]; then
|
||||
mapfile -t old < <(find "$REPOSITORY/releases" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %p\n' | sort -nr | awk -v keep="$retention" 'NR>keep {$1=""; sub(/^ /,""); print}')
|
||||
for dir in "${old[@]}"; do [[ "$dir" == "$RELEASE_DIR" ]] || rm -rf -- "$dir"; done
|
||||
fi
|
||||
release_retention=${RELEASE_RETENTION:-10}
|
||||
prune_release_dirs "$REPOSITORY/releases" "$release_retention" "$RELEASE_DIR"
|
||||
log "published RustBox $VERSION-$RELEASE: $REPOSITORY_URL"
|
||||
Reference in new issue
Block a user