Browse Source

feat(release): 添加参数支持单独构建前后端镜像

支持通过参数指定构建目标(backend/frontend/all)和自定义 tag
pull/13907/head
winter 3 weeks ago
parent
commit
f1bf5d07c6
  1. 39
      release.sh

39
release.sh

@ -3,18 +3,43 @@
set -e
# === 配置 ===
USER=fewinter # 你的 Docker Hub 用户名
USER=fewinter
BACKEND_DIR=./backend
FRONTEND_DIR=./frontend
BACKEND_IMAGE=$USER/fastapi-backend
FRONTEND_IMAGE=$USER/fastapi-frontend
TAG=${1:-latest} # 默认 tag 是 latest,传参可覆盖
# === 解析参数 ===
TAG=latest
TARGET=all
if [[ $# -eq 1 ]]; then
if [[ "$1" == "all" || "$1" == "backend" || "$1" == "frontend" ]]; then
TARGET="$1"
else
TAG="$1"
fi
elif [[ $# -eq 2 ]]; then
TAG="$1"
TARGET="$2"
fi
# === 检查目标 ===
if [[ "$TARGET" != "backend" && "$TARGET" != "frontend" && "$TARGET" != "all" ]]; then
echo "❌ 无效的目标: $TARGET"
echo "用法: $0 [tag] [backend|frontend|all]"
exit 1
fi
# === 构建并推送 ===
echo "▶ Building and pushing backend..."
docker buildx build --platform linux/amd64 -t $BACKEND_IMAGE:$TAG $BACKEND_DIR --push
if [[ "$TARGET" == "backend" || "$TARGET" == "all" ]]; then
echo "▶ Building and pushing backend..."
docker buildx build --platform linux/amd64 -t $BACKEND_IMAGE:$TAG $BACKEND_DIR --push
fi
echo "▶ Building and pushing frontend..."
docker buildx build --platform linux/amd64 -t $FRONTEND_IMAGE:$TAG $FRONTEND_DIR --push
if [[ "$TARGET" == "frontend" || "$TARGET" == "all" ]]; then
echo "▶ Building and pushing frontend..."
docker buildx build --platform linux/amd64 -t $FRONTEND_IMAGE:$TAG $FRONTEND_DIR --push
fi
echo "✅ Release completed: $TAG"
echo "✅ Release completed: tag=$TAG target=$TARGET"

Loading…
Cancel
Save