|
1 | 1 | name: Build FastGPT images |
| 2 | + |
2 | 3 | on: |
3 | 4 | workflow_dispatch: |
4 | 5 | push: |
5 | 6 | paths: |
6 | | - - 'projects/app/**' |
7 | | - - 'packages/**' |
| 7 | + - "projects/app/**" |
| 8 | + - "packages/**" |
8 | 9 | tags: |
9 | | - - 'v*' |
| 10 | + - "v*" |
| 11 | + |
10 | 12 | jobs: |
11 | 13 | build-fastgpt-images: |
12 | 14 | permissions: |
13 | 15 | packages: write |
14 | 16 | contents: read |
15 | 17 | attestations: write |
16 | 18 | 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' }} |
18 | 33 | steps: |
19 | 34 | # install env |
20 | 35 | - name: Checkout |
21 | | - uses: actions/checkout@v3 |
| 36 | + uses: actions/checkout@v4 |
22 | 37 | with: |
23 | 38 | 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 | + |
29 | 40 | - name: Set up Docker Buildx |
30 | | - uses: docker/setup-buildx-action@v2 |
| 41 | + uses: docker/setup-buildx-action@v3 |
31 | 42 | with: |
32 | 43 | driver-opts: network=host |
| 44 | + |
33 | 45 | - name: Cache Docker layers |
34 | 46 | uses: actions/cache@v4 |
35 | 47 | with: |
36 | 48 | path: /tmp/.buildx-cache |
37 | | - key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 49 | + key: ${{ runner.os }}-${{ matrix.sub_routes.repo }}-buildx-${{ github.sha }} |
38 | 50 | restore-keys: | |
39 | | - ${{ runner.os }}-buildx- |
| 51 | + ${{ runner.os }}-${{ matrix.sub_routes.repo }}-buildx- |
40 | 52 |
|
41 | 53 | # login docker |
42 | 54 | - name: Login to GitHub Container Registry |
43 | | - uses: docker/login-action@v2 |
| 55 | + uses: docker/login-action@v3 |
44 | 56 | with: |
45 | 57 | registry: ghcr.io |
46 | 58 | username: ${{ github.repository_owner }} |
47 | 59 | password: ${{ secrets.GITHUB_TOKEN }} |
48 | 60 | - name: Login to Ali Hub |
49 | | - uses: docker/login-action@v2 |
| 61 | + uses: docker/login-action@v3 |
50 | 62 | with: |
51 | 63 | registry: registry.cn-hangzhou.aliyuncs.com |
52 | 64 | username: ${{ secrets.ALI_HUB_USERNAME }} |
53 | 65 | password: ${{ secrets.ALI_HUB_PASSWORD }} |
54 | 66 | - name: Login to Docker Hub |
55 | | - uses: docker/login-action@v2 |
| 67 | + uses: docker/login-action@v3 |
56 | 68 | with: |
57 | 69 | username: ${{ secrets.DOCKER_HUB_NAME }} |
58 | 70 | password: ${{ secrets.DOCKER_HUB_PASSWORD }} |
59 | 71 |
|
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 |
78 | 87 |
|
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 |
82 | 89 | 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:}" |
127 | 93 |
|
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 |
131 | 96 | 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 |
146 | 101 |
|
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: |
187 | 103 | permissions: |
188 | 104 | packages: write |
189 | 105 | contents: read |
190 | 106 | attestations: write |
191 | 107 | 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 |
193 | 116 | 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 |
217 | 117 | - name: Login to GitHub Container Registry |
218 | | - uses: docker/login-action@v2 |
| 118 | + uses: docker/login-action@v3 |
219 | 119 | with: |
220 | 120 | registry: ghcr.io |
221 | 121 | username: ${{ github.repository_owner }} |
222 | 122 | password: ${{ secrets.GITHUB_TOKEN }} |
223 | 123 | - name: Login to Ali Hub |
224 | | - uses: docker/login-action@v2 |
| 124 | + uses: docker/login-action@v3 |
225 | 125 | with: |
226 | 126 | registry: registry.cn-hangzhou.aliyuncs.com |
227 | 127 | username: ${{ secrets.ALI_HUB_USERNAME }} |
228 | 128 | password: ${{ secrets.ALI_HUB_PASSWORD }} |
229 | 129 | - name: Login to Docker Hub |
230 | | - uses: docker/login-action@v2 |
| 130 | + uses: docker/login-action@v3 |
231 | 131 | with: |
232 | 132 | username: ${{ secrets.DOCKER_HUB_NAME }} |
233 | 133 | password: ${{ secrets.DOCKER_HUB_PASSWORD }} |
234 | 134 |
|
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 | + |
236 | 145 | - name: Set image name and tag |
237 | 146 | run: | |
238 | 147 | 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 |
245 | 154 | 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 |
252 | 161 | fi |
253 | 162 |
|
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 |
257 | 165 | 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