forked from tsaarni/docker-deb-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·88 lines (70 loc) · 2.29 KB
/
build
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash -e
PROG=$(basename $0)
PROG_DIR=$(dirname $0)
function usage {
cat <<EOF 1>&2
usage: $PROG [options...] SOURCEDIR
Options:
-i IMAGE Name of the docker image (including tag) to use as package build environment.
-o DIR Destination directory to store packages to.
-d DIR Directory that contains other deb packages that need to be installed before build.
EOF
exit 1
}
function fatal {
echo "$PROG: ${1:-"Unknown Error"}" 1>&2
exit 1
}
function abspath {
echo $(cd "$1" && pwd)
}
###########################################################################
[[ $# -eq 0 ]] && usage
while getopts "i:o:d:h" opt; do
case $opt in
i)
image="$OPTARG"
;;
o)
outdir="$OPTARG"
;;
d)
depdir="$OPTARG"
;;
h)
usage
;;
*)
usage
;;
esac
done
shift $(($OPTIND - 1))
srcdir=$1
docker_args="-it "
# Check that mandatory parameters are valid
[[ ! "$outdir" ]] && fatal "output directory was not given (-o DIR)"
[[ ! -d "$outdir" ]] && fatal "output directory does not exist: $outdir"
[[ ! "$srcdir" ]] && fatal "source directory not given"
[[ ! -r "$srcdir/debian" ]] && fatal "source direcotry does not contain debian sub directory"
[[ ! "$image" ]] && fatal "docker image name not given (-i IMAGE)"
# Check that optional parameters are valid
if [[ "$depdir" ]]; then
[[ ! -d "$depdir" ]] && fatal "dependency directory given but does not exist: $depdir"
docker_args+="-v $(abspath "$depdir"):/dependencies:ro "
fi
docker_args+="-v $(abspath "$srcdir"):/source-ro:ro -v $(abspath "$outdir"):/output -v $(cd $PROG_DIR; pwd)/build-helper.sh:/build-helper.sh:ro "
# Pass current UID and GID to container, so that it can change the
# ownership of output files which are otherwise writen to outdir as
# root
docker_args+="-e USER=$(id -u) -e GROUP=$(id -g) "
# Comment following out if you want to keep container after execution
# for debugging
docker_args+="--rm "
# Workaround for the Qt RCC problem, see:
# https://stackoverflow.com/a/52084936
docker_args+="--security-opt seccomp:unconfined "
cmd="docker run -it $docker_args $image /build-helper.sh"
echo "Running docker:"
echo "$cmd"
exec $cmd