diff options
Diffstat (limited to 'dabuild.in')
| -rwxr-xr-x | dabuild.in | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/dabuild.in b/dabuild.in new file mode 100755 index 0000000..91b2c50 --- /dev/null +++ b/dabuild.in @@ -0,0 +1,60 @@ +#!/bin/sh + +# Copyright (C) 2019 Richard Mortier <mort@cantab.net> +# Licensed under the MIT License, https://opensource.org/licenses/MIT + +set -e + +## debug +if [ "$DABUILD_DEBUG" = "true" ]; then + set -x + PS4='$LINENO: ' +fi + +## check running from within an `aports` tree +if [ "${PWD%*/aports*}" = "$PWD" ]; then + echo "Error: expecting to be run from within an aports tree!" + echo "Could not find '/aports' in the current path ($PWD)" + exit 1 +fi + +## use branch to figure out most appropriate alpine version +if [ "$DABUILD_VERSION" ]; then + ABUILD_VERSION=$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 + ;; + esac +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 + -v ${PWD%/aports*}/packages:/home/builder/packages +" +if [ "$DABUILD_CACHE" = "true" ]; then + for v in %%ABUILD_VOLUMES%% ; do + vol=abuild-$ABUILD_VERSION-${v//\//_} + if [ "$DABUILD_CLEAN" = "true" ]; then + ## clean the cache if requested + docker rm -f $(docker ps -qaf "volume=$vol") >/dev/null 2>/dev/null || true + docker volume rm $vol >/dev/null + docker volume create $vol >/dev/null + fi + ABUILD_VOLUMES="$ABUILD_VOLUMES -v $vol:/$v" + done +fi + +## go! +ABUILD_WORKDIR=/home/builder/aports${PWD#*/aports} +DOCKER="docker run -ti $ABUILD_VOLUMES -e DABUILD_DEBUG $DABUILD_ARGS" +$DOCKER --workdir $ABUILD_WORKDIR %%ABUILD_IMAGE%%:$ABUILD_VERSION "$@" |
