fix(部署脚本): 添加平台架构检测和自动适配功能

检测主机架构并自动设置正确的平台参数,确保在不同架构的主机上正确部署容器
移除不再使用的image.tar文件
This commit is contained in:
zhouyonggao 2025-11-28 16:32:20 +08:00
parent 85e86abbce
commit bf3eae2f2f
3 changed files with 33 additions and 1 deletions

View File

@ -1,9 +1,19 @@
#!/usr/bin/env sh
set -e
ENV=${1:-test}
ENV=${1:-prod}
MODE=${2:-no-build}
ENVFILE=""
if [ -f ".env.$ENV" ]; then ENVFILE="--env-file .env.$ENV"; fi
PLATFORM=${PLATFORM:-}
if [ -z "$PLATFORM" ]; then
ARCH=$(uname -m)
case "$ARCH" in
x86_64) PLATFORM="linux/amd64" ;;
aarch64) PLATFORM="linux/arm64" ;;
*) PLATFORM="linux/amd64" ;;
esac
fi
export PLATFORM
case "$MODE" in
no-build)
APP_ENV=$ENV docker compose $ENVFILE up -d ;;

View File

@ -5,6 +5,14 @@ ENV=${1:-test}
IMAGE=${2:-marketingsystemdatatool_msdt:latest}
CMD=${3:-up}
PLATFORM=${PLATFORM:-}
if [ -z "$PLATFORM" ]; then
ARCH=$(uname -m)
case "$ARCH" in
x86_64) PLATFORM="linux/amd64" ;;
aarch64) PLATFORM="linux/arm64" ;;
*) PLATFORM="linux/amd64" ;;
esac
fi
ROOT_DIR=$(cd "$(dirname "$0")/.." && pwd)
@ -19,6 +27,20 @@ case "$CMD" in
docker rm -f msdt >/dev/null 2>&1 || true
PLATFORM_FLAG=""
if [ -n "$PLATFORM" ]; then PLATFORM_FLAG="--platform $PLATFORM"; fi
IMG_ARCH=""
if docker image inspect "$IMAGE" >/dev/null 2>&1; then
IMG_ARCH=$(docker image inspect "$IMAGE" --format '{{.Architecture}}' 2>/dev/null || echo "")
fi
if [ -n "$IMG_ARCH" ]; then
HOST_ARCH=$(uname -m)
case "$HOST_ARCH" in x86_64) HOST_ARCH="amd64" ;; aarch64) HOST_ARCH="arm64" ;; *) HOST_ARCH="amd64" ;; esac
if [ "$IMG_ARCH" != "$HOST_ARCH" ]; then
docker pull --platform "$PLATFORM" "$IMAGE" >/dev/null 2>&1 || true
PLATFORM_FLAG="--platform $PLATFORM"
fi
else
docker pull --platform "$PLATFORM" "$IMAGE" >/dev/null 2>&1 || true
fi
docker run -d --name msdt $PLATFORM_FLAG \
-p 8077:8077 \
-e APP_ENV="$ENV" \

Binary file not shown.