forked from kaitranntt/CLIProxyAPIPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
321 lines (287 loc) · 11 KB
/
Copy pathdocker-image.yml
File metadata and controls
321 lines (287 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
name: docker-image
# Builds and publishes the multi-arch Docker image for CLIProxyAPIPlus.
#
# Triggers:
# - push to main -> build & push :latest only
# - push of any v* tag -> build & push :tag + :latest
# - workflow_dispatch with optional `tag` input
#
# Architecture: native ARM64 / AMD64 partner jobs (no QEMU), merged into
# a single multi-arch manifest.
#
# Registries:
# - GHCR: ghcr.io/<repository> (built-in GITHUB_TOKEN)
# - Docker Hub: kaitranntt/cli-proxy-api-plus when DOCKERHUB_TOKEN is
# configured (DOCKERHUB_USERNAME is optional; defaults to kaitranntt)
on:
workflow_dispatch:
inputs:
tag:
description: 'Existing tag to build, e.g. v6.9.45-0'
required: false
type: string
push:
branches:
- main
tags:
- 'v*'
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
GHCR_REGISTRY: ghcr.io
GHCR_IMAGE_NAME: ${{ github.repository }}
DOCKERHUB_IMAGE_NAME: kaitranntt/cli-proxy-api-plus
permissions:
contents: read
packages: write
concurrency:
group: docker-image-${{ inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
# ── shared metadata ──────────────────────────────────────────────────────
meta:
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.ref.outputs.ref }}
is_tag: ${{ steps.ref.outputs.is_tag }}
version: ${{ steps.meta.outputs.version }}
commit: ${{ steps.meta.outputs.commit }}
build_date: ${{ steps.meta.outputs.build_date }}
ghcr_ref: ${{ steps.img.outputs.ghcr_ref }}
dockerhub_ref: ${{ steps.img.outputs.dockerhub_ref }}
dockerhub_enabled: ${{ steps.dockerhub.outputs.enabled }}
tag_version: ${{ steps.tags.outputs.tag_version }}
tag_latest: ${{ steps.tags.outputs.tag_latest }}
steps:
- name: Resolve build ref
id: ref
run: |
REF="${GITHUB_REF_NAME}"
# workflow_dispatch may supply an explicit tag
if [ -n "${{ inputs.tag }}" ]; then REF="${{ inputs.tag }}"; fi
echo "ref=${REF}" >> "$GITHUB_OUTPUT"
# Determine mode: tag push -> versioned, otherwise latest-only
if echo "${GITHUB_REF}" | grep -q '^refs/tags/'; then
echo "is_tag=true" >> "$GITHUB_OUTPUT"
elif [ -n "${{ inputs.tag }}" ]; then
echo "is_tag=true" >> "$GITHUB_OUTPUT"
else
echo "is_tag=false" >> "$GITHUB_OUTPUT"
fi
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ steps.ref.outputs.ref }}
fetch-depth: 0
- name: Build metadata
id: meta
run: |
VERSION="${{ steps.ref.outputs.ref }}"
COMMIT="$(git rev-parse --short HEAD)"
BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
{
echo "version=${VERSION}"
echo "commit=${COMMIT}"
echo "build_date=${BUILD_DATE}"
} >> "$GITHUB_OUTPUT"
- name: Lowercase image names
id: img
run: |
GHCR_IMG="${GHCR_REGISTRY}/${GHCR_IMAGE_NAME}"
GHCR_IMG_LC="$(echo "${GHCR_IMG}" | tr '[:upper:]' '[:lower:]')"
DOCKERHUB_IMG_LC="$(echo "${DOCKERHUB_IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')"
{
echo "ghcr_ref=${GHCR_IMG_LC}"
echo "dockerhub_ref=${DOCKERHUB_IMG_LC}"
} >> "$GITHUB_OUTPUT"
- name: Detect Docker Hub credentials
id: dockerhub
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
if [ -n "${DOCKERHUB_TOKEN}" ]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi
- name: Build tag list
id: tags
env:
GHCR_REF: ${{ steps.img.outputs.ghcr_ref }}
VERSION: ${{ steps.meta.outputs.version }}
IS_TAG: ${{ steps.ref.outputs.is_tag }}
run: |
# Always push to latest
echo "tag_latest=${GHCR_REF}:latest" >> "$GITHUB_OUTPUT"
if [ "${IS_TAG}" = "true" ]; then
echo "tag_version=${GHCR_REF}:${VERSION}" >> "$GITHUB_OUTPUT"
else
# Branch push: version tag is same as latest (only latest pushed)
echo "tag_version=${GHCR_REF}:latest" >> "$GITHUB_OUTPUT"
fi
# ── AMD64 build ──────────────────────────────────────────────────────────
build-amd64:
needs: meta
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.meta.outputs.ref }}
fetch-depth: 0
- name: Refresh models catalog
run: |
git fetch --depth 1 https://github.com/router-for-me/models.git main
git show FETCH_HEAD:models.json > internal/registry/models/models.json
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
if: needs.meta.outputs.dockerhub_enabled == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME || 'kaitranntt' }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push (amd64)
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
provenance: false
build-args: |
VERSION=${{ needs.meta.outputs.version }}
COMMIT=${{ needs.meta.outputs.commit }}
BUILD_DATE=${{ needs.meta.outputs.build_date }}
tags: |
${{ needs.meta.outputs.tag_version }}-amd64
cache-from: type=gha,scope=amd64
cache-to: type=gha,mode=max,scope=amd64
# ── ARM64 build ──────────────────────────────────────────────────────────
build-arm64:
needs: meta
runs-on: ubuntu-24.04-arm
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.meta.outputs.ref }}
fetch-depth: 0
- name: Refresh models catalog
run: |
git fetch --depth 1 https://github.com/router-for-me/models.git main
git show FETCH_HEAD:models.json > internal/registry/models/models.json
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
if: needs.meta.outputs.dockerhub_enabled == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME || 'kaitranntt' }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push (arm64)
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/arm64
push: true
provenance: false
build-args: |
VERSION=${{ needs.meta.outputs.version }}
COMMIT=${{ needs.meta.outputs.commit }}
BUILD_DATE=${{ needs.meta.outputs.build_date }}
tags: |
${{ needs.meta.outputs.tag_version }}-arm64
cache-from: type=gha,scope=arm64
cache-to: type=gha,mode=max,scope=arm64
# ── Merge multi-arch manifest ────────────────────────────────────────────
merge:
needs: [meta, build-amd64, build-arm64]
runs-on: ubuntu-latest
steps:
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
if: needs.meta.outputs.dockerhub_enabled == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME || 'kaitranntt' }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create and push multi-arch manifest (GHCR)
env:
TAG_VERSION: ${{ needs.meta.outputs.tag_version }}
TAG_LATEST: ${{ needs.meta.outputs.tag_latest }}
IS_TAG: ${{ needs.meta.outputs.is_tag }}
run: |
set -euo pipefail
AMEND=""
for SUFFIX in -amd64 -arm64; do
docker pull "${TAG_VERSION}${SUFFIX}"
AMEND="${AMEND} --amend ${TAG_VERSION}${SUFFIX}"
done
if [ "${IS_TAG}" = "true" ]; then
docker manifest create ${TAG_VERSION} ${AMEND}
docker manifest push ${TAG_VERSION}
fi
docker manifest create ${TAG_LATEST} ${AMEND}
docker manifest push ${TAG_LATEST}
- name: Create and push multi-arch manifest (Docker Hub)
if: needs.meta.outputs.dockerhub_enabled == 'true'
env:
DOCKERHUB_REF: ${{ needs.meta.outputs.dockerhub_ref }}
TAG_VERSION: ${{ needs.meta.outputs.tag_version }}
IS_TAG: ${{ needs.meta.outputs.is_tag }}
run: |
set -euo pipefail
VERSION_TAG="${DOCKERHUB_REF}:${TAG_VERSION##*:}"
LATEST_TAG="${DOCKERHUB_REF}:latest"
AMEND=""
for SUFFIX in -amd64 -arm64; do
AMEND="${AMEND} --amend ${TAG_VERSION}${SUFFIX}"
done
if [ "${IS_TAG}" = "true" ]; then
docker manifest create ${VERSION_TAG} ${AMEND}
docker manifest push ${VERSION_TAG}
fi
docker manifest create ${LATEST_TAG} ${AMEND}
docker manifest push ${LATEST_TAG}
- name: Summary
env:
GHCR_REF: ${{ needs.meta.outputs.ghcr_ref }}
DOCKERHUB_REF: ${{ needs.meta.outputs.dockerhub_ref }}
VERSION: ${{ needs.meta.outputs.version }}
IS_TAG: ${{ needs.meta.outputs.is_tag }}
DOCKERHUB_ENABLED: ${{ needs.meta.outputs.dockerhub_enabled }}
run: |
{
echo "## Published"
echo "- \`${GHCR_REF}:latest\`"
if [ "${IS_TAG}" = "true" ]; then
echo "- \`${GHCR_REF}:${VERSION}\`"
fi
if [ "${DOCKERHUB_ENABLED}" = "true" ]; then
echo "- \`${DOCKERHUB_REF}:latest\`"
if [ "${IS_TAG}" = "true" ]; then
echo "- \`${DOCKERHUB_REF}:${VERSION}\`"
fi
echo
echo "Pull: \`docker pull ${DOCKERHUB_REF}:latest\`"
else
echo
echo "Pull: \`docker pull ${GHCR_REF}:latest\`"
fi
} >> "$GITHUB_STEP_SUMMARY"