mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-05-06 21:52:54 +08:00
fix(docker,buildx): 兼容本地registry 模式
This commit is contained in:
@@ -6,46 +6,49 @@ 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`
|
||||
done
|
||||
# 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)
|
||||
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`
|
||||
REAL_PATH=$PHYS_DIR/$TARGET_FILE
|
||||
# Compute the canonicalized name by finding the physical path
|
||||
# for the directory we're in and appending the target file.
|
||||
PHYS_DIR=$(pwd -P)
|
||||
REAL_PATH=$PHYS_DIR/$TARGET_FILE
|
||||
}
|
||||
|
||||
get_current_arch() {
|
||||
local current_arch
|
||||
case $(uname -m) in
|
||||
x86_64)
|
||||
current_arch=amd64
|
||||
;;
|
||||
aarch64)
|
||||
current_arch=arm64
|
||||
;;
|
||||
x86_64)
|
||||
current_arch=amd64
|
||||
;;
|
||||
aarch64)
|
||||
current_arch=arm64
|
||||
;;
|
||||
esac
|
||||
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)
|
||||
SRC_DIR=$(cd .. && pwd)
|
||||
popd > /dev/null
|
||||
popd >/dev/null
|
||||
|
||||
DOCKER_DIR="$SRC_DIR/build/docker"
|
||||
|
||||
@@ -63,29 +66,28 @@ build_bin() {
|
||||
local BUILD_ARCH=$2
|
||||
local BUILD_CGO=$3
|
||||
case "$1" in
|
||||
host-image)
|
||||
rm -vf _output/bin/$1
|
||||
rm -rvf _output/bin/bundles/$1
|
||||
if [ -z "$LIBQEMUIO_PATH" ]; then
|
||||
echo "Need set \$LIBQEMUIO_PATH env to build host-image"
|
||||
exit 1
|
||||
fi
|
||||
GOOS=linux make cmd/$1
|
||||
;;
|
||||
climc)
|
||||
rm -vf _output/bin/*cli
|
||||
env $BUILD_ARCH $BUILD_CGO make -C "$SRC_DIR" docker-alpine-build F="cmd/$1 cmd/*cli"
|
||||
;;
|
||||
host-deployer | telegraf-raid-plugin)
|
||||
env $BUILD_ARCH $BUILD_CGO make -C "$SRC_DIR" docker-centos-build F="cmd/$1"
|
||||
;;
|
||||
*)
|
||||
env $BUILD_ARCH $BUILD_CGO make -C "$SRC_DIR" docker-alpine-build F="cmd/$1"
|
||||
;;
|
||||
host-image)
|
||||
rm -vf _output/bin/$1
|
||||
rm -rvf _output/bin/bundles/$1
|
||||
if [ -z "$LIBQEMUIO_PATH" ]; then
|
||||
echo "Need set \$LIBQEMUIO_PATH env to build host-image"
|
||||
exit 1
|
||||
fi
|
||||
GOOS=linux make cmd/$1
|
||||
;;
|
||||
climc)
|
||||
rm -vf _output/bin/*cli
|
||||
env $BUILD_ARCH $BUILD_CGO make -C "$SRC_DIR" docker-alpine-build F="cmd/$1 cmd/*cli"
|
||||
;;
|
||||
host-deployer | telegraf-raid-plugin)
|
||||
env $BUILD_ARCH $BUILD_CGO make -C "$SRC_DIR" docker-centos-build F="cmd/$1"
|
||||
;;
|
||||
*)
|
||||
env $BUILD_ARCH $BUILD_CGO make -C "$SRC_DIR" docker-alpine-build F="cmd/$1"
|
||||
;;
|
||||
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
|
||||
docker buildx build -t "$tag" -f "$2" "$3" --push
|
||||
docker pull "$tag"
|
||||
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() {
|
||||
@@ -158,13 +177,13 @@ build_process_with_buildx() {
|
||||
fi
|
||||
|
||||
case "$component" in
|
||||
host | torrent)
|
||||
buildx_and_push $img_name $DOCKER_DIR/multi-arch/Dockerfile.$component $SRC_DIR $arch
|
||||
;;
|
||||
*)
|
||||
build_bin $component $build_env
|
||||
buildx_and_push $img_name $DOCKER_DIR/Dockerfile.$component $SRC_DIR $arch
|
||||
;;
|
||||
host | torrent)
|
||||
buildx_and_push $img_name $DOCKER_DIR/multi-arch/Dockerfile.$component $SRC_DIR $arch
|
||||
;;
|
||||
*)
|
||||
build_bin $component $build_env
|
||||
buildx_and_push $img_name $DOCKER_DIR/Dockerfile.$component $SRC_DIR $arch
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -188,13 +207,19 @@ 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
|
||||
docker manifest annotate $img_name --arch amd64 --os linux $img_name-amd64
|
||||
docker manifest annotate $img_name --arch arm64 --os linux $img_name-arm64
|
||||
docker manifest inspect ${img_name} | grep -wq amd64
|
||||
docker manifest inspect ${img_name} | grep -wq arm64
|
||||
docker manifest inspect ${img_name} | grep -wq amd64
|
||||
docker manifest inspect ${img_name} | grep -wq arm64
|
||||
docker manifest push --insecure $img_name
|
||||
}
|
||||
|
||||
@@ -228,16 +253,16 @@ for component in $COMPONENTS; do
|
||||
fi
|
||||
|
||||
case "$ARCH" in
|
||||
all)
|
||||
for arch in "arm64" "amd64"; do
|
||||
general_build $component $arch "true"
|
||||
done
|
||||
make_manifest_image $component
|
||||
;;
|
||||
*)
|
||||
if [ -e "$DOCKER_DIR/Dockerfile.$component" ]; then
|
||||
general_build $component $ARCH "false"
|
||||
fi
|
||||
;;
|
||||
all)
|
||||
for arch in "arm64" "amd64"; do
|
||||
general_build $component $arch "true"
|
||||
done
|
||||
make_manifest_image $component
|
||||
;;
|
||||
*)
|
||||
if [ -e "$DOCKER_DIR/Dockerfile.$component" ]; then
|
||||
general_build $component $ARCH "false"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user