This repository has been archived by the owner on Feb 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·125 lines (109 loc) · 2.68 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
set -eu
PROGNAME=$(basename $0)
BASEDIR=$(cd $(dirname $0); pwd)
PREFIX=$(id -un)
NO_CACHE=no
SQUASH=no
help() {
cat <<EOF >&2
Build a Docker image for an architecture
Usage:
$PROGNAME -h | --help
$PROGNAME [--prefix <prefix>] <arch>
Options:
-h, --help Show help
--prefix <prefix> Prefix of the Docker Image (Default: $PREFIX)
--no-cache Do not use cache when building the image
--squash Squash newly built layers into a single new layer
Arguments:
<arch> Architecture of the Docker image (amd64|armv5|armv7|arm64)
EOF
exit 0
}
error() {
echo "$1" >&2
exit 1
}
while [ $# -gt 0 ]
do
case $1 in
'-h' | '--help')
help
;;
'--prefix')
PREFIX="$2"
shift 2
;;
'--no-cache')
NO_CACHE=yes
shift
;;
'--squash')
SQUASH=yes
shift
;;
*)
break
;;
esac
done
ARCH=$1
case $ARCH in
amd64)
# Assumed that the CPU architecture of build machine is amd64
#DOCKERFILE=Dockerfile.cross
#BASE_IMAGE=amd64/debian:buster-slim
#DEBIAN_ARCH=amd64
#GCC_HOST_TRIPLE=x86-64-linux-gnu
#RUST_TARGET_TRIPLE=x86_64-unknown-linux-gnu
DOCKERFILE=Dockerfile
BASE_IMAGE=
DEBIAN_ARCH=
GCC_HOST_TRIPLE=
RUST_TARGET_TRIPLE=
;;
armv5)
DOCKERFILE=Dockerfile.cross
BASE_IMAGE=arm32v5/debian:buster-slim
DEBIAN_ARCH=armel
GCC_HOST_TRIPLE=arm-linux-gnueabi
RUST_TARGET_TRIPLE=arm-unknown-linux-gnueabi
;;
armv7)
DOCKERFILE=Dockerfile.cross
BASE_IMAGE=arm32v7/debian:buster-slim
DEBIAN_ARCH=armhf
GCC_HOST_TRIPLE=arm-linux-gnueabihf
RUST_TARGET_TRIPLE=armv7-unknown-linux-gnueabihf
;;
arm64)
DOCKERFILE=Dockerfile.cross
DEBIAN_ARCH=arm64
BASE_IMAGE=arm64v8/debian:buster-slim
GCC_HOST_TRIPLE=aarch64-linux-gnu
RUST_TARGET_TRIPLE=aarch64-unknown-linux-gnu
;;
*)
error "Unsupported: $ARCH"
;;
esac
cat <<EOF >&2
PREFIX : $PREFIX
NO_CAACHE : $NO_CACHE
SQUASH : $SQUASH
ARCH : $ARCH
EOF
BUILD_OPTIONS=
if [ "$NO_CACHE" = yes ]; then
BUILD_OPTIONS="$BUILD_OPTIONS --no-cache"
fi
if [ "$SQUASH" = yes ]; then
BUILD_OPTIONS="$BUILD_OPTIONS --squash"
fi
docker build $BUILD_OPTIONS -t $PREFIX/mirakc:$ARCH -f $DOCKERFILE \
--build-arg base_image=$BASE_IMAGE \
--build-arg debian_arch=$DEBIAN_ARCH \
--build-arg gcc_host_triple=$GCC_HOST_TRIPLE \
--build-arg rust_target_triple=$RUST_TARGET_TRIPLE \
.