Files
AiTool/docker_dev.sh
2026-03-18 17:01:10 +08:00

57 lines
1.9 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Docker 开发与部署:支持仅更新变动内容、动态加载,避免每次全量重建
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
COMPOSE_BASE="docker compose -f docker-compose.yml"
# dev 直接使用独立 compose 文件,避免与生产 compose 合并导致 ports/镜像覆盖问题
COMPOSE_DEV="docker compose -f docker-compose.dev.yml"
usage() {
echo "用法: $0 [mode]"
echo ""
echo " (无参数) 默认构建并启动(生产模式:前端为静态 SPA + Nginx后端 FastAPI"
echo " dev 开发模式:容器内 Vite 热重载,前端 http://localhost:3001Ctrl+C 停容器)"
echo " dev-bg 开发模式后台运行,前端 http://localhost:3001停止用: $0 down"
echo " restart 仅重启容器内服务,不重建镜像"
echo " build 仅重新构建镜像(依赖未变时只重建代码层,较快)"
echo " down 停止并移除容器"
exit 0
}
case "${1:-up}" in
up|"")
echo "[Ops-Core] 构建并启动(生产模式:静态 SPA + API..."
${COMPOSE_BASE} up --build
;;
dev)
echo "[Ops-Core] 开发模式:容器内 Vite 热重载,前端 http://localhost:3001Ctrl+C 停止)..."
${COMPOSE_DEV} up --build
;;
dev-bg)
echo "[Ops-Core] 开发模式(后台):同上,但 Ctrl+C 不会停容器,需用 ./docker_dev.sh down 停止..."
${COMPOSE_DEV} up --build -d
;;
restart)
echo "[Ops-Core] 仅重启服务(不重建镜像)..."
${COMPOSE_BASE} restart backend frontend
;;
build)
echo "[Ops-Core] 仅构建镜像(变更少时只重建代码层)..."
${COMPOSE_BASE} build
;;
down)
${COMPOSE_BASE} down
${COMPOSE_DEV} down 2>/dev/null || true
;;
-h|--help)
usage
;;
*)
echo "未知参数: $1"
usage
;;
esac