From f1bf5d07c6666f8131854bab31cdfe12d49ed91f Mon Sep 17 00:00:00 2001 From: winter Date: Mon, 14 Jul 2025 11:05:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(release):=20=E6=B7=BB=E5=8A=A0=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=94=AF=E6=8C=81=E5=8D=95=E7=8B=AC=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E5=89=8D=E5=90=8E=E7=AB=AF=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持通过参数指定构建目标(backend/frontend/all)和自定义 tag --- release.sh | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/release.sh b/release.sh index f555f7a3f..20ca113f6 100755 --- a/release.sh +++ b/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"