From 616ec11d32e253059f49509ccc65fd61698316c8 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Fri, 27 Mar 2020 02:57:41 -0500 Subject: Add cache to apk invocation Repeated test-image creation hammers the repository servers and slows down image creation. If the host has an apk cache set up in /etc/apk/cache, use that; otherwise, allow a directory to be specified. --- adelie-build-cd | 10 ++++++++++ adelie-build-txz | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/adelie-build-cd b/adelie-build-cd index 0e57a03..b5870e2 100755 --- a/adelie-build-cd +++ b/adelie-build-cd @@ -74,6 +74,7 @@ usage() { printf 'Valid phases: clean install initrd iso all\n' } +[ -d /etc/apk/cache ] && def_cache=/etc/apk/cache while [ -n "$1" ]; do case $1 in @@ -103,6 +104,13 @@ while [ -n "$1" ]; do shift readonly MY_VER=$1 ;; + -c | --cache) + shift + readonly MY_CACHE=$1 + ;; + --no-cache) + unset def_cache + ;; *) usage >&2 exit 127 @@ -119,6 +127,7 @@ readonly PHASE=${MY_PHASE:-all} readonly VERSION=${MY_VER:-$def_ver} readonly APKVER=${MY_APKVER:-$VERSION} readonly URL=${MY_URL:-https://distfiles.adelielinux.org/adelie/$APKVER/} +readonly CACHE=${MY_CACHE:-$def_cache} set +a ensure_commands @@ -161,6 +170,7 @@ install_pkgs() { mknod squashroot-$ARCH/dev/urandom c 1 9 mkdir -p squashroot-$ARCH/usr/sbin apk --arch $ARCH \ + ${CACHE:+--cache-dir "${CACHE}"} \ -X "$URL/system/$EXTRA_MIRROR" \ -X "$URL/user/$EXTRA_MIRROR" \ -U --root squashroot-$ARCH --initdb add $PACKAGES $ARCH_PKGS $KIND_PKGS diff --git a/adelie-build-txz b/adelie-build-txz index 15d81bf..b419de1 100755 --- a/adelie-build-txz +++ b/adelie-build-txz @@ -57,6 +57,7 @@ usage() { printf 'Default VERSION: %s\n' $def_ver } +[ -d /etc/apk/cache ] && def_cache=/etc/apk/cache while [ -n "$1" ]; do case $1 in @@ -75,6 +76,13 @@ while [ -n "$1" ]; do shift readonly MY_VER=$1 ;; + -c | --cache) + shift + readonly MY_CACHE=$1 + ;; + --no-cache) + unset def_cache + ;; *) usage >&2 exit 127 @@ -90,6 +98,7 @@ readonly PHASE=${MY_PHASE:-all} readonly VERSION=${MY_VER:-$def_ver} readonly APKVER=${MY_APKVER:-$VERSION} readonly URL=${MY_URL:-https://distfiles.adelielinux.org/adelie/$VERSION/} +readonly CACHE=${MY_CACHE:-$def_cache} set +a ensure_commands @@ -132,6 +141,7 @@ install_pkgs() { mknod rootfs-$ARCH/dev/urandom c 1 9 mkdir -p rootfs-$ARCH/usr/sbin apk --arch $ARCH \ + ${CACHE:+--cache-dir "${CACHE}"} \ -X "$URL/system/$EXTRA_MIRROR" \ -X "$URL/user/$EXTRA_MIRROR" \ -U --root rootfs-$ARCH --initdb add $PACKAGES $ARCH_PKGS -- cgit v1.2.3-70-g09d2 From 5fc8198b54849b02e2d48b51b96a94b9851383af Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Fri, 27 Mar 2020 20:19:35 -0500 Subject: Add documentation to manpages for new cache options --- adelie-build-cd.8 | 11 +++++++++++ adelie-build-txz.8 | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/adelie-build-cd.8 b/adelie-build-cd.8 index 885e29e..5da2b73 100644 --- a/adelie-build-cd.8 +++ b/adelie-build-cd.8 @@ -12,6 +12,8 @@ .Op Fl p Ar PHASE .Op Fl s .Op Fl v Ar VERSION +.Op Fl -cache Ar CACHE +.Op Fl -no-cache .Sh DESCRIPTION .Nm creates a live CD image or installer CD image for Adélie Linux using @@ -52,6 +54,15 @@ This requires the suite of utilities to be available. .It Fl v Ar VERSION Specifies the version of Adélie Linux to use for the created ISO. +.It Fl -cache Ar CACHE +Specifies the location of the cache directory to use, to speed up +.Xr apk 8 +runs. Defaults to the system cache in +.Pa /etc/apk/cache . +.It Fl -no-cache +Do not use any cache directory for this +.Xr apk 8 +run; pull all packages from the repository. .El .Ss Phases The diff --git a/adelie-build-txz.8 b/adelie-build-txz.8 index 4dcc4ca..268cfca 100644 --- a/adelie-build-txz.8 +++ b/adelie-build-txz.8 @@ -9,6 +9,8 @@ .Op Fl a Ar ARCH .Op Fl -mini .Op Fl v Ar VERSION +.Op Fl -cache Ar CACHE +.Op Fl -no-cache .Sh DESCRIPTION .Nm creates a rootfs tarball, similar to a Gentoo stage3 or Alpine miniroot, using @@ -29,6 +31,15 @@ Specifies that a mini rootfs (no kernel or live media tools installed) is desired. .It Fl v Ar VERSION Specifies the version of Adélie Linux to use for the created rootfs tarball. +.It Fl -cache Ar CACHE +Specifies the location of the cache directory to use, to speed up +.Xr apk 8 +runs. Defaults to the system cache in +.Pa /etc/apk/cache . +.It Fl -no-cache +Do not use any cache directory for this +.Xr apk 8 +run; pull all packages from the repository. .El .Sh ENVIRONMENT .Bl -tag -width "EXTRA_MIRROR" -offset indent -compact -- cgit v1.2.3-70-g09d2 From bd4a68aef064d0f375f17b4f0988688da30b884d Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Fri, 27 Mar 2020 20:46:30 -0500 Subject: Missed a couple apk invocations in the full cd build path --- adelie-build-cd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adelie-build-cd b/adelie-build-cd index b5870e2..acd6530 100755 --- a/adelie-build-cd +++ b/adelie-build-cd @@ -254,6 +254,7 @@ make_structure() { if test -n "${DO_FULL+full}"; then # This ensures we have documentation available on-disc, and to install. apk --arch $ARCH \ + ${CACHE:+--cache-dir "${CACHE}"} \ -X "$URL/system/$EXTRA_MIRROR" \ -X "$URL/user/$EXTRA_MIRROR" \ --root squashroot-$ARCH add docs @@ -261,6 +262,7 @@ make_structure() { mkdir -p $PACKAGES_DIR # Fetch all APKs. apk --arch $ARCH \ + ${CACHE:+--cache-dir "${CACHE}"} \ -X "$URL/system/$EXTRA_MIRROR" \ -X "$URL/user/$EXTRA_MIRROR" \ --root squashroot-$ARCH fetch -o $PACKAGES_DIR $(apk --root squashroot-$ARCH info) -- cgit v1.2.3-70-g09d2 From 3fb12f36c8136c7abd998322d900d6e01214e4dc Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Mon, 30 Mar 2020 07:59:12 -0500 Subject: Avoid system cache if specified arch differs from host arch --- adelie-build-cd | 5 +++-- adelie-build-cd.8 | 3 ++- adelie-build-txz | 5 +++-- adelie-build-txz.8 | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/adelie-build-cd b/adelie-build-cd index acd6530..f7d97a0 100755 --- a/adelie-build-cd +++ b/adelie-build-cd @@ -74,8 +74,6 @@ usage() { printf 'Valid phases: clean install initrd iso all\n' } -[ -d /etc/apk/cache ] && def_cache=/etc/apk/cache - while [ -n "$1" ]; do case $1 in -a | --arch) @@ -119,6 +117,9 @@ while [ -n "$1" ]; do shift done +[ -d /etc/apk/cache ] && def_cache=/etc/apk/cache +[ -z "${MY_ARCH}" -o "${MY_ARCH}" = "${def_arch}" ] || unset def_cache + set -a readonly ARCH=${MY_ARCH:-$def_arch} readonly KIND=${MY_KIND:-live} diff --git a/adelie-build-cd.8 b/adelie-build-cd.8 index 5da2b73..76f3184 100644 --- a/adelie-build-cd.8 +++ b/adelie-build-cd.8 @@ -58,7 +58,8 @@ Specifies the version of Adélie Linux to use for the created ISO. Specifies the location of the cache directory to use, to speed up .Xr apk 8 runs. Defaults to the system cache in -.Pa /etc/apk/cache . +.Pa /etc/apk/cache +for the same architecture, or none. This directory must exist, or it is ignored. .It Fl -no-cache Do not use any cache directory for this .Xr apk 8 diff --git a/adelie-build-txz b/adelie-build-txz index b419de1..4387af2 100755 --- a/adelie-build-txz +++ b/adelie-build-txz @@ -57,8 +57,6 @@ usage() { printf 'Default VERSION: %s\n' $def_ver } -[ -d /etc/apk/cache ] && def_cache=/etc/apk/cache - while [ -n "$1" ]; do case $1 in -a | --arch) @@ -91,6 +89,9 @@ while [ -n "$1" ]; do shift done +[ -d /etc/apk/cache ] && def_cache=/etc/apk/cache +[ -z "${MY_ARCH}" -o "${MY_ARCH}" = "${def_arch}" ] || unset def_cache + set -a readonly ARCH=${MY_ARCH:-$def_arch} readonly LDARCH=${LDARCH:-$ARCH} diff --git a/adelie-build-txz.8 b/adelie-build-txz.8 index 268cfca..6dfa9d5 100644 --- a/adelie-build-txz.8 +++ b/adelie-build-txz.8 @@ -35,7 +35,8 @@ Specifies the version of Adélie Linux to use for the created rootfs tarball. Specifies the location of the cache directory to use, to speed up .Xr apk 8 runs. Defaults to the system cache in -.Pa /etc/apk/cache . +.Pa /etc/apk/cache +for the same architecture, or none. This directory must exist, or it is ignored. .It Fl -no-cache Do not use any cache directory for this .Xr apk 8 -- cgit v1.2.3-70-g09d2