Skip to content

Commit 25fb662

Browse files
authored
chore: update admin release workflow (#6842)
* chore: update admin release workflow * fix: preview-admin-build.yml
1 parent c1c6b95 commit 25fb662

3 files changed

Lines changed: 175 additions & 15 deletions

File tree

.github/workflows/build-admin.yml

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
name: Build FastGPT Admin images
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- "v*"
8+
9+
jobs:
10+
build-fastgpt-admin-images:
11+
permissions:
12+
packages: write
13+
contents: read
14+
attestations: write
15+
id-token: write
16+
strategy:
17+
matrix:
18+
sub_routes:
19+
- repo: fastgpt-pro
20+
base_url: ""
21+
- repo: fastgpt-pro-sub-route
22+
base_url: "/fastaipro"
23+
- repo: fastgpt-pro-sub-route-gchat
24+
base_url: "/gchat-admin"
25+
archs:
26+
- arch: amd64
27+
- arch: arm64
28+
runs-on: ubuntu-24.04-arm
29+
runs-on: ${{ matrix.archs.runs-on || 'ubuntu-24.04' }}
30+
steps:
31+
# install env
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 1
36+
37+
- name: Update submodules
38+
env:
39+
PRO_SUBMODULE_TOKEN: ${{ secrets.PRO_SUBMODULE_TOKEN }}
40+
run: |
41+
if [ -f .gitmodules ]; then
42+
if [ -z "${PRO_SUBMODULE_TOKEN}" ]; then
43+
echo "::error::PRO_SUBMODULE_TOKEN is required to clone the private pro submodule. Add it to this repository's Actions secrets, or run this workflow from a repository that has the secret configured."
44+
exit 1
45+
fi
46+
git config --global url."https://x-access-token:${PRO_SUBMODULE_TOKEN}@github.com/".insteadOf "https://github.com/"
47+
git submodule update --init --recursive
48+
fi
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v3
52+
with:
53+
driver-opts: network=host
54+
55+
- name: Cache Docker layers
56+
uses: actions/cache@v4
57+
with:
58+
path: /tmp/.buildx-cache
59+
key: ${{ runner.os }}-${{ matrix.archs.arch }}-${{ matrix.sub_routes.repo
60+
}}-buildx-${{ github.sha }}
61+
restore-keys: |
62+
${{ runner.os }}-${{ matrix.archs.arch }}-${{ matrix.sub_routes.repo }}-buildx-
63+
64+
# login docker (GHCR only; Ali tags are pushed in release job via imagetools)
65+
- name: Login to GitHub Container Registry
66+
uses: docker/login-action@v3
67+
with:
68+
registry: ghcr.io
69+
username: ${{ github.repository_owner }}
70+
password: ${{ secrets.GITHUB_TOKEN }}
71+
72+
- name: Build for ${{ matrix.archs.arch }}
73+
id: build
74+
uses: docker/build-push-action@v6
75+
with:
76+
context: .
77+
file: pro/admin/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 }}
83+
org.opencontainers.image.description=${{ matrix.sub_routes.repo }} image
84+
outputs: type=image,"name=ghcr.io/${{ github.repository_owner }}/${{
85+
matrix.sub_routes.repo }}",push-by-digest=true,push=true
86+
cache-from: type=local,src=/tmp/.buildx-cache
87+
cache-to: type=local,dest=/tmp/.buildx-cache
88+
89+
- name: Export digest
90+
run: |
91+
mkdir -p ${{ runner.temp }}/digests/${{ matrix.sub_routes.repo }}
92+
digest="${{ steps.build.outputs.digest }}"
93+
touch "${{ runner.temp }}/digests/${{ matrix.sub_routes.repo }}/${digest#sha256:}"
94+
95+
- name: Upload digest
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: digests-${{ matrix.sub_routes.repo }}-${{ github.sha }}-${{
99+
matrix.archs.arch }}
100+
path: ${{ runner.temp }}/digests/${{ matrix.sub_routes.repo }}/*
101+
if-no-files-found: error
102+
retention-days: 1
103+
104+
release-fastgpt-images:
105+
permissions:
106+
packages: write
107+
contents: read
108+
attestations: write
109+
id-token: write
110+
needs: build-fastgpt-admin-images
111+
strategy:
112+
matrix:
113+
sub_routes:
114+
- repo: fastgpt-pro
115+
- repo: fastgpt-pro-sub-route
116+
- repo: fastgpt-pro-sub-route-gchat
117+
runs-on: ubuntu-24.04
118+
steps:
119+
- name: Login to GitHub Container Registry
120+
uses: docker/login-action@v3
121+
with:
122+
registry: ghcr.io
123+
username: ${{ github.repository_owner }}
124+
password: ${{ secrets.GITHUB_TOKEN }}
125+
- name: Login to Ali Hub
126+
uses: docker/login-action@v3
127+
with:
128+
registry: registry.cn-hangzhou.aliyuncs.com
129+
username: ${{ secrets.FASTGPT_ALI_IMAGE_USER }}
130+
password: ${{ secrets.FASTGPT_ALI_IMAGE_PSW }}
131+
132+
- name: Download digests
133+
uses: actions/download-artifact@v4
134+
with:
135+
path: ${{ runner.temp }}/digests
136+
pattern: digests-${{ matrix.sub_routes.repo }}-${{ github.sha }}-*
137+
merge-multiple: true
138+
139+
- name: Set up Docker Buildx
140+
uses: docker/setup-buildx-action@v3
141+
142+
- name: Set image name and tag
143+
run: |
144+
if [[ "${{ github.ref_name }}" == "main" ]]; then
145+
echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
146+
echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
147+
echo "Ali_Tag=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
148+
echo "Ali_Latest=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
149+
else
150+
echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:${{ github.ref_name }}" >> $GITHUB_ENV
151+
echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
152+
echo "Ali_Tag=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/${{ matrix.sub_routes.repo }}:${{ github.ref_name }}" >> $GITHUB_ENV
153+
echo "Ali_Latest=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/${{ matrix.sub_routes.repo }}:latest" >> $GITHUB_ENV
154+
fi
155+
156+
- name: Create manifest list and push
157+
working-directory: ${{ runner.temp }}/digests
158+
run: |
159+
TAGS="$(echo -e "${Git_Tag}\n${Git_Latest}\n${Ali_Tag}\n${Ali_Latest}")"
160+
for TAG in $TAGS; do
161+
docker buildx imagetools create -t $TAG \
162+
$(printf 'ghcr.io/${{ github.repository_owner }}/${{ matrix.sub_routes.repo }}@sha256:%s ' *)
163+
sleep 5
164+
done

.github/workflows/preview-admin-build.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Preview Admin Image - Build
22

33
on:
4-
pull_request_target:
5-
types: [ opened, synchronize, reopened ]
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
branches: ['*']
67
paths:
78
- "pro"
89
- "pro/**"
@@ -14,10 +15,9 @@ on:
1415
- ".gitmodules"
1516
- ".github/workflows/preview-admin-build.yml"
1617
- ".github/workflows/preview-admin-push.yml"
17-
workflow_dispatch:
1818

1919
concurrency:
20-
group: "preview-admin-build-${{ github.event.pull_request.number || github.ref }}"
20+
group: 'preview-admin-build-${{ github.head_ref || github.ref }}'
2121
cancel-in-progress: true
2222

2323
permissions:
@@ -31,11 +31,8 @@ jobs:
3131
- name: Checkout PR code
3232
uses: actions/checkout@v4
3333
with:
34-
ref: ${{ github.event_name == 'pull_request_target' &&
35-
github.event.pull_request.head.sha || github.ref }}
36-
repository: ${{ github.event_name == 'pull_request_target' &&
37-
github.event.pull_request.head.repo.full_name || github.repository
38-
}}
34+
ref: ${{ github.event.pull_request.head.sha }}
35+
repository: ${{ github.event.pull_request.head.repo.full_name }}
3936
fetch-depth: 1
4037

4138
- name: Update submodules
@@ -63,20 +60,19 @@ jobs:
6360
file: pro/admin/Dockerfile
6461
platforms: linux/amd64
6562
push: false
66-
tags: fastgpt-pro-pr:${{ github.event_name == 'pull_request_target' &&
67-
github.event.pull_request.head.sha || github.sha }}
63+
tags: fastgpt-pro-pr:${{ github.event.pull_request.head.sha }}
6864
labels: |
6965
org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT
7066
org.opencontainers.image.description=fastgpt-pro admin image
71-
org.opencontainers.image.revision=${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
67+
org.opencontainers.image.revision=${{ github.event.pull_request.head.sha }}
7268
outputs: type=docker,dest=/tmp/fastgpt-pro-image.tar
7369
cache-from: type=gha,scope=fastgpt-pro
7470
cache-to: type=gha,mode=max,scope=fastgpt-pro
7571

7672
- name: Save PR metadata
7773
run: |
78-
echo "${{ github.event.pull_request.number || '' }}" > /tmp/pr-number.txt
79-
echo "${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}" > /tmp/pr-sha.txt
74+
echo "${{ github.event.pull_request.number }}" > /tmp/pr-number.txt
75+
echo "${{ github.event.pull_request.head.sha }}" > /tmp/pr-sha.txt
8076
8177
- name: Upload Docker image artifact
8278
uses: actions/upload-artifact@v4

pro

Submodule pro updated from 41720ca to de08613

0 commit comments

Comments
 (0)