aboutsummaryrefslogtreecommitdiffstats
path: root/abuild.in
blob: 0b3f77eefa94d3ed57662a4e70a3b550e79b47c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh

set -e

## debug
if [ "$DOCKER_ABUILD_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 [ "$DOCKER_ABUILD_VERSION" ]; then
  ABUILD_VERSION=$DOCKER_ABUILD_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
"
if [ "$DOCKER_ABUILD_CACHE" = "true" ]; then
  for v in %%ABUILD_VOLUMES%% ; do
    vol=abuild-$ABUILD_VERSION-${v//\//_}
    if [ "$DOCKER_ABUILD_CLEAN" = "true" ]; then
      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 DOCKER_ABUILD_DEBUG $DOCKER_ABUILD_ARGS"
$DOCKER --workdir $ABUILD_WORKDIR %%ABUILD_IMAGE%%:$ABUILD_VERSION "$@"