From 65855b64c1f53a4cce5014dce0adeb965cb46c06 Mon Sep 17 00:00:00 2001 From: Jurangren Date: Sat, 20 Dec 2025 08:54:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Docker=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8F=8A=20GitHub=20Actions=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 新增 Dockerfile,支持在 Node.js 环境下本地运行 API。 * 添加 GitHub Actions 工作流,实现镜像自动构建并推送到 Docker Hub。 * 支持多平台构建(linux/amd64, linux/arm64)。 * 在 README.md 中补充了 Docker 本地运行的操作指南。 --- .github/workflows/docker-publish.yml | 54 ++++++++++++++++++++++++++++ Dockerfile | 12 +++++++ README.md | 7 ++++ 3 files changed, 73 insertions(+) create mode 100644 .github/workflows/docker-publish.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..2aeec23 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,54 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + tags: + - "v*" + workflow_dispatch: + +env: + REGISTRY: docker.io + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/wrangler-api + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=sha + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7c39d97 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM node:20-alpine + +WORKDIR /app + +COPY package*.json ./ +RUN npm ci + +COPY . . + +EXPOSE 8787 + +CMD ["npx", "wrangler", "dev", "--local", "--ip", "0.0.0.0", "--port", "8787"] diff --git a/README.md b/README.md index f004dd4..ae951c7 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,13 @@ npx wrangler login # 首次需要 npx wrangler publish ``` +## Docker +### 本地运行 +```bash +docker build -t wrangler-api:local . +docker run --rm -p 8787:8787 wrangler-api:local +``` + ## API 使用 - 路径:`POST /gal` 或 `POST /patch` - Content-Type:`multipart/form-data`