From cfdc5e5d9a7e0df1716d9aad2af551c07334879a Mon Sep 17 00:00:00 2001 From: niyyzf Date: Tue, 29 Jul 2025 14:22:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9E=84=E5=BB=BA=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 5 ++++- .gitea/workflows/docker-build.yml | 5 ++++- Dockerfile | 4 +++- build.sh | 25 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 build.sh diff --git a/.dockerignore b/.dockerignore index b7b0cf9..f9b615b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,4 +15,7 @@ dist .idea *.swp *.swo -*~ \ No newline at end of file +*~ +bun.lock +.git +.gitea \ No newline at end of file diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index f6a3e10..e70740c 100644 --- a/.gitea/workflows/docker-build.yml +++ b/.gitea/workflows/docker-build.yml @@ -12,6 +12,9 @@ jobs: - name: 释放内存 run: docker system prune -a -f + - name: 设置 Docker Buildx + run: docker buildx create --use + - name: 拉取自定义 checkout action run: git clone http://114.67.155.184:3000//niyyzf/checkout.git ./.actions/checkout @@ -23,7 +26,7 @@ jobs: max-attempts: 5 - name: 构建 Docker 镜像 - run: docker build -t watch-stock-list:latest . + run: docker build --cache-from type=gha --cache-to type=gha,mode=max -t watch-stock-list:latest . - name: 启动/重启服务(Docker Compose) run: | diff --git a/Dockerfile b/Dockerfile index 73b67f1..af8a483 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,9 @@ WORKDIR /app # 安装依赖 COPY package.json ./ -RUN npm install +# 使用 npm 缓存来加速构建 +RUN npm config set cache /tmp/npm-cache && \ + npm install --cache /tmp/npm-cache --prefer-offline --no-audit --no-fund # 构建阶段 FROM base AS builder diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..7e8d787 --- /dev/null +++ b/build.sh @@ -0,0 +1,25 @@ + #!/bin/bash + +# 本地构建脚本 - 包含缓存优化 +set -e + +echo "🚀 开始构建 Docker 镜像..." + +# 清理旧镜像(可选) +# docker system prune -f + +# 使用 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 \ + . + +echo "✅ 构建完成!" + +# 启动容器(可选) +echo "🐳 启动容器..." +docker-compose up -d + +echo "🎉 部署完成!应用运行在 http://localhost:7799" \ No newline at end of file