Skip to content

Commit 9f85c04

Browse files
committed
fix(ci): merge docker manifest
1 parent 5d1b517 commit 9f85c04

File tree

2 files changed

+81
-27
lines changed

2 files changed

+81
-27
lines changed

.github/workflows/docker-publish.yml

+80-26
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,117 @@
1-
name: Docker Build and Publish
1+
name: Build and Push Docker Images
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches:
6+
- main # 当推送到 main 分支时触发
67
workflow_dispatch: # 允许手动触发
78

89
env:
910
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/deep-research-web
1011

1112
jobs:
12-
build:
13+
docker:
14+
name: Build Docker Image (${{ matrix.arch }})
15+
runs-on: ${{ matrix.runner }}
16+
1317
strategy:
1418
matrix:
1519
include:
16-
- platform: linux/amd64
17-
runner: ubuntu-latest
18-
- platform: linux/arm64
19-
runner: ubuntu-24.04-arm
20-
runs-on: ${{ matrix.runner }}
21-
permissions:
22-
contents: read
23-
packages: write
20+
- arch: amd64
21+
runner: ubuntu-22.04
22+
platform: linux/amd64
23+
- arch: arm64
24+
runner: ubuntu-22.04-arm
25+
platform: linux/arm64
2426

2527
steps:
2628
- name: Checkout repository
2729
uses: actions/checkout@v4
2830

2931
- name: Set up Docker Buildx
3032
uses: docker/setup-buildx-action@v3
31-
with:
32-
platforms: ${{ matrix.platform }}
3333

34-
- name: Log in to Docker Hub
34+
- name: Login to Docker Hub
3535
uses: docker/login-action@v3
3636
with:
3737
username: ${{ secrets.DOCKERHUB_USERNAME }}
3838
password: ${{ secrets.DOCKERHUB_TOKEN }}
3939

40-
- name: Extract metadata (tags, labels) for Docker
40+
- name: Docker metadata
4141
id: meta
4242
uses: docker/metadata-action@v5
4343
with:
4444
images: ${{ env.IMAGE_NAME }}
4545
tags: |
46-
type=raw,value=latest,enable={{is_default_branch}}
47-
type=sha,prefix={{branch}}-
4846
type=ref,event=branch
49-
type=ref,event=tag
47+
type=ref,event=pr
48+
type=semver,pattern={{version}}
49+
type=semver,pattern={{major}}.{{minor}}
50+
type=sha,format=long
51+
type=raw,value=latest,enable={{is_default_branch}}
5052
51-
- name: Build and push Docker image
53+
- name: Build and push by digest
54+
id: build
5255
uses: docker/build-push-action@v5
5356
with:
5457
context: .
55-
push: true
5658
platforms: ${{ matrix.platform }}
57-
tags: ${{ steps.meta.outputs.tags }}
5859
labels: ${{ steps.meta.outputs.labels }}
59-
cache-from: |
60-
type=gha,scope=${{ matrix.platform }}
61-
cache-to: |
62-
type=gha,mode=max,scope=${{ matrix.platform }}
63-
target: runner # 只构建到最终阶段
60+
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max
63+
64+
- name: Export digest
65+
run: |
66+
mkdir -p /tmp/digests
67+
digest="${{ steps.build.outputs.digest }}"
68+
touch "/tmp/digests/${digest#sha256:}"
69+
70+
- name: Upload digest
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: digests-${{ matrix.arch }}
74+
path: /tmp/digests/*
75+
if-no-files-found: error
76+
retention-days: 1
77+
78+
merge:
79+
name: Merge and Push Multi-arch Image
80+
needs: [docker]
81+
runs-on: ubuntu-22.04
82+
83+
steps:
84+
- name: Download digests
85+
uses: actions/download-artifact@v4
86+
with:
87+
pattern: digests-*
88+
path: /tmp/digests
89+
merge-multiple: true
90+
91+
- name: Set up Docker Buildx
92+
uses: docker/setup-buildx-action@v3
93+
94+
- name: Login to Docker Hub
95+
uses: docker/login-action@v3
96+
with:
97+
username: ${{ secrets.DOCKERHUB_USERNAME }}
98+
password: ${{ secrets.DOCKERHUB_TOKEN }}
99+
100+
- name: Docker metadata
101+
id: meta
102+
uses: docker/metadata-action@v5
103+
with:
104+
images: ${{ env.IMAGE_NAME }}
105+
tags: |
106+
type=ref,event=branch
107+
type=ref,event=pr
108+
type=semver,pattern={{version}}
109+
type=semver,pattern={{major}}.{{minor}}
110+
type=sha,format=long
111+
type=raw,value=latest,enable={{is_default_branch}}
112+
113+
- name: Create manifest list and push
114+
working-directory: /tmp/digests
115+
run: |
116+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< '${{ steps.meta.outputs.json }}') \
117+
$(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *)

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ RUN pnpm build:optimize
2121
FROM node:20-alpine AS runner
2222
WORKDIR /app
2323

24-
ENV NODE_ENV production
24+
ENV NODE_ENV=production
2525

2626
# 只复制必要的文件
2727
COPY --from=builder /app/.output .output

0 commit comments

Comments
 (0)