From c552d8c1bf5f3cd6b0400dbcbdff97249c42521e Mon Sep 17 00:00:00 2001 From: He Lei Date: Wed, 14 Sep 2022 10:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8docker=20buildx,=20=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E6=94=AF=E6=8C=81=E8=B7=A8=E5=B9=B3=E5=8F=B0build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 . --- build_docker_images.sh | 68 +++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/build_docker_images.sh b/build_docker_images.sh index bc110256..7c8b855c 100644 --- a/build_docker_images.sh +++ b/build_docker_images.sh @@ -1,31 +1,36 @@ #!/bin/bash set -e -while getopts c:t:m:v: opt +while getopts c:t:p:m:v: opt do - case $opt in - t) - type=$OPTARG - ;; - v) + case $opt in + t) + type=$OPTARG + ;; + v) version=$OPTARG ;; + p) + platform=$OPTARG + ;; m) model=$OPTARG ;; - ?) - echo "unkonwn" - exit - ;; + ?) + echo "unkonwn" + exit + ;; 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,16 +39,36 @@ 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') ;; 'Release') ;; *) - echo "unkonwn model" - echo ".sh [-t build|push] [-m Debug|Release] [-v [version]]" - exit - ;; + echo "unkonwn model" + echo $help_string + exit + ;; esac namespace="zlmediakit" @@ -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" @@ -62,8 +88,8 @@ case $type in docker push $namespace/$packagename:$model.$version ;; *) - echo "unkonwn type" - echo ".sh [-t build|push] [-m Debug|Release] [-v [version]]" - exit - ;; + echo "unkonwn type" + echo $help_string + exit + ;; esac