使用docker buildx, 用于支持跨平台build

docker buildx build --platform=$platform --network=host --build-arg MODEL=$model -t $namespace/$packagename:$model.$version .
#docker build --network=host --build-arg MODEL=$model -t $namespace/$packagename:$model.$version .
This commit is contained in:
He Lei 2022-09-14 10:08:18 +08:00 committed by GitHub
parent 08789454c3
commit c552d8c1bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
#!/bin/bash
set -e
while getopts c:t:m:v: opt
while getopts c:t:p:m:v: opt
do
case $opt in
t)
@ -9,6 +9,9 @@ do
v)
version=$OPTARG
;;
p)
platform=$OPTARG
;;
m)
model=$OPTARG
;;
@ -19,13 +22,15 @@ do
esac
done
help_string=".sh [-t build|push] [-p (amd64|arm64|...,default is `arch`) ] [-m Debug|Release] [-v [version]]"
if [[ ! -n $type ]];then
echo ".sh [-t build|push] [-m Debug|Release] [-v [version]]"
echo $help_string
exit
fi
if [[ ! -n $model ]];then
echo ".sh [-t build|push] [-m Debug|Release] [-v [version]]"
echo $help_string
exit
fi
@ -34,6 +39,26 @@ if [[ ! -n $version ]];then
version="latest"
fi
if [[ ! -n $platform ]];then
platform=`arch`
echo "auto select arch:${platform}"
fi
case $platform in
"arm64")
#eg:osx
platform="linux/arm64"
;;
"x86_64"|"amd64")
platform="linux/amd64"
;;
*)
echo "unknown cpu-arch ${platform}"
echo "Use 'docker buildx ls' to get supported ARCH"
exit
;;
esac
case $model in
'Debug')
;;
@ -41,7 +66,7 @@ case $model in
;;
*)
echo "unkonwn model"
echo ".sh [-t build|push] [-m Debug|Release] [-v [version]]"
echo $help_string
exit
;;
esac
@ -53,7 +78,8 @@ case $type in
'build')
rm -rf ./build/CMakeCache.txt
# 以腾讯云账号为例
docker build --network=host --build-arg MODEL=$model -t $namespace/$packagename:$model.$version .
docker buildx build --platform=$platform --network=host --build-arg MODEL=$model -t $namespace/$packagename:$model.$version .
#docker build --network=host --build-arg MODEL=$model -t $namespace/$packagename:$model.$version .
;;
'push')
echo "push to dst registry"
@ -63,7 +89,7 @@ case $type in
;;
*)
echo "unkonwn type"
echo ".sh [-t build|push] [-m Debug|Release] [-v [version]]"
echo $help_string
exit
;;
esac