Commit 1b516171 authored by Richard Mortier's avatar Richard Mortier

Merge branch 'multiple_fixes' into 'master'

Multiple fixes and features

See merge request !60
parents f0862dd4 8ff016b9
Pipeline #6518 passed with stages
in 14 minutes and 35 seconds
; 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
#!/bin/sh
set -eu
readonly CMD=${1:-help}
readonly VERSION=unknown
readonly PROGRAM=${0##*/}
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
}
list_volumes() {
docker volume ls --quiet --filter name="^dabuild"
}
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
$PROGRAM ($VERSION)
Available subcommands:
enable: enable multi-arch support via binfmt_misc
disable: disable mutli-arch support
help: this help screen
EOF
}
usage() {
cat <<- EOF
$PROGRAM ($VERSION)
Available commands:
config: access abuild configuration
volumes: list created dabuild volumes
multiarch: enable docker multi-arch support
help: this help screen
EOF
}
case $CMD in
config) manage_config;;
volumes) list_volumes;;
multiarch) multiarch "$@";;
help) usage;;
*) usage; exit 1;;
esac
......@@ -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
......
......@@ -3,121 +3,118 @@
# Copyright (C) 2019 Richard Mortier <mort@cantab.net>
# 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
PS4='$LINENO: '
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
## allow setting of arch by env variable
[ ! "$DABUILD_ARCH" ] && DABUILD_ARCH=$(uname -m)
case "$DABUILD_ARCH" in
x86|x86_64|aarch64|armhf|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
[ ! "$DABUILD_DOCKER" ] && DABUILD_DOCKER=docker
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
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
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
fi
## check $DABUILD_PACKAGES is a writable directory
ABUILD_PACKAGES=${DABUILD_PACKAGES:-${PWD%/aports/*}/packages/${ABUILD_VERSION}}
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
# 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 ${HOME}/.abuild:/home/builder/.abuild \
-v ${PWD%/aports/*}/aports:/home/builder/aports \
-v ${ABUILD_PACKAGES}:/home/builder/packages"
ABUILD_VOLUMES="-v ${PWD%/aports/*}/aports:/home/builder/aports \
-v ${DABUILD_PACKAGES}:/home/builder/packages"
if [ -f "/etc/abuild.conf" ]; then
ABUILD_VOLUMES="$ABUILD_VOLUMES -v /etc/abuild.conf:/etc/abuild.conf:ro"
# pass over gitconfig for abuild-keygen
if [ -f "$HOME/.gitconfig" ]; then
ABUILD_VOLUMES="$ABUILD_VOLUMES \
-v $HOME/.gitconfig:/home/builder/.gitconfig"
fi
if [ -w "/var/cache/distfiles" ]; then
ABUILD_VOLUMES="$ABUILD_VOLUMES -v /var/cache/distfiles:/var/cache/distfiles"
fi
setup_named_volume() {
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"
}
# pass over gitconfig for abuild-keygen
if [ -f "$HOME/.gitconfig" ]; then
ABUILD_VOLUMES="$ABUILD_VOLUMES -v $HOME/.gitconfig:/home/builder/.gitconfig"
if [ "$DABUILD_APK_CACHE" = "true" ]; then
setup_named_volume apkcache "/etc/apk/cache"
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
if [ "$DABUILD_CCACHE" = "true" ]; then
setup_named_volume ccache "/home/builder/.ccache"
DABUILD_ENV="$DABUILD_ENV -e DABUILD_CCACHE=true"
fi
ABUILD_RM="--rm"
if [ "$DABUILD_RM" = "false" ]; then
ABUILD_RM=""
# use a bind or named volume for distfiles.
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
if [ "$DABUILD_RM" != "false" ]; then
DABUILD_ARGS="$DABUILD_ARGS --rm"
fi
## go!
$_DOCKER run --tty --interactive \
$ABUILD_RM \
$ABUILD_VOLUMES \
-e DABUILD_DEBUG \
$DABUILD_ARGS \
--workdir /home/builder/aports/${PWD#*/aports/} \
%%ABUILD_IMAGE%%:$ABUILD_VERSION-$DABUILD_ARCH "$@"
$ABUILD_VOLUMES \
$DABUILD_ENV \
$DABUILD_ARGS \
--workdir /home/builder/aports/"${PWD#*/aports/}" \
%%ABUILD_IMAGE%%:$DABUILD_VERSION-$DABUILD_ARCH "$@"
......@@ -13,22 +13,32 @@ 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)]"
# 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 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
# 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment