fix(docker,buildx): 兼容本地registry 模式

This commit is contained in:
Zhang Dongliang
2023-06-14 14:37:57 +08:00
parent 3b74c006cc
commit f7051bc618
2 changed files with 92 additions and 64 deletions

3
.editorconfig Normal file
View File

@@ -0,0 +1,3 @@
[*.sh]
indent_style = space
indent_size = 4

View File

@@ -6,24 +6,24 @@ set -o errexit
set -o pipefail
if [ "$DEBUG" == "true" ]; then
set -ex ;export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -ex
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
fi
readlink_mac() {
cd `dirname $1`
TARGET_FILE=`basename $1`
cd $(dirname $1)
TARGET_FILE=$(basename $1)
# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
TARGET_FILE=`readlink $TARGET_FILE`
cd `dirname $TARGET_FILE`
TARGET_FILE=`basename $TARGET_FILE`
while [ -L "$TARGET_FILE" ]; do
TARGET_FILE=$(readlink $TARGET_FILE)
cd $(dirname $TARGET_FILE)
TARGET_FILE=$(basename $TARGET_FILE)
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
PHYS_DIR=`pwd -P`
PHYS_DIR=$(pwd -P)
REAL_PATH=$PHYS_DIR/$TARGET_FILE
}
@@ -40,7 +40,10 @@ get_current_arch() {
echo $current_arch
}
pushd $(cd "$(dirname "$0")"; pwd) > /dev/null
pushd $(
cd "$(dirname "$0")"
pwd
) >/dev/null
readlink_mac $(basename "$0")
cd "$(dirname "$REAL_PATH")"
CUR_DIR=$(pwd)
@@ -85,7 +88,6 @@ build_bin() {
esac
}
build_bundle_libraries() {
for bundle_component in 'host-image'; do
if [ $1 == $bundle_component ]; then
@@ -99,8 +101,25 @@ build_image() {
local tag=$1
local file=$2
local path=$3
local arch
if [[ "$tag" == *:5000/* ]]; then
arch=$(arch)
case $arch in
x86_64)
docker buildx build -t "$tag" -f "$2" "$3" --output type=docker --platform linux/amd64
;;
aarch64)
docker buildx build -t "$tag" -f "$2" "$3" --output type=docker --platform linux/arm64
;;
*)
echo wrong arch
exit 1
;;
esac
else
docker buildx build -t "$tag" -f "$2" "$3" --push
docker pull "$tag"
fi
}
buildx_and_push() {
@@ -188,6 +207,12 @@ make_manifest_image() {
echo "[$(readlink -f ${BASH_SOURCE}):${LINENO} ${FUNCNAME[0]}] return for DRY_RUN"
return
fi
if [[ "$img_name" == *:5000/* ]]; then
docker push $img_name-amd64
docker push $img_name-arm64
fi
docker manifest create --amend --insecure $img_name \
$img_name-amd64 \
$img_name-arm64