You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1007 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
# 预构建镜像更新 — 加载新 tar 并重建容器(不编译)
# 用法:bash deploy/update-prebuilt-image.sh [镜像tar路径]
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
COMPOSE_FILE="${ROOT_DIR}/deploy/docker-compose.prebuilt.yml"
ENV_FILE="${ROOT_DIR}/.env"
IMAGE_TAG="yubao-app:latest"
TAR_PATH="${1:-${ROOT_DIR}/deploy/yubao-app-image.tar}"
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
log() { echo -e "${GREEN}[prebuilt-update]${NC} $*"; }
err() { echo -e "${RED}[prebuilt-update]${NC} $*" >&2; }
if [[ ! -f "$ENV_FILE" ]]; then
err "缺少 .env"
exit 1
fi
if [[ ! -f "$TAR_PATH" ]]; then
err "缺少镜像 tar: $TAR_PATH"
exit 1
fi
cd "$ROOT_DIR"
compose=(docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE")
log "停止 web/worker…"
"${compose[@]}" stop web worker || true
log "加载新镜像…"
docker load -i "$TAR_PATH"
log "重建容器…"
"${compose[@]}" up -d --force-recreate
"${compose[@]}" ps
log "完成"