-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen_image_buildx.sh
59 lines (50 loc) · 1.62 KB
/
gen_image_buildx.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
#!/usr/bin/env bash
#
IMAGE=ntopng
TAG=dev-latest
#TAG=latest-stable
DUSER=edgd1er
CACHE=""
#CACHE=" --no-cache"
aptcacher= #$(ip route get 1 | awk '{print $7}')
WHERE="--load"
#fonctions
enableMultiArch() {
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx rm amd-arm
docker buildx create --use --name amd-arm --driver-opt image=moby/buildkit:master --platform=linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/arm/v6
docker buildx inspect --bootstrap amd-arm
}
usage() {
echo "Usage: $0 [-n ] no build cache [ -l ] load into docker images, , [ -p ] push to registry ]" 1>&2
exit 1
}
while getopts ":hlpn" option; do
case "${option}" in
h)
usage
exit 1
;;
l)
WHERE="--load"
;;
n)
CACHE="--no-cache"
;;
p)
WHERE="--push"
;;
*)
usage
;;
esac
done
shift $((OPTIND - 1))
##add amd if running on amd
[[ $(uname -m) =~ "x86_64" ]] && PTF="linux/amd64" || PTF="linux/arm/v7"
[[ ${WHERE} =~ push ]] && PTF+=",linux/arm/v7" && enableMultiArch
echo -e "\nWhere: \e[32m$WHERE\e[0m, building \e[32m$TAG\e[0m with cached apt \e[32m${aptcacher:-\"none\"}\e[0m using cache \e[32m$CACHE\e[0m and apt cache \e[32m$aptCacher\e[0m for platform \e[32m${PTF}\e[0m\n\n"
docker buildx build ${WHERE} --platform ${PTF} --build-arg TAG=${TAG} --build-arg DEBIAN_VER=bullseye --build-arg TZ=America/Chicago --build-arg aptcacher=${aptcacher} -f Dockerfile.all -t ${DUSER}/${IMAGE}:${TAG} .
ret=$?
[[ ${ret} != "0" ]] && echo "\n error while building image" && exit 1
#docker manifest create edgd1er/ntopng-docker edgd1er/ntopng-docker:armhf edgd1er/ntopng-docker:amd64