Skip to content

Commit 5d1b517

Browse files
committed
perf(ci): use matrix to speed up build
1 parent ac71604 commit 5d1b517

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

.github/workflows/docker-publish.yml

+16-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ env:
1010

1111
jobs:
1212
build:
13-
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
include:
16+
- platform: linux/amd64
17+
runner: ubuntu-latest
18+
- platform: linux/arm64
19+
runner: ubuntu-24.04-arm
20+
runs-on: ${{ matrix.runner }}
1421
permissions:
1522
contents: read
1623
packages: write
@@ -19,11 +26,10 @@ jobs:
1926
- name: Checkout repository
2027
uses: actions/checkout@v4
2128

22-
- name: Set up QEMU
23-
uses: docker/setup-qemu-action@v3
24-
2529
- name: Set up Docker Buildx
2630
uses: docker/setup-buildx-action@v3
31+
with:
32+
platforms: ${{ matrix.platform }}
2733

2834
- name: Log in to Docker Hub
2935
uses: docker/login-action@v3
@@ -47,8 +53,11 @@ jobs:
4753
with:
4854
context: .
4955
push: true
50-
platforms: linux/amd64,linux/arm64
56+
platforms: ${{ matrix.platform }}
5157
tags: ${{ steps.meta.outputs.tags }}
5258
labels: ${{ steps.meta.outputs.labels }}
53-
cache-from: type=gha
54-
cache-to: type=gha,mode=max
59+
cache-from: |
60+
type=gha,scope=${{ matrix.platform }}
61+
cache-to: |
62+
type=gha,mode=max,scope=${{ matrix.platform }}
63+
target: runner # 只构建到最终阶段

Dockerfile

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
FROM node:20-alpine AS builder
1+
FROM node:20-alpine AS deps
22

33
WORKDIR /app
44

5+
# 只复制依赖相关文件
56
COPY package.json pnpm-lock.yaml ./
67
RUN npm i -g --force pnpm@9
7-
RUN pnpm install --frozen-lockfile
8+
RUN pnpm install --frozen-lockfile --prod
9+
10+
FROM node:20-alpine AS builder
11+
WORKDIR /app
812

13+
COPY --from=deps /app/node_modules ./node_modules
914
COPY . .
15+
1016
ENV NODE_OPTIONS="--max_old_space_size=2048"
17+
RUN npm i -g --force pnpm@9
18+
RUN pnpm install --frozen-lockfile
1119
RUN pnpm build:optimize
1220

1321
FROM node:20-alpine AS runner
14-
1522
WORKDIR /app
1623

17-
# We only need the `.output` directory, which contains everything the app needs to run
24+
ENV NODE_ENV production
25+
26+
# 只复制必要的文件
1827
COPY --from=builder /app/.output .output
1928
COPY --from=builder /app/package.json .
2029

0 commit comments

Comments
 (0)