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.

66 lines
1.6 KiB

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
# bash deploy/update-prebuilt-image.sh --db-push
# bash deploy/update-prebuilt-image.sh /path/to/yubao-app-image.tar --db-push
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="${ROOT_DIR}/deploy/yubao-app-image.tar"
DO_DB_PUSH=false
for arg in "$@"; do
case "$arg" in
--db-push) DO_DB_PUSH=true ;;
-h|--help)
echo "用法: bash deploy/update-prebuilt-image.sh [镜像tar] [--db-push]"
exit 0
;;
*)
TAR_PATH="$arg"
;;
esac
done
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
if [[ "$DO_DB_PUSH" == "true" ]]; then
log "同步数据库结构(prisma db push,不删数据)…"
"${compose[@]}" run --rm --no-deps web pnpm exec prisma db push --skip-generate
fi
"${compose[@]}" ps
log "完成。登录仍用 .env 中 APP_ADMIN_USER / APP_ADMIN_PASS,勿覆盖 .env"