-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·67 lines (57 loc) · 1.39 KB
/
build.sh
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
#!/usr/bin/env bash
set -e
set -o pipefail
function usage() {
echo "Usage: [DOCKER_PLATFORM=os/arch] $0 target"
echo "Runs the build in a predictable Docker environment."
echo "'target' is a build target (try 'help')."
echo "DOCKER_PLATFORM can optionally be set."
exit 1
}
if [ $# -lt 1 ] ; then
usage
fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ] ; then
usage
fi
TTY=""
if [ -t 0 ]; then
TTY="--tty"
fi
if [ -z "$DOCKER_PLATFORM" ] ; then
DOCKER_PLATFORM="linux/$(docker system info --format '{{.Architecture}}')"
fi
GID="$(id -g)"
GROUP="$(getent group $(getent passwd $USER | cut -d: -f4) | cut -d: -f1)"
GIT_ROOT="$(cd $(dirname $0) && git rev-parse --show-toplevel)"
if ! test -d "$GIT_ROOT"/.cache ; then
mkdir "$GIT_ROOT"/.cache
fi
DOCKER_IMAGE="$(docker build \
--platform ${DOCKER_PLATFORM} \
--build-arg USER="$USER" \
--build-arg UID="$UID" \
--build-arg GROUP="$GROUP" \
--build-arg GID="$GID" \
--build-arg HOME="$HOME" \
--quiet \
.
)"
NAME="rrb-$$"
function kill_container() {
docker kill --signal SIGKILL "${NAME}" &>/dev/null || true
}
trap kill_container EXIT
docker run \
--name "${NAME}" \
--platform ${DOCKER_PLATFORM} \
--user "${UID}:${GID}" \
--rm \
${TTY} \
--interactive \
--volume ${GIT_ROOT}:${HOME}/rrb \
--volume ${GIT_ROOT}/.cache:${HOME}/.cache \
--volume ${HOME}/rrb/.cache \
--workdir ${HOME}/rrb \
${DOCKER_IMAGE} \
make --no-print-directory "${@}"