From cc90c936735febcaa6b2088f1c396669af3586fb Mon Sep 17 00:00:00 2001 From: lezi-fun <177434121+lezi-fun@users.noreply.github.com> Date: Tue, 11 Aug 2026 18:59:22 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20multi-arch=20images=20=E2=80=94=20linux/a?= =?UTF-8?q?md64=20+=20linux/arm64=20+=20windows/amd64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Linux: build-push-action platforms linux/amd64,linux/arm64 - Windows: separate job on windows-latest (switch to Windows container engine, native docker build with Dockerfile.windows) → :next-windows - Dockerfile.windows: node:20-windowsservercore-ltsc2022, bun install, standalone output --- .github/workflows/docker-ghcr.yml | 37 ++++++++++++++++++++++++++++++- Dockerfile.windows | 30 +++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.windows diff --git a/.github/workflows/docker-ghcr.yml b/.github/workflows/docker-ghcr.yml index b9d34a2..bb123c3 100644 --- a/.github/workflows/docker-ghcr.yml +++ b/.github/workflows/docker-ghcr.yml @@ -42,12 +42,47 @@ jobs: type=semver,pattern={{major}}.{{minor}} type=sha,prefix=git- - - name: Build and push + - name: Build and push (linux/amd64 + linux/arm64) 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 }} cache-from: type=gha cache-to: type=gha,mode=max + + # Windows 容器镜像(windowsservercore):需要在 Windows runner 上 + # 切换 Windows 容器引擎后原生 docker build(buildx 不支持交叉构建 Windows 容器) + windows: + runs-on: windows-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Switch Docker to Windows containers + shell: pwsh + run: | + & "$env:ProgramFiles\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine + + - name: Build Windows image + shell: pwsh + run: | + docker build -f Dockerfile.windows -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:next-windows . + + - name: Push Windows image + shell: pwsh + run: | + docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:next-windows diff --git a/Dockerfile.windows b/Dockerfile.windows new file mode 100644 index 0000000..2a1b40d --- /dev/null +++ b/Dockerfile.windows @@ -0,0 +1,30 @@ +# ============================================================ +# Forumlify (Next.js) Windows 容器镜像 +# 构建:windows runner 切 Windows 容器引擎后 docker build +# ============================================================ + +# ---- 构建阶段 ---- +FROM node:20-windowsservercore-ltsc2022 AS builder +WORKDIR C:/app +ENV DOCKER=1 + +# bun 装依赖(bun.lock 最新;npm 会读旧 package-lock.json → react 18 → 构建失败) +RUN npm install -g bun +COPY package.json bun.lock* package-lock.json* ./ +RUN bun install +COPY . . +RUN bun run build + +# ---- 运行阶段 ---- +FROM node:20-windowsservercore-ltsc2022 +WORKDIR C:/app +ENV NODE_ENV=production + +# standalone 输出(含 server.js 与最小 node_modules) +COPY --from=builder C:/app/.next/standalone ./ +COPY --from=builder C:/app/.next/static ./.next/static + +RUN mkdir C:/app/uploads + +EXPOSE 3000 +CMD ["node", "server.js"]