fix(部署脚本): 添加平台架构检测和自动适配功能
检测主机架构并自动设置正确的平台参数,确保在不同架构的主机上正确部署容器 移除不再使用的image.tar文件
This commit is contained in:
parent
85e86abbce
commit
bf3eae2f2f
|
|
@ -1,9 +1,19 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
set -e
|
set -e
|
||||||
ENV=${1:-test}
|
ENV=${1:-prod}
|
||||||
MODE=${2:-no-build}
|
MODE=${2:-no-build}
|
||||||
ENVFILE=""
|
ENVFILE=""
|
||||||
if [ -f ".env.$ENV" ]; then ENVFILE="--env-file .env.$ENV"; fi
|
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
|
case "$MODE" in
|
||||||
no-build)
|
no-build)
|
||||||
APP_ENV=$ENV docker compose $ENVFILE up -d ;;
|
APP_ENV=$ENV docker compose $ENVFILE up -d ;;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,14 @@ ENV=${1:-test}
|
||||||
IMAGE=${2:-marketingsystemdatatool_msdt:latest}
|
IMAGE=${2:-marketingsystemdatatool_msdt:latest}
|
||||||
CMD=${3:-up}
|
CMD=${3:-up}
|
||||||
PLATFORM=${PLATFORM:-}
|
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)
|
ROOT_DIR=$(cd "$(dirname "$0")/.." && pwd)
|
||||||
|
|
||||||
|
|
@ -19,6 +27,20 @@ case "$CMD" in
|
||||||
docker rm -f msdt >/dev/null 2>&1 || true
|
docker rm -f msdt >/dev/null 2>&1 || true
|
||||||
PLATFORM_FLAG=""
|
PLATFORM_FLAG=""
|
||||||
if [ -n "$PLATFORM" ]; then PLATFORM_FLAG="--platform $PLATFORM"; fi
|
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 \
|
docker run -d --name msdt $PLATFORM_FLAG \
|
||||||
-p 8077:8077 \
|
-p 8077:8077 \
|
||||||
-e APP_ENV="$ENV" \
|
-e APP_ENV="$ENV" \
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue