From 92e1d5f5fb737da2bafd6e114c2c53cbb8e2280d Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Fri, 10 Jan 2020 09:16:18 +0100 Subject: add apk cache and simplify named volumes - apk supports caching of packages for reuse on next run. This is the prefered way and should be relativly fast compared to other package magenagers. This also removed the need for other named volumes which need to be setup and maintained on each run. - correcly set perm of volume mount points --- dabuild.in | 38 ++++++++++++++++++++------------------ entrypoint.sh | 16 ++++++++++++---- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/dabuild.in b/dabuild.in index 61f38fa..a548540 100755 --- a/dabuild.in +++ b/dabuild.in @@ -19,6 +19,7 @@ fi if [ "$DABUILD_DEBUG" = "true" ]; then set -x PS4='$LINENO: ' + DABUILD_ENV="$DABUILD_ENV -e DABUILD_DEBUG=true" fi ## check running from within an `aports` tree @@ -75,8 +76,7 @@ if [ ! \( -d "$ABUILD_PACKAGES" -a -w "$ABUILD_PACKAGES" \) ]; then fi ## setup volumes; use named volumes as cache if desired -ABUILD_VOLUMES="-v ${HOME}/.abuild:/home/builder/.abuild \ - -v ${PWD%/aports/*}/aports:/home/builder/aports \ +ABUILD_VOLUMES="-v ${PWD%/aports/*}/aports:/home/builder/aports \ -v ${ABUILD_PACKAGES}:/home/builder/packages" if [ -f "/etc/abuild.conf" ]; then @@ -92,22 +92,24 @@ if [ -f "$HOME/.gitconfig" ]; then ABUILD_VOLUMES="$ABUILD_VOLUMES -v $HOME/.gitconfig:/home/builder/.gitconfig" fi -if [ "$DABUILD_CACHE" = "true" ]; then - for v in %%ABUILD_VOLUMES%% ; do - vol=abuild-$ABUILD_VERSION-$DABUILD_ARCH-${v//\//_} - if [ "$DABUILD_CLEAN" = "true" ]; then - ## clean the cache if requested - $_DOCKER rm -f $($_DOCKER ps -qaf "volume=$vol") >/dev/null 2>&1 || true - $_DOCKER volume rm $vol >/dev/null - fi - - if $_DOCKER volume ls -f 'name=$v' | grep $v >/dev/null ; then - $_DOCKER volume create $vol >/dev/null - fi - ABUILD_VOLUMES="$ABUILD_VOLUMES -v $vol:/$v" - done +setup_named_volume() { + local name=$1 dest=$2 single=$3 + local volume="dabuild-$name-$ALPINE_RELEASE-$DABUILD_ARCH" + [ "$single" = "true" ] && volume="dabuild-$name" + ABUILD_VOLUMES="$ABUILD_VOLUMES -v $volume:$dest" +} + +if [ "$DABUILD_APK_CACHE" = "true" ]; then + setup_named_volume apkcache "/etc/apk/cache" fi +if [ "$DABUILD_CCACHE" = "true" ]; then + setup_named_volume ccache "/home/builder/.ccache" + DABUILD_ENV="$DABUILD_ENV -e DABUILD_CCACHE=true" +fi + +setup_named_volume config "/home/builder/.abuild" true + ABUILD_RM="--rm" if [ "$DABUILD_RM" = "false" ]; then ABUILD_RM="" @@ -117,7 +119,7 @@ fi $_DOCKER run --tty --interactive \ $ABUILD_RM \ $ABUILD_VOLUMES \ - -e DABUILD_DEBUG \ - $DABUILD_ARGS \ + $DABUILD_ENV \ + $DABUILD_ARGS \ --workdir /home/builder/aports/${PWD#*/aports/} \ %%ABUILD_IMAGE%%:$ABUILD_VERSION-$DABUILD_ARCH "$@" diff --git a/entrypoint.sh b/entrypoint.sh index c9dfc55..a76a84d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -13,10 +13,8 @@ if [ "$DABUILD_DEBUG" = "true" ]; then PS4='$LINENO: ' fi -## check can write to ~/.abuild -if [ ! -w "$HOME/.abuild/" ]; then - die "Error: unwritable ~/.abuild [$(ls -lad ~/.abuild | cut -d " " -f 1)]" -fi +# enable ccache if requested +[ "$DABUILD_CCACHE" = "true" ] && export USE_CCACHE=1 ## generate signing keys on first run if [ ! -r "$HOME/.abuild/abuild.conf" ]; then @@ -30,6 +28,16 @@ fi fi ) +# make sure distfiles has correct permissions +sudo install -d -m 775 -g abuild /var/cache/distfiles + +# correct permissions of user volumes +for vpath in /home/builder/.ccache /home/builder/.abuild \ + /home/builder/packages +do + [ -d "$vpath" ] && sudo chown builder:builder "$vpath" +done + sudo cp -v "$HOME"/.abuild/*.rsa.pub /etc/apk/keys/ sudo apk -U upgrade -a -- cgit v1.2.3 From 5ff1d53bd82829ca31c2eb9c99c22305efd5abd5 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Fri, 10 Jan 2020 09:28:00 +0100 Subject: add script to administer dabuild --- dabuild-admin | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 dabuild-admin diff --git a/dabuild-admin b/dabuild-admin new file mode 100755 index 0000000..86c5da8 --- /dev/null +++ b/dabuild-admin @@ -0,0 +1,25 @@ +#!/bin/sh + +readonly cmd=$1 + +manage_config() { + docker run --user 1000:1000 --rm -it --workdir /mnt/abuild \ + -v dabuild-config:/mnt/abuild alpine sh +} + +usage() { + cat <<- EOF + dabuild: version (unknown) + + Available commands: + config: access abuild configuration + help: this help screen + EOF +} + + +case $cmd in + config) manage_config;; + help) usage;; + *) usage; exit 1;; +esac -- cgit v1.2.3 From 716a449699cbb8655f08ec400a878525cac836c7 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Fri, 10 Jan 2020 10:11:28 +0100 Subject: rename alpine based variables --- dabuild.in | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/dabuild.in b/dabuild.in index a548540..882684b 100755 --- a/dabuild.in +++ b/dabuild.in @@ -30,12 +30,18 @@ if [ "${PWD%*/aports/*}" = "$PWD" ]; then fi ## allow setting of arch by env variable -[ ! "$DABUILD_ARCH" ] && DABUILD_ARCH=$(uname -m) -case "$DABUILD_ARCH" in - x86|x86_64|aarch64|armhf|armv7 ) ;; +if [ "$DABUILD_ARCH" ]; then + ALPINE_ARCH=$DABUILD_ARCH +else + ALPINE_ARCH=$(uname -m) +fi + +case "$ALPINE_ARCH" in + x86|x86_64|aarch64|armhf|armv7);; + armv8l|arm) ALPINE_ARCH=armv7;; * ) die "Unsupported arch \"$DABUILD_ARCH\" detected." \ - "Expected one of: x86|x86_64|aarch64|armhf|armv7" \ - "You may force it setting DABUILD_ARCH=\"xxx\" in invocation";; + "Expected one of: x86|x86_64|aarch64|armhf|armv7" \ + "You may force it setting DABUILD_ARCH=\"xxx\" in invocation";; esac ## allow setting of `docker` command by env variable @@ -50,23 +56,19 @@ _DOCKER=$DABUILD_DOCKER ## use branch to figure out most appropriate alpine version if [ "$DABUILD_VERSION" ]; then - ABUILD_VERSION=$DABUILD_VERSION + ALPINE_RELEASE=$DABUILD_VERSION else APORTS_BRANCH=$(git status | head -1) APORTS_BRANCH="${APORTS_BRANCH##*[ /]}" case $APORTS_BRANCH in - [[:digit:]].[[:digit:]]-stable ) - ABUILD_VERSION=${APORTS_BRANCH%-stable} - ;; - - * ) - ABUILD_VERSION=edge - ;; + [[:digit:]].[[:digit:]]-stable) + ALPINE_RELEASE=${APORTS_BRANCH%-stable};; + *) ALPINE_RELEASE=edge;; esac fi ## check $DABUILD_PACKAGES is a writable directory -ABUILD_PACKAGES=${DABUILD_PACKAGES:-${PWD%/aports/*}/packages/${ABUILD_VERSION}} +ABUILD_PACKAGES=${DABUILD_PACKAGES:-${PWD%/aports/*}/packages/${ALPINE_RELEASE}} mkdir -p $ABUILD_PACKAGES if [ ! \( -d "$ABUILD_PACKAGES" -a -w "$ABUILD_PACKAGES" \) ]; then @@ -94,7 +96,7 @@ fi setup_named_volume() { local name=$1 dest=$2 single=$3 - local volume="dabuild-$name-$ALPINE_RELEASE-$DABUILD_ARCH" + local volume="dabuild-$name-$ALPINE_RELEASE-$ALPINE_ARCH" [ "$single" = "true" ] && volume="dabuild-$name" ABUILD_VOLUMES="$ABUILD_VOLUMES -v $volume:$dest" } @@ -122,4 +124,4 @@ $_DOCKER run --tty --interactive \ $DABUILD_ENV \ $DABUILD_ARGS \ --workdir /home/builder/aports/${PWD#*/aports/} \ - %%ABUILD_IMAGE%%:$ABUILD_VERSION-$DABUILD_ARCH "$@" + %%ABUILD_IMAGE%%:$ALPINE_RELEASE-$ALPINE_ARCH "$@" -- cgit v1.2.3 From c881e41b1d4f4722c4dbda6f646e50aa378e2298 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Fri, 10 Jan 2020 10:31:36 +0100 Subject: admin: add cmd to list all volumes --- dabuild-admin | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dabuild-admin b/dabuild-admin index 86c5da8..fe74182 100755 --- a/dabuild-admin +++ b/dabuild-admin @@ -7,12 +7,17 @@ manage_config() { -v dabuild-config:/mnt/abuild alpine sh } +list_volumes() { + docker volume ls --quiet --filter name="^dabuild" +} + usage() { cat <<- EOF dabuild: version (unknown) Available commands: config: access abuild configuration + volumes: list created dabuild volumes help: this help screen EOF } @@ -20,6 +25,7 @@ usage() { case $cmd in config) manage_config;; + volumes) list_volumes;; help) usage;; *) usage; exit 1;; esac -- cgit v1.2.3 From f597419fe1c16306f4c9a3257ed9df45245ca8fe Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Sat, 11 Jan 2020 15:11:24 +0100 Subject: entrypoint: simplify abuild key generation --- entrypoint.sh | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index a76a84d..84c5d6a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,18 +16,11 @@ fi # enable ccache if requested [ "$DABUILD_CCACHE" = "true" ] && export USE_CCACHE=1 -## generate signing keys on first run -if [ ! -r "$HOME/.abuild/abuild.conf" ]; then - abuild-keygen -n -a +# generate new abuild key if not set +if ! grep -sq "^PACKAGER_PRIVKEY=" "$HOME"/.abuild/abuild.conf; then + abuild-keygen -n -a fi -( - . "$HOME/.abuild/abuild.conf" - if [ ! -s "$PACKAGER_PRIVKEY" ]; then - abuild-keygen -n -a - fi -) - # make sure distfiles has correct permissions sudo install -d -m 775 -g abuild /var/cache/distfiles -- cgit v1.2.3 From a0b63da7c2b00144f963d70088a76f9fbb469c4c Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Sat, 11 Jan 2020 15:11:59 +0100 Subject: dabuild: do not mount hosts /etc/abuild.conf On Alpine (and also on other dists) its not safe to share the same abuild.conf for multiple Alpine releases and architectures. Use the users .abuild/abuild.conf instead. --- dabuild.in | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dabuild.in b/dabuild.in index 882684b..eb39b39 100755 --- a/dabuild.in +++ b/dabuild.in @@ -81,10 +81,6 @@ fi ABUILD_VOLUMES="-v ${PWD%/aports/*}/aports:/home/builder/aports \ -v ${ABUILD_PACKAGES}:/home/builder/packages" -if [ -f "/etc/abuild.conf" ]; then - ABUILD_VOLUMES="$ABUILD_VOLUMES -v /etc/abuild.conf:/etc/abuild.conf:ro" -fi - if [ -w "/var/cache/distfiles" ]; then ABUILD_VOLUMES="$ABUILD_VOLUMES -v /var/cache/distfiles:/var/cache/distfiles" fi -- cgit v1.2.3 From 314f30b4c9176699e5c0cb97060b79340bd7a713 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Sat, 11 Jan 2020 16:38:33 +0100 Subject: add default settings to users abuild.conf --- entrypoint.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 84c5d6a..51d7bac 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,15 @@ fi # enable ccache if requested [ "$DABUILD_CCACHE" = "true" ] && export USE_CCACHE=1 +# set some abuild defaults on first run +if [ ! -f "$HOME/.abuild/abuild.conf" ]; then + mkdir -p "$HOME"/.abuild/ + cat <<- EOF > "$HOME"/.abuild/abuild.conf + export JOBS=\$(nproc) + export MAKEFLAGS=-j\$JOBS + EOF +fi + # generate new abuild key if not set if ! grep -sq "^PACKAGER_PRIVKEY=" "$HOME"/.abuild/abuild.conf; then abuild-keygen -n -a -- cgit v1.2.3 From 08211018f3604ac016bf37ce6eb3ea83a394ced7 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Sat, 11 Jan 2020 17:49:45 +0100 Subject: make distfiles named volume/bind configuable: - set to true to enable named volume - set to absolute path to enable bind mount --- dabuild.conf | 5 +++++ dabuild.in | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dabuild.conf b/dabuild.conf index 227bb92..1d7cd37 100644 --- a/dabuild.conf +++ b/dabuild.conf @@ -17,6 +17,11 @@ # acting as caches. # DABUILD_CLEAN=false +# Use a bind mount or a named volume to store distfiles. +# to enable as a named volume set it to true +# to enable as a bind mount set it to an absolute path +# DABUILD_DISTFILES=false + # Output debug messages to stdout. # DABUILD_DEBUG=false diff --git a/dabuild.in b/dabuild.in index eb39b39..6839e8d 100755 --- a/dabuild.in +++ b/dabuild.in @@ -81,10 +81,6 @@ fi ABUILD_VOLUMES="-v ${PWD%/aports/*}/aports:/home/builder/aports \ -v ${ABUILD_PACKAGES}:/home/builder/packages" -if [ -w "/var/cache/distfiles" ]; then - ABUILD_VOLUMES="$ABUILD_VOLUMES -v /var/cache/distfiles:/var/cache/distfiles" -fi - # pass over gitconfig for abuild-keygen if [ -f "$HOME/.gitconfig" ]; then ABUILD_VOLUMES="$ABUILD_VOLUMES -v $HOME/.gitconfig:/home/builder/.gitconfig" @@ -106,6 +102,14 @@ if [ "$DABUILD_CCACHE" = "true" ]; then DABUILD_ENV="$DABUILD_ENV -e DABUILD_CCACHE=true" fi +# use a bind or named volume for distfiles. +DABUILD_DISTFILES=${DABUILD_DISTFILES:-false} +case $DABUILD_DISTFILES in + */*) ABUILD_VOLUMES="$ABUILD_VOLUMES -v $DABUILD_DISTFILES:/var/cache/distfiles";; + true) setup_named_volume distfiles "/var/cache/distfiles" true;; + *) ;; +esac + setup_named_volume config "/home/builder/.abuild" true ABUILD_RM="--rm" -- cgit v1.2.3 From 8dd4a740439ea72bb288f5b07cf204e0bdbe42c2 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Sat, 11 Jan 2020 22:17:45 +0100 Subject: admin: add enable multi-arch --- dabuild-admin | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dabuild-admin b/dabuild-admin index fe74182..87861d4 100755 --- a/dabuild-admin +++ b/dabuild-admin @@ -11,6 +11,11 @@ list_volumes() { docker volume ls --quiet --filter name="^dabuild" } +enable_multiarch() { + docker run --rm --privileged multiarch/qemu-user-static \ + --reset --persistent yes --credential yes +} + usage() { cat <<- EOF dabuild: version (unknown) @@ -18,6 +23,7 @@ usage() { Available commands: config: access abuild configuration volumes: list created dabuild volumes + multiarch: enable docker multi-arch support help: this help screen EOF } @@ -26,6 +32,7 @@ usage() { case $cmd in config) manage_config;; volumes) list_volumes;; + multiarch) enable_multiarch;; help) usage;; *) usage; exit 1;; esac -- cgit v1.2.3 From 7215f7a6723e8840c5ef55d07e88e57a6f24d979 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Mon, 13 Jan 2020 23:23:52 +0100 Subject: remove check for packages dir Packages dir is a docker volume and the mount point will be automatically created. Permissions will be correct from entrypoint. --- dabuild.in | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/dabuild.in b/dabuild.in index 6839e8d..78ec170 100755 --- a/dabuild.in +++ b/dabuild.in @@ -67,16 +67,10 @@ else esac fi -## check $DABUILD_PACKAGES is a writable directory +## set packages directory based on aports location if not set +## FIXME this will not append release dir if set manually ABUILD_PACKAGES=${DABUILD_PACKAGES:-${PWD%/aports/*}/packages/${ALPINE_RELEASE}} -mkdir -p $ABUILD_PACKAGES -if [ ! \( -d "$ABUILD_PACKAGES" -a -w "$ABUILD_PACKAGES" \) ]; then - die "Error: invalid or unwritable packages directory specified!" \ - "ABUILD_PACKAGES = '$ABUILD_PACKAGES'" \ - "DABUILD_PACKAGES = '$DABUILD_PACKAGES'" -fi - ## setup volumes; use named volumes as cache if desired ABUILD_VOLUMES="-v ${PWD%/aports/*}/aports:/home/builder/aports \ -v ${ABUILD_PACKAGES}:/home/builder/packages" -- cgit v1.2.3 From 4be94cb83ebc28d39e17c042bfe1e8755b45fb5c Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Mon, 13 Jan 2020 23:28:13 +0100 Subject: use git symbolic-ref to get branch name --- dabuild.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dabuild.in b/dabuild.in index 78ec170..a05c1bd 100755 --- a/dabuild.in +++ b/dabuild.in @@ -58,8 +58,7 @@ _DOCKER=$DABUILD_DOCKER if [ "$DABUILD_VERSION" ]; then ALPINE_RELEASE=$DABUILD_VERSION else - APORTS_BRANCH=$(git status | head -1) - APORTS_BRANCH="${APORTS_BRANCH##*[ /]}" + APORTS_BRANCH=$(git symbolic-ref --short -q HEAD) case $APORTS_BRANCH in [[:digit:]].[[:digit:]]-stable) ALPINE_RELEASE=${APORTS_BRANCH%-stable};; -- cgit v1.2.3 From 5203f3db49f90de3495519cf53ff90996755f114 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Tue, 14 Jan 2020 00:50:31 +0100 Subject: dabuild: set shell to catch unset vars assign default values early in dabuild --- dabuild.in | 65 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/dabuild.in b/dabuild.in index a05c1bd..162ba37 100755 --- a/dabuild.in +++ b/dabuild.in @@ -3,18 +3,33 @@ # Copyright (C) 2019 Richard Mortier # Licensed under the MIT License, https://opensource.org/licenses/MIT -set -e - -die () { - printf >&2 "%s\n" "$@" - exit 1 -} +set -eu # source the configuration if available if [ -f "/etc/dabuild.conf" ]; then . /etc/dabuild.conf fi +# set defaults +: "${DABUILD_DEBUG:=false}" +: "${DABUILD_ARCH:=$(uname -m)}" +: "${DABUILD_DOCKER:=docker}" +: "${DABUILD_VERSION=}" +: "${DABUILD_PACKAGES:=${PWD%/aports/*}/packages}}" +: "${DABUILD_APK_CACHE:=true}" +: "${DABUILD_CCACHE:=false}" +: "${DABUILD_DISTFILES:=false}" +: "${DABUILD_RM:=true}" +: "${DABUILD_ARGS=}" + +# reset vars +DABUILD_ENV= + +die () { + printf >&2 "%s\n" "$@" + exit 1 +} + ## debug if [ "$DABUILD_DEBUG" = "true" ]; then set -x @@ -29,23 +44,15 @@ if [ "${PWD%*/aports/*}" = "$PWD" ]; then exit 1 fi -## allow setting of arch by env variable -if [ "$DABUILD_ARCH" ]; then - ALPINE_ARCH=$DABUILD_ARCH -else - ALPINE_ARCH=$(uname -m) -fi - -case "$ALPINE_ARCH" in +case "$DABUILD_ARCH" in x86|x86_64|aarch64|armhf|armv7);; - armv8l|arm) ALPINE_ARCH=armv7;; + armv8l|arm) DABUILD_ARCH=armv7;; * ) die "Unsupported arch \"$DABUILD_ARCH\" detected." \ "Expected one of: x86|x86_64|aarch64|armhf|armv7" \ "You may force it setting DABUILD_ARCH=\"xxx\" in invocation";; esac ## allow setting of `docker` command by env variable -[ ! "$DABUILD_DOCKER" ] && DABUILD_DOCKER=docker case "$DABUILD_DOCKER" in podman|docker ) ;; * ) die "Unsupported docker CLI replacement \"$DABUILD_DOCKER\" detected." \ @@ -55,24 +62,21 @@ esac _DOCKER=$DABUILD_DOCKER ## use branch to figure out most appropriate alpine version -if [ "$DABUILD_VERSION" ]; then - ALPINE_RELEASE=$DABUILD_VERSION -else +if [ ! "$DABUILD_VERSION" ]; then APORTS_BRANCH=$(git symbolic-ref --short -q HEAD) case $APORTS_BRANCH in [[:digit:]].[[:digit:]]-stable) ALPINE_RELEASE=${APORTS_BRANCH%-stable};; - *) ALPINE_RELEASE=edge;; + *) DABUILD_VERSION=edge;; esac fi -## set packages directory based on aports location if not set -## FIXME this will not append release dir if set manually -ABUILD_PACKAGES=${DABUILD_PACKAGES:-${PWD%/aports/*}/packages/${ALPINE_RELEASE}} +# set packages dir based on alpine release +DABUILD_PACKAGES="$DABUILD_PACKAGES/$DABUILD_VERSION" ## setup volumes; use named volumes as cache if desired ABUILD_VOLUMES="-v ${PWD%/aports/*}/aports:/home/builder/aports \ - -v ${ABUILD_PACKAGES}:/home/builder/packages" + -v ${DABUILD_PACKAGES}:/home/builder/packages" # pass over gitconfig for abuild-keygen if [ -f "$HOME/.gitconfig" ]; then @@ -80,8 +84,8 @@ if [ -f "$HOME/.gitconfig" ]; then fi setup_named_volume() { - local name=$1 dest=$2 single=$3 - local volume="dabuild-$name-$ALPINE_RELEASE-$ALPINE_ARCH" + local name=$1 dest=$2 single="${3:-false}" + local volume="dabuild-$name-$DABUILD_VERSION-$DABUILD_ARCH" [ "$single" = "true" ] && volume="dabuild-$name" ABUILD_VOLUMES="$ABUILD_VOLUMES -v $volume:$dest" } @@ -96,7 +100,6 @@ if [ "$DABUILD_CCACHE" = "true" ]; then fi # use a bind or named volume for distfiles. -DABUILD_DISTFILES=${DABUILD_DISTFILES:-false} case $DABUILD_DISTFILES in */*) ABUILD_VOLUMES="$ABUILD_VOLUMES -v $DABUILD_DISTFILES:/var/cache/distfiles";; true) setup_named_volume distfiles "/var/cache/distfiles" true;; @@ -105,16 +108,14 @@ esac setup_named_volume config "/home/builder/.abuild" true -ABUILD_RM="--rm" -if [ "$DABUILD_RM" = "false" ]; then - ABUILD_RM="" +if [ "$DABUILD_RM" != "false" ]; then + DABUILD_ARGS="$DABUILD_ARGS --rm" fi ## go! $_DOCKER run --tty --interactive \ - $ABUILD_RM \ $ABUILD_VOLUMES \ $DABUILD_ENV \ $DABUILD_ARGS \ --workdir /home/builder/aports/${PWD#*/aports/} \ - %%ABUILD_IMAGE%%:$ALPINE_RELEASE-$ALPINE_ARCH "$@" + %%ABUILD_IMAGE%%:$DABUILD_VERSION-$DABUILD_ARCH "$@" -- cgit v1.2.3 From 9a099c23581b669ca3c958803e497b27f47352b0 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Tue, 14 Jan 2020 00:53:11 +0100 Subject: dabuild: alpine release can have more digits --- dabuild.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dabuild.in b/dabuild.in index 162ba37..de5e849 100755 --- a/dabuild.in +++ b/dabuild.in @@ -65,8 +65,7 @@ _DOCKER=$DABUILD_DOCKER if [ ! "$DABUILD_VERSION" ]; then APORTS_BRANCH=$(git symbolic-ref --short -q HEAD) case $APORTS_BRANCH in - [[:digit:]].[[:digit:]]-stable) - ALPINE_RELEASE=${APORTS_BRANCH%-stable};; + *-stable) DABUILD_VERSION=${APORTS_BRANCH%-stable};; *) DABUILD_VERSION=edge;; esac fi -- cgit v1.2.3 From 0c5cd4e259f07f2618f5acf98bbea1e2025a899b Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Tue, 14 Jan 2020 10:20:15 +0100 Subject: add editorconfig support and follow alpine coding style --- .editorconfig | 12 ++++++++++++ dabuild.in | 58 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 41 insertions(+), 29 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5665f37 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +; Editorconfig See http://editorconfig.org for details. + +# Top-most EditorConfig file. +root = true + +[*] +charset = utf-8 +indent_style = tab +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +; max_line_length = 80 diff --git a/dabuild.in b/dabuild.in index de5e849..3e389c5 100755 --- a/dabuild.in +++ b/dabuild.in @@ -26,48 +26,46 @@ fi DABUILD_ENV= die () { - printf >&2 "%s\n" "$@" + printf >&2 "%s\\n" "$@" exit 1 } ## debug if [ "$DABUILD_DEBUG" = "true" ]; then - set -x - PS4='$LINENO: ' - DABUILD_ENV="$DABUILD_ENV -e DABUILD_DEBUG=true" + set -x + PS4='$LINENO: ' + DABUILD_ENV="$DABUILD_ENV -e DABUILD_DEBUG=true" fi ## check running from within an `aports` tree if [ "${PWD%*/aports/*}" = "$PWD" ]; then - die "Error: expecting to be run from within an aports tree!" \ - "Could not find '/aports/' in the current path: $PWD" - exit 1 + die "Error: expecting to be run from within an aports tree!" \ + "Could not find '/aports/' in the current path: $PWD" fi case "$DABUILD_ARCH" in - x86|x86_64|aarch64|armhf|armv7);; - armv8l|arm) DABUILD_ARCH=armv7;; - * ) die "Unsupported arch \"$DABUILD_ARCH\" detected." \ - "Expected one of: x86|x86_64|aarch64|armhf|armv7" \ - "You may force it setting DABUILD_ARCH=\"xxx\" in invocation";; + x86|x86_64|aarch64|armhf|armv7);; + armv8l|arm) DABUILD_ARCH=armv7;; + *) die "Unsupported arch \"$DABUILD_ARCH\" detected." \ + "Expected one of: x86|x86_64|aarch64|armhf|armv7" \ + "You may force it setting DABUILD_ARCH=\"xxx\" in invocation";; esac ## allow setting of `docker` command by env variable case "$DABUILD_DOCKER" in - podman|docker ) ;; - * ) die "Unsupported docker CLI replacement \"$DABUILD_DOCKER\" detected." \ - "Expected one of: docker|podman" - ;; + podman|docker) ;; + *) die "Unsupported docker CLI replacement \"$DABUILD_DOCKER\" detected." \ + "Expected one of: docker|podman";; esac _DOCKER=$DABUILD_DOCKER ## use branch to figure out most appropriate alpine version if [ ! "$DABUILD_VERSION" ]; then - APORTS_BRANCH=$(git symbolic-ref --short -q HEAD) - case $APORTS_BRANCH in - *-stable) DABUILD_VERSION=${APORTS_BRANCH%-stable};; - *) DABUILD_VERSION=edge;; - esac + APORTS_BRANCH=$(git symbolic-ref --short -q HEAD) + case $APORTS_BRANCH in + *-stable) DABUILD_VERSION=${APORTS_BRANCH%-stable};; + *) DABUILD_VERSION=edge;; + esac fi # set packages dir based on alpine release @@ -75,11 +73,12 @@ DABUILD_PACKAGES="$DABUILD_PACKAGES/$DABUILD_VERSION" ## setup volumes; use named volumes as cache if desired ABUILD_VOLUMES="-v ${PWD%/aports/*}/aports:/home/builder/aports \ - -v ${DABUILD_PACKAGES}:/home/builder/packages" + -v ${DABUILD_PACKAGES}:/home/builder/packages" # pass over gitconfig for abuild-keygen if [ -f "$HOME/.gitconfig" ]; then - ABUILD_VOLUMES="$ABUILD_VOLUMES -v $HOME/.gitconfig:/home/builder/.gitconfig" + ABUILD_VOLUMES="$ABUILD_VOLUMES \ + -v $HOME/.gitconfig:/home/builder/.gitconfig" fi setup_named_volume() { @@ -100,7 +99,8 @@ fi # use a bind or named volume for distfiles. case $DABUILD_DISTFILES in - */*) ABUILD_VOLUMES="$ABUILD_VOLUMES -v $DABUILD_DISTFILES:/var/cache/distfiles";; + */*) ABUILD_VOLUMES="$ABUILD_VOLUMES \ + -v $DABUILD_DISTFILES:/var/cache/distfiles";; true) setup_named_volume distfiles "/var/cache/distfiles" true;; *) ;; esac @@ -113,8 +113,8 @@ fi ## go! $_DOCKER run --tty --interactive \ - $ABUILD_VOLUMES \ - $DABUILD_ENV \ - $DABUILD_ARGS \ - --workdir /home/builder/aports/${PWD#*/aports/} \ - %%ABUILD_IMAGE%%:$DABUILD_VERSION-$DABUILD_ARCH "$@" + $ABUILD_VOLUMES \ + $DABUILD_ENV \ + $DABUILD_ARGS \ + --workdir /home/builder/aports/"${PWD#*/aports/}" \ + %%ABUILD_IMAGE%%:$DABUILD_VERSION-$DABUILD_ARCH "$@" -- cgit v1.2.3 From 01864fcb022ea355be58f366d8e30ce5008a51f3 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Tue, 14 Jan 2020 10:21:45 +0100 Subject: admin: set shell to -eu --- dabuild-admin | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dabuild-admin b/dabuild-admin index 87861d4..a235f24 100755 --- a/dabuild-admin +++ b/dabuild-admin @@ -1,6 +1,8 @@ #!/bin/sh -readonly cmd=$1 +set -eu + +readonly cmd=${1:-help} manage_config() { docker run --user 1000:1000 --rm -it --workdir /mnt/abuild \ -- cgit v1.2.3 From 86fc81da6841708a04bcc4d084e03a43dc508334 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Sat, 18 Jan 2020 14:39:04 +0100 Subject: admin: multiarch add enable/disable with warning --- dabuild-admin | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/dabuild-admin b/dabuild-admin index a235f24..6303e9c 100755 --- a/dabuild-admin +++ b/dabuild-admin @@ -4,6 +4,24 @@ set -eu readonly cmd=${1:-help} +die() { + echo "$@" >&2 + exit 1 +} + +ask() { + local question="$1" + while true; do + # SC2039 -p is non posix but widely available + read -rp "$question" yn + case $yn in + [Yy]) return 0;; + [Nn]) exit;; + *) echo "Please answer y/n.";; + esac + done +} + manage_config() { docker run --user 1000:1000 --rm -it --workdir /mnt/abuild \ -v dabuild-config:/mnt/abuild alpine sh @@ -13,9 +31,27 @@ list_volumes() { docker volume ls --quiet --filter name="^dabuild" } -enable_multiarch() { - docker run --rm --privileged multiarch/qemu-user-static \ - --reset --persistent yes --credential yes +multiarch() { + case "${2:-help}" in + enable) ask "Are you sure you want to enable multi-arch system wide? (y/n): " + docker run --rm --privileged multiarch/qemu-user-static \ + --reset --persistent yes --credential yes ;; + disable) sudo --prompt="Sudo password:" find /proc/sys/fs/binfmt_misc \ + -type f -name 'qemu-*' -exec sh -c 'echo -1 > {}' \; ;; + help) multiarch_usage ;; + *) die "Unknown subcommand \"$2\"" ;; + esac +} + +multiarch_usage() { + cat <<- EOF + dabuild: version (unknown) + + Available subcommands: + enable: enable multi-arch support via binfmt_misc + disable: disable mutli-arch support + help: this help screen + EOF } usage() { @@ -30,11 +66,10 @@ usage() { EOF } - case $cmd in config) manage_config;; volumes) list_volumes;; - multiarch) enable_multiarch;; + multiarch) multiarch "$@";; help) usage;; *) usage; exit 1;; esac -- cgit v1.2.3 From 8ff016b9a6a8f131cef589ffb4a2eb35d7ad79e4 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Sat, 18 Jan 2020 14:47:15 +0100 Subject: admin: use correct program and uppercase globals --- dabuild-admin | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dabuild-admin b/dabuild-admin index 6303e9c..299cb6a 100755 --- a/dabuild-admin +++ b/dabuild-admin @@ -2,7 +2,9 @@ set -eu -readonly cmd=${1:-help} +readonly CMD=${1:-help} +readonly VERSION=unknown +readonly PROGRAM=${0##*/} die() { echo "$@" >&2 @@ -45,7 +47,7 @@ multiarch() { multiarch_usage() { cat <<- EOF - dabuild: version (unknown) + $PROGRAM ($VERSION) Available subcommands: enable: enable multi-arch support via binfmt_misc @@ -56,7 +58,7 @@ multiarch_usage() { usage() { cat <<- EOF - dabuild: version (unknown) + $PROGRAM ($VERSION) Available commands: config: access abuild configuration @@ -66,7 +68,7 @@ usage() { EOF } -case $cmd in +case $CMD in config) manage_config;; volumes) list_volumes;; multiarch) multiarch "$@";; -- cgit v1.2.3