-
Notifications
You must be signed in to change notification settings - Fork 115
/
cross-build.sh
86 lines (66 loc) · 1.44 KB
/
cross-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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# cross comiple for arm using Docker Late Lee<[email protected]>
#
# docker >= 17.05.0-ce
# host kernel >= 4.8
# TODO: build arm & x86 in one script file
#!/bin/bash
set -e
ARCH=arm64v8 #arm32v7
main(){
if [ `whoami` != "root" ];then
echo "please using root"
exit
fi
#if [[ $# != 1 ]]; then
# usage
# exit
#fi
echo "begin at"
date
docker_prepare arm64
docker_build
echo "finish at"
date
}
usage() {
echo "Usage:"
echo "$0 arm | arm64"
}
myexit() {
echo "error exit at:"
date
exit 0
}
prepare_qemu(){
sudo apt-get install qemu-user-static
}
docker_prepare(){
arch=$@
if [[ $arch == arm ]]; then
ARCH=arm32v7
elif [[ $arch == arm64 ]]; then
ARCH=arm64v8
else
echo "$arch not support"
exit
fi
echo "build arch: " $ARCH
}
docker_build(){
if [[ ! -f /usr/bin/qemu-aarch64-static ]]; then
echo "install qemu..."
apt-get install qemu-user-static -y
fi
echo "setting env..."
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes || myexit
echo "building..."
docker build -t metaverse -f docker/Dockerfile.cross --build-arg BUILD_FROM=$ARCH . || myexit
echo "copying..."
docker run -d --rm --name foobar metaverse || myexit
rm -rf output && mkdir -p output
docker cp foobar:/usr/local/lib output
docker cp foobar:/usr/local/bin output
docker rm -f foobar
echo "Done"
}
main $@