perf(scripts): 优化docker部署脚本的构建逻辑

如果镜像已存在则跳过构建,减少不必要的构建时间
This commit is contained in:
zhouyonggao 2025-12-08 18:00:24 +08:00
parent 83f3634d06
commit 935d54c54c
1 changed files with 2 additions and 5 deletions

View File

@ -7,12 +7,9 @@ TAG="$ENV_NAME"
PORT="${PORT:-8077}" PORT="${PORT:-8077}"
cd "$ROOT_DIR" cd "$ROOT_DIR"
# 强制构建新镜像,确保使用最新的 Dockerfile # 如果镜像存在,则直接使用;否则构建
if docker image inspect "$IMAGE:$TAG" >/dev/null 2>&1; then if docker image inspect "$IMAGE:$TAG" >/dev/null 2>&1; then
DOCKER_BUILDKIT=1 docker build \ echo "镜像 $IMAGE:$TAG 已存在,跳过构建。"
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg GOPROXY="${GOPROXY:-https://goproxy.cn,direct}" \
--cache-from "$IMAGE:$TAG" -t "$IMAGE:$TAG" -f Dockerfile .
else else
DOCKER_BUILDKIT=1 docker build \ DOCKER_BUILDKIT=1 docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \ --build-arg BUILDKIT_INLINE_CACHE=1 \