From f96e141b176cf834a01b88c19508df6e01af9088 Mon Sep 17 00:00:00 2001 From: niyyzf Date: Tue, 29 Jul 2025 14:25:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/docker-build.yml | 13 ++++++------- Dockerfile | 2 +- build-docker.sh | 18 ++++++++++++++++++ build.sh | 4 +--- 4 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 build-docker.sh diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index e70740c..4868e3d 100644 --- a/.gitea/workflows/docker-build.yml +++ b/.gitea/workflows/docker-build.yml @@ -13,7 +13,9 @@ jobs: run: docker system prune -a -f - name: 设置 Docker Buildx - run: docker buildx create --use + run: | + docker buildx create --use --name builder + docker buildx inspect --bootstrap - name: 拉取自定义 checkout action run: git clone http://114.67.155.184:3000//niyyzf/checkout.git ./.actions/checkout @@ -25,10 +27,7 @@ jobs: persist-credentials: false max-attempts: 5 - - name: 构建 Docker 镜像 - run: docker build --cache-from type=gha --cache-to type=gha,mode=max -t watch-stock-list:latest . - - - name: 启动/重启服务(Docker Compose) + - name: 构建并部署 run: | - docker compose down || true - docker compose up -d --force-recreate \ No newline at end of file + chmod +x build-docker.sh + ./build-docker.sh \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index af8a483..3be934f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ WORKDIR /app COPY package.json ./ # 使用 npm 缓存来加速构建 RUN npm config set cache /tmp/npm-cache && \ - npm install --cache /tmp/npm-cache --prefer-offline --no-audit --no-fund + npm install --cache /tmp/npm-cache --prefer-offline --no-audit --no-fund --production=false # 构建阶段 FROM base AS builder diff --git a/build-docker.sh b/build-docker.sh new file mode 100644 index 0000000..3c5094d --- /dev/null +++ b/build-docker.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Gitea Actions 专用构建脚本 +set -e + +echo "🚀 开始构建 Docker 镜像..." + +# 使用标准 docker build 命令 +docker build -t watch-stock-list:latest . + +echo "✅ 构建完成!" + +# 启动容器 +echo "🐳 启动容器..." +docker-compose down || true +docker-compose up -d --force-recreate + +echo "🎉 部署完成!应用运行在 http://localhost:7799" \ No newline at end of file diff --git a/build.sh b/build.sh index 7e8d787..8f4e0f2 100644 --- a/build.sh +++ b/build.sh @@ -8,10 +8,8 @@ echo "🚀 开始构建 Docker 镜像..." # 清理旧镜像(可选) # docker system prune -f -# 使用 Buildx 和缓存构建 +# 使用 Buildx 构建 docker buildx build \ - --cache-from type=local,src=/tmp/.buildx-cache \ - --cache-to type=local,dest=/tmp/.buildx-cache,mode=max \ --tag watch-stock-list:latest \ --load \ .