Skip to content

Commit ea74c66

Browse files
authored
feat: github workflow arm runner (#4530)
* feat: arm runner * fix * fix: outputs name * fix: outputs name * fix: 429 * feat: cache key * fix: tags * fix: tags * feat: sandbox arm64 runner * fix: sandbox dockerfile * feat: merge build
1 parent 38597d8 commit ea74c66

File tree

2 files changed

+181
-233
lines changed

2 files changed

+181
-233
lines changed
Lines changed: 95 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -1,273 +1,171 @@
11
name: Build FastGPT images
2+
23
on:
34
workflow_dispatch:
45
push:
56
paths:
6-
- 'projects/app/**'
7-
- 'packages/**'
7+
- "projects/app/**"
8+
- "packages/**"
89
tags:
9-
- 'v*'
10+
- "v*"
11+
1012
jobs:
1113
build-fastgpt-images:
1214
permissions:
1315
packages: write
1416
contents: read
1517
attestations: write
1618
id-token: write
17-
runs-on: ubuntu-20.04
19+
strategy:
20+
matrix:
21+
sub_routes:
22+
- repo: fastgpt
23+
base_url: ""
24+
- repo: fastgpt-sub-route
25+
base_url: "/fastai"
26+
- repo: fastgpt-sub-route-gchat
27+
base_url: "/gchat"
28+
archs:
29+
- arch: amd64
30+
- arch: arm64
31+
runs-on: ubuntu-24.04-arm
32+
runs-on: ${{ matrix.archs.runs-on || 'ubuntu-24.04' }}
1833
steps:
1934
# install env
2035
- name: Checkout
21-
uses: actions/checkout@v3
36+
uses: actions/checkout@v4
2237
with:
2338
fetch-depth: 1
24-
- name: Install Dependencies
25-
run: |
26-
sudo apt update && sudo apt install -y nodejs npm
27-
- name: Set up QEMU (optional)
28-
uses: docker/setup-qemu-action@v2
39+
2940
- name: Set up Docker Buildx
30-
uses: docker/setup-buildx-action@v2
41+
uses: docker/setup-buildx-action@v3
3142
with:
3243
driver-opts: network=host
44+
3345
- name: Cache Docker layers
3446
uses: actions/cache@v4
3547
with:
3648
path: /tmp/.buildx-cache
37-
key: ${{ runner.os }}-buildx-${{ github.sha }}
49+
key: ${{ runner.os }}-${{ matrix.sub_routes.repo }}-buildx-${{ github.sha }}
3850
restore-keys: |
39-
${{ runner.os }}-buildx-
51+
${{ runner.os }}-${{ matrix.sub_routes.repo }}-buildx-
4052
4153
# login docker
4254
- name: Login to GitHub Container Registry
43-
uses: docker/login-action@v2
55+
uses: docker/login-action@v3
4456
with:
4557
registry: ghcr.io
4658
username: ${{ github.repository_owner }}
4759
password: ${{ secrets.GITHUB_TOKEN }}
4860
- name: Login to Ali Hub
49-
uses: docker/login-action@v2
61+
uses: docker/login-action@v3
5062
with:
5163
registry: registry.cn-hangzhou.aliyuncs.com
5264
username: ${{ secrets.ALI_HUB_USERNAME }}
5365
password: ${{ secrets.ALI_HUB_PASSWORD }}
5466
- name: Login to Docker Hub
55-
uses: docker/login-action@v2
67+
uses: docker/login-action@v3
5668
with:
5769
username: ${{ secrets.DOCKER_HUB_NAME }}
5870
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
5971

60-
# Set tag
61-
- name: Set image name and tag
62-
run: |
63-
if [[ "${{ github.ref_name }}" == "main" ]]; then
64-
echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/fastgpt:latest" >> $GITHUB_ENV
65-
echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/fastgpt:latest" >> $GITHUB_ENV
66-
echo "Ali_Tag=${{ secrets.ALI_IMAGE_NAME }}/fastgpt:latest" >> $GITHUB_ENV
67-
echo "Ali_Latest=${{ secrets.ALI_IMAGE_NAME }}/fastgpt:latest" >> $GITHUB_ENV
68-
echo "Docker_Hub_Tag=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt:latest" >> $GITHUB_ENV
69-
echo "Docker_Hub_Latest=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt:latest" >> $GITHUB_ENV
70-
else
71-
echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/fastgpt:${{ github.ref_name }}" >> $GITHUB_ENV
72-
echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/fastgpt:latest" >> $GITHUB_ENV
73-
echo "Ali_Tag=${{ secrets.ALI_IMAGE_NAME }}/fastgpt:${{ github.ref_name }}" >> $GITHUB_ENV
74-
echo "Ali_Latest=${{ secrets.ALI_IMAGE_NAME }}/fastgpt:latest" >> $GITHUB_ENV
75-
echo "Docker_Hub_Tag=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt:${{ github.ref_name }}" >> $GITHUB_ENV
76-
echo "Docker_Hub_Latest=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt:latest" >> $GITHUB_ENV
77-
fi
72+
- name: Build for ${{ matrix.archs.arch }}
73+
id: build
74+
uses: docker/build-push-action@v6
75+
with:
76+
context: .
77+
file: projects/app/Dockerfile
78+
platforms: linux/${{ matrix.archs.arch }}
79+
build-args: |
80+
${{ matrix.sub_routes.base_url && format('base_url={0}', matrix.sub_routes.base_url) || '' }}
81+
labels: |
82+
org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}
83+
org.opencontainers.image.description=${{ matrix.sub_routes.repo }} image
84+
outputs: type=image,"name=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }},${{ secrets.ALI_IMAGE_NAME }}/${{ matrix.sub_routes.repo }},${{ secrets.DOCKER_IMAGE_NAME }}/${{ matrix.sub_routes.repo }}",push-by-digest=true,push=true
85+
cache-from: type=local,src=/tmp/.buildx-cache
86+
cache-to: type=local,dest=/tmp/.buildx-cache
7887

79-
- name: Build and publish image for main branch or tag push event
80-
env:
81-
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
88+
- name: Export digest
8289
run: |
83-
docker buildx build \
84-
-f projects/app/Dockerfile \
85-
--platform linux/amd64,linux/arm64 \
86-
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT" \
87-
--label "org.opencontainers.image.description=fastgpt image" \
88-
--push \
89-
--cache-from=type=local,src=/tmp/.buildx-cache \
90-
--cache-to=type=local,dest=/tmp/.buildx-cache \
91-
-t ${Git_Tag} \
92-
-t ${Git_Latest} \
93-
-t ${Ali_Tag} \
94-
-t ${Ali_Latest} \
95-
-t ${Docker_Hub_Tag} \
96-
-t ${Docker_Hub_Latest} \
97-
.
98-
build-fastgpt-images-sub-route:
99-
permissions:
100-
packages: write
101-
contents: read
102-
attestations: write
103-
id-token: write
104-
runs-on: ubuntu-20.04
105-
steps:
106-
# install env
107-
- name: Checkout
108-
uses: actions/checkout@v3
109-
with:
110-
fetch-depth: 1
111-
- name: Install Dependencies
112-
run: |
113-
sudo apt update && sudo apt install -y nodejs npm
114-
- name: Set up QEMU (optional)
115-
uses: docker/setup-qemu-action@v2
116-
- name: Set up Docker Buildx
117-
uses: docker/setup-buildx-action@v2
118-
with:
119-
driver-opts: network=host
120-
- name: Cache Docker layers
121-
uses: actions/cache@v4
122-
with:
123-
path: /tmp/.buildx-cache
124-
key: ${{ runner.os }}-buildx-${{ github.sha }}
125-
restore-keys: |
126-
${{ runner.os }}-buildx-
90+
mkdir -p ${{ runner.temp }}/digests/${{ matrix.sub_routes.repo }}
91+
digest="${{ steps.build.outputs.digest }}"
92+
touch "${{ runner.temp }}/digests/${{ matrix.sub_routes.repo }}/${digest#sha256:}"
12793
128-
# login docker
129-
- name: Login to GitHub Container Registry
130-
uses: docker/login-action@v2
94+
- name: Upload digest
95+
uses: actions/upload-artifact@v4
13196
with:
132-
registry: ghcr.io
133-
username: ${{ github.repository_owner }}
134-
password: ${{ secrets.GITHUB_TOKEN }}
135-
- name: Login to Ali Hub
136-
uses: docker/login-action@v2
137-
with:
138-
registry: registry.cn-hangzhou.aliyuncs.com
139-
username: ${{ secrets.ALI_HUB_USERNAME }}
140-
password: ${{ secrets.ALI_HUB_PASSWORD }}
141-
- name: Login to Docker Hub
142-
uses: docker/login-action@v2
143-
with:
144-
username: ${{ secrets.DOCKER_HUB_NAME }}
145-
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
97+
name: digests-${{ matrix.sub_routes.repo }}-${{ github.sha }}-${{ matrix.archs.arch }}
98+
path: ${{ runner.temp }}/digests/${{ matrix.sub_routes.repo }}/*
99+
if-no-files-found: error
100+
retention-days: 1
146101

147-
# Set tag
148-
- name: Set image name and tag
149-
run: |
150-
if [[ "${{ github.ref_name }}" == "main" ]]; then
151-
echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/fastgpt-sub-route:latest" >> $GITHUB_ENV
152-
echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/fastgpt-sub-route:latest" >> $GITHUB_ENV
153-
echo "Ali_Tag=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sub-route:latest" >> $GITHUB_ENV
154-
echo "Ali_Latest=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sub-route:latest" >> $GITHUB_ENV
155-
echo "Docker_Hub_Tag=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-sub-route:latest" >> $GITHUB_ENV
156-
echo "Docker_Hub_Latest=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-sub-route:latest" >> $GITHUB_ENV
157-
else
158-
echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/fastgpt-sub-route:${{ github.ref_name }}" >> $GITHUB_ENV
159-
echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/fastgpt-sub-route:latest" >> $GITHUB_ENV
160-
echo "Ali_Tag=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sub-route:${{ github.ref_name }}" >> $GITHUB_ENV
161-
echo "Ali_Latest=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sub-route:latest" >> $GITHUB_ENV
162-
echo "Docker_Hub_Tag=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-sub-route:${{ github.ref_name }}" >> $GITHUB_ENV
163-
echo "Docker_Hub_Latest=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-sub-route:latest" >> $GITHUB_ENV
164-
fi
165-
166-
- name: Build and publish image for main branch or tag push event
167-
env:
168-
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
169-
run: |
170-
docker buildx build \
171-
-f projects/app/Dockerfile \
172-
--platform linux/amd64,linux/arm64 \
173-
--build-arg base_url=/fastai \
174-
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT" \
175-
--label "org.opencontainers.image.description=fastgpt image" \
176-
--push \
177-
--cache-from=type=local,src=/tmp/.buildx-cache \
178-
--cache-to=type=local,dest=/tmp/.buildx-cache \
179-
-t ${Git_Tag} \
180-
-t ${Git_Latest} \
181-
-t ${Ali_Tag} \
182-
-t ${Ali_Latest} \
183-
-t ${Docker_Hub_Tag} \
184-
-t ${Docker_Hub_Latest} \
185-
.
186-
build-fastgpt-images-sub-route-gchat:
102+
release-fastgpt-images:
187103
permissions:
188104
packages: write
189105
contents: read
190106
attestations: write
191107
id-token: write
192-
runs-on: ubuntu-20.04
108+
needs: build-fastgpt-images
109+
strategy:
110+
matrix:
111+
sub_routes:
112+
- repo: fastgpt
113+
- repo: fastgpt-sub-route
114+
- repo: fastgpt-sub-route-gchat
115+
runs-on: ubuntu-24.04
193116
steps:
194-
# install env
195-
- name: Checkout
196-
uses: actions/checkout@v3
197-
with:
198-
fetch-depth: 1
199-
- name: Install Dependencies
200-
run: |
201-
sudo apt update && sudo apt install -y nodejs npm
202-
- name: Set up QEMU (optional)
203-
uses: docker/setup-qemu-action@v2
204-
- name: Set up Docker Buildx
205-
uses: docker/setup-buildx-action@v2
206-
with:
207-
driver-opts: network=host
208-
- name: Cache Docker layers
209-
uses: actions/cache@v4
210-
with:
211-
path: /tmp/.buildx-cache
212-
key: ${{ runner.os }}-buildx-${{ github.sha }}
213-
restore-keys: |
214-
${{ runner.os }}-buildx-
215-
216-
# login docker
217117
- name: Login to GitHub Container Registry
218-
uses: docker/login-action@v2
118+
uses: docker/login-action@v3
219119
with:
220120
registry: ghcr.io
221121
username: ${{ github.repository_owner }}
222122
password: ${{ secrets.GITHUB_TOKEN }}
223123
- name: Login to Ali Hub
224-
uses: docker/login-action@v2
124+
uses: docker/login-action@v3
225125
with:
226126
registry: registry.cn-hangzhou.aliyuncs.com
227127
username: ${{ secrets.ALI_HUB_USERNAME }}
228128
password: ${{ secrets.ALI_HUB_PASSWORD }}
229129
- name: Login to Docker Hub
230-
uses: docker/login-action@v2
130+
uses: docker/login-action@v3
231131
with:
232132
username: ${{ secrets.DOCKER_HUB_NAME }}
233133
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
234134

235-
# Set tag
135+
- name: Download digests
136+
uses: actions/download-artifact@v4
137+
with:
138+
path: ${{ runner.temp }}/digests
139+
pattern: digests-${{ matrix.sub_routes.repo }}-${{ github.sha }}-*
140+
merge-multiple: true
141+
142+
- name: Set up Docker Buildx
143+
uses: docker/setup-buildx-action@v3
144+
236145
- name: Set image name and tag
237146
run: |
238147
if [[ "${{ github.ref_name }}" == "main" ]]; then
239-
echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/fastgpt-sub-route-gchat:latest" >> $GITHUB_ENV
240-
echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/fastgpt-sub-route-gchat:latest" >> $GITHUB_ENV
241-
echo "Ali_Tag=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sub-route-gchat:latest" >> $GITHUB_ENV
242-
echo "Ali_Latest=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sub-route-gchat:latest" >> $GITHUB_ENV
243-
echo "Docker_Hub_Tag=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-sub-route-gchat:latest" >> $GITHUB_ENV
244-
echo "Docker_Hub_Latest=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-sub-route-gchat:latest" >> $GITHUB_ENV
148+
echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
149+
echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
150+
echo "Ali_Tag=${{ secrets.ALI_IMAGE_NAME }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
151+
echo "Ali_Latest=${{ secrets.ALI_IMAGE_NAME }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
152+
echo "Docker_Hub_Tag=${{ secrets.DOCKER_IMAGE_NAME }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
153+
echo "Docker_Hub_Latest=${{ secrets.DOCKER_IMAGE_NAME }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
245154
else
246-
echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/fastgpt-sub-route-gchat:${{ github.ref_name }}" >> $GITHUB_ENV
247-
echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/fastgpt-sub-route-gchat:latest" >> $GITHUB_ENV
248-
echo "Ali_Tag=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sub-route-gchat:${{ github.ref_name }}" >> $GITHUB_ENV
249-
echo "Ali_Latest=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sub-route-gchat:latest" >> $GITHUB_ENV
250-
echo "Docker_Hub_Tag=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-sub-route-gchat:${{ github.ref_name }}" >> $GITHUB_ENV
251-
echo "Docker_Hub_Latest=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-sub-route-gchat:latest" >> $GITHUB_ENV
155+
echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:${{ github.ref_name }}" >> $GITHUB_ENV
156+
echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
157+
echo "Ali_Tag=${{ secrets.ALI_IMAGE_NAME }}/${{ matrix.sub_routes.repo }}:${{ github.ref_name }}" >> $GITHUB_ENV
158+
echo "Ali_Latest=${{ secrets.ALI_IMAGE_NAME }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
159+
echo "Docker_Hub_Tag=${{ secrets.DOCKER_IMAGE_NAME }}/${{ matrix.sub_routes.repo }}:${{ github.ref_name }}" >> $GITHUB_ENV
160+
echo "Docker_Hub_Latest=${{ secrets.DOCKER_IMAGE_NAME }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
252161
fi
253162
254-
- name: Build and publish image for main branch or tag push event
255-
env:
256-
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
163+
- name: Create manifest list and push
164+
working-directory: ${{ runner.temp }}/digests
257165
run: |
258-
docker buildx build \
259-
-f projects/app/Dockerfile \
260-
--platform linux/amd64,linux/arm64 \
261-
--build-arg base_url=/gchat \
262-
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT" \
263-
--label "org.opencontainers.image.description=fastgpt-sub-route-gchat image" \
264-
--push \
265-
--cache-from=type=local,src=/tmp/.buildx-cache \
266-
--cache-to=type=local,dest=/tmp/.buildx-cache \
267-
-t ${Git_Tag} \
268-
-t ${Git_Latest} \
269-
-t ${Ali_Tag} \
270-
-t ${Ali_Latest} \
271-
-t ${Docker_Hub_Tag} \
272-
-t ${Docker_Hub_Latest} \
273-
.
166+
TAGS="$(echo -e "${Git_Tag}\n${Git_Latest}\n${Ali_Tag}\n${Ali_Latest}\n${Docker_Hub_Tag}\n${Docker_Hub_Latest}")"
167+
for TAG in $TAGS; do
168+
docker buildx imagetools create -t $TAG \
169+
$(printf 'ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}@sha256:%s ' *)
170+
sleep 5
171+
done

0 commit comments

Comments
 (0)