forked from Cambricon/mlu-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_image.sh
executable file
·93 lines (78 loc) · 2.61 KB
/
build_image.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
87
88
89
90
91
92
93
#!/bin/bash
# Copyright 2020 Cambricon, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
curpath=$(dirname "$0")
cd "$curpath" || exit 1
: "${TAG:=v1.5.0}"
: "${ARCH:=amd64}"
: "${LIBCNDEV:=/usr/local/neuware/lib64/libcndev.so}"
echo "Build environ (Can be overridden):"
echo "TAG = $TAG"
echo "ARCH = $ARCH"
echo "LIBCNDEV = $LIBCNDEV"
echo "APT_PROXY = $APT_PROXY"
echo "GOPROXY = $GOPROXY"
case $(uname -m) in
x86_64)
build_arch=amd64
;;
aarch64*)
build_arch=arm64
;;
armv8*)
build_arch=arm64
esac
rm -rf "$curpath/image"
mkdir -p "$curpath/image"
# Cambricon neuware installation path
if [[ ! -f "$LIBCNDEV" ]]; then
echo "Can't find libcndev.so at $LIBCNDEV."
echo "Please install Cambricon neuware, or set LIBCNDEV environ to path of libcndev.so"
exit 1
fi
case $ARCH in
amd64)
file_arch=x86-64
;;
arm64)
file_arch=aarch64
;;
*)
echo "Unknown arch $ARCH"
exit 1
esac
if ! file "$LIBCNDEV" --dereference | grep -q "$file_arch"; then
echo "$LIBCNDEV is not for $ARCH"
exit 1
fi
cp "$LIBCNDEV" "$curpath/libs/linux/$ARCH/"
echo "Building Cambricon MLU Exporter docker image."
# Legacy build for docker 18.06.
# Remove this when docker is upgraded to 19.03 in all environ.
[[ "$ARCH" == "$build_arch" ]] && docker build -t "cambricon-mlu-exporter:$TAG" \
--build-arg "GOPROXY=$GOPROXY" --build-arg "APT_PROXY=$APT_PROXY" \
--build-arg "BUILDPLATFORM=linux/$ARCH" \
--build-arg "TARGETPLATFORM=linux/$ARCH" .
[[ "$ARCH" == "$build_arch" ]] && docker save -o "image/cambricon-mlu-exporter-$ARCH.tar" \
"cambricon-mlu-exporter:$TAG"
if [[ "$ARCH" != "$build_arch" && "$(docker version -f '{{ge .Client.Version "19.03"}}')" != "true" ]]; then
echo "Needs docker 19.03 and above"
exit 1
fi
[[ "$ARCH" != "$build_arch" ]] && DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build \
--platform="linux/$ARCH" -t "cambricon-mlu-exporter:$TAG" \
--build-arg "GOPROXY=$GOPROXY" --build-arg "APT_PROXY=$APT_PROXY" \
--output type=docker,dest="./image/cambricon-mlu-exporter-$ARCH.tar" .
echo "Image is saved at ./image/cambricon-mlu-exporter-$ARCH.tar"
rm -f "$curpath/libs/linux/$ARCH/libcndev.so"