-
Notifications
You must be signed in to change notification settings - Fork 582
/
run-docker.sh
executable file
·81 lines (65 loc) · 1.56 KB
/
run-docker.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
set -e
set -o pipefail
#set -x
PLATFORM=$1
ARCH=$2
IMAGE=$3
OUT_DIR=$4
Q=$5
# Colors
RED="\x1b[31m"
GREEN="\x1b[32m"
YELLOW="\x1b[33m"
BLUE="\x1b[34m"
RESET="\x1b[0m"
ERASE_LINE="\x1b[2K"
# Find our real path of this directory
REALPATH=
for bin in realpath grealpath; do
##echo "Testing for ${bin}..."
if [ -x "`which $bin`" ]; then
REALPATH=`which $bin`
fi
done
if [ -z "$REALPATH" ]; then
printf "${RED}ERROR:${RESET} Could not find 'realpath' binary\n"
exit 1
fi
ROOT=`$REALPATH .`
if [ -z "$PLATFORM" ]; then
printf "${RED}ERROR:${RESET} No platform specified\n"
exit 1
fi
if [ -z "$ARCH" ]; then
printf "${RED}ERROR:${RESET} No architecture specified\n"
exit 1
fi
if [ -z "$IMAGE" ]; then
printf "${RED}ERROR:${RESET} No container specified\n"
exit 1
fi
if [ ! -d "$OUT_DIR" ]; then
printf "${RED}ERROR:${RESET} Output directory not given or not a directory\n"
printf " $$OUT_DIR = $OUT_DIR\n"
exit 1
fi
CID=$(docker run \
-d \
--name=static-build-${PLATFORM}-${ARCH} \
-v ${ROOT}/make:/make \
-v ${OUT_DIR}:/output \
$IMAGE \
/bin/bash \
-c "cd /make && make PLATFORM=${PLATFORM} ARCH=${ARCH} Q=$Q install"
)
DESC=$(printf "%s/%s" "$PLATFORM" "$ARCH")
HEADER=$(printf " ${GREEN}%-10s${RESET} | ${BLUE}%-15s${RESET} | %s | " "DOCKER" "$DESC" "${CID:0:12}")
printf "${HEADER}${YELLOW}WAITING${RESET}"
EXIT_CODE=$(docker wait $CID)
if [ "$EXIT_CODE" == "0" ]; then
docker rm $CID >/dev/null
printf "\r${ERASE_LINE}${HEADER}${GREEN}SUCCESS${RESET}\n"
else
printf "\r${ERASE_LINE}${HEADER}${RED}ERROR (code %d)${RESET}\n" "$EXIT_CODE"
fi