perf(ci): use matrix to speed up build
This commit is contained in:
23
.github/workflows/docker-publish.yml
vendored
23
.github/workflows/docker-publish.yml
vendored
@ -10,7 +10,14 @@ env:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- platform: linux/amd64
|
||||
runner: ubuntu-latest
|
||||
- platform: linux/arm64
|
||||
runner: ubuntu-24.04-arm
|
||||
runs-on: ${{ matrix.runner }}
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
@ -19,11 +26,10 @@ jobs:
|
||||
- name: Checkout repository
|
||||
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
|
||||
with:
|
||||
platforms: ${{ matrix.platform }}
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
@ -47,8 +53,11 @@ jobs:
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
platforms: ${{ matrix.platform }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
cache-from: |
|
||||
type=gha,scope=${{ matrix.platform }}
|
||||
cache-to: |
|
||||
type=gha,mode=max,scope=${{ matrix.platform }}
|
||||
target: runner # 只构建到最终阶段
|
||||
|
17
Dockerfile
17
Dockerfile
@ -1,20 +1,29 @@
|
||||
FROM node:20-alpine AS builder
|
||||
FROM node:20-alpine AS deps
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 只复制依赖相关文件
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN npm i -g --force pnpm@9
|
||||
RUN pnpm install --frozen-lockfile
|
||||
RUN pnpm install --frozen-lockfile --prod
|
||||
|
||||
FROM node:20-alpine AS builder
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
ENV NODE_OPTIONS="--max_old_space_size=2048"
|
||||
RUN npm i -g --force pnpm@9
|
||||
RUN pnpm install --frozen-lockfile
|
||||
RUN pnpm build:optimize
|
||||
|
||||
FROM node:20-alpine AS runner
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# We only need the `.output` directory, which contains everything the app needs to run
|
||||
ENV NODE_ENV production
|
||||
|
||||
# 只复制必要的文件
|
||||
COPY --from=builder /app/.output .output
|
||||
COPY --from=builder /app/package.json .
|
||||
|
||||
|
Reference in New Issue
Block a user