11name : docker-image
22
3- # Builds and publishes the multi-arch Docker image for CLIProxyAPIPlus to GHCR .
3+ # Builds and publishes the multi-arch Docker image for CLIProxyAPIPlus.
44#
55# Triggers:
66# - push of any v* tag (works when a PAT pushes the tag; sync-release-tag.yml
@@ -11,8 +11,10 @@ name: docker-image
1111# Runner: self-hosted `cliproxy` (docker host LXC). QEMU + buildx produce both
1212# linux/amd64 and linux/arm64 from a single x64 host.
1313#
14- # Registry: ghcr.io/<owner>/cli-proxy-api-plus. Auth uses the built-in
15- # GITHUB_TOKEN — no Docker Hub credentials required.
14+ # Registries:
15+ # - GHCR: ghcr.io/<owner>/cli-proxy-api-plus using built-in GITHUB_TOKEN
16+ # - Docker Hub: kaitranntt/cli-proxy-api-plus when DOCKERHUB_TOKEN is
17+ # configured (DOCKERHUB_USERNAME is optional; defaults to kaitranntt)
1618
1719on :
1820 workflow_dispatch :
2729
2830env :
2931 APP_NAME : CLIProxyAPI
30- REGISTRY : ghcr.io
31- IMAGE_NAME : ${{ github.repository_owner }}/cli-proxy-api-plus
32+ GHCR_REGISTRY : ghcr.io
33+ GHCR_IMAGE_NAME : ${{ github.repository_owner }}/cli-proxy-api-plus
34+ DOCKERHUB_IMAGE_NAME : kaitranntt/cli-proxy-api-plus
3235
3336permissions :
3437 contents : read
@@ -71,16 +74,38 @@ jobs:
7174 - name : Login to GHCR
7275 uses : docker/login-action@v3
7376 with :
74- registry : ${{ env.REGISTRY }}
77+ registry : ${{ env.GHCR_REGISTRY }}
7578 username : ${{ github.actor }}
7679 password : ${{ secrets.GITHUB_TOKEN }}
7780
78- - name : Lowercase image name
81+ - name : Detect Docker Hub credentials
82+ id : dockerhub
83+ env :
84+ DOCKERHUB_TOKEN : ${{ secrets.DOCKERHUB_TOKEN }}
85+ run : |
86+ if [ -n "${DOCKERHUB_TOKEN}" ]; then
87+ echo "enabled=true" >> "$GITHUB_OUTPUT"
88+ else
89+ echo "enabled=false" >> "$GITHUB_OUTPUT"
90+ fi
91+
92+ - name : Login to Docker Hub
93+ if : steps.dockerhub.outputs.enabled == 'true'
94+ uses : docker/login-action@v3
95+ with :
96+ username : ${{ secrets.DOCKERHUB_USERNAME || 'kaitranntt' }}
97+ password : ${{ secrets.DOCKERHUB_TOKEN }}
98+
99+ - name : Lowercase image names
79100 id : img
80101 run : |
81- IMG="${REGISTRY}/${IMAGE_NAME}"
82- IMG_LC="$(echo "${IMG}" | tr '[:upper:]' '[:lower:]')"
83- echo "ref=${IMG_LC}" >> "$GITHUB_OUTPUT"
102+ GHCR_IMG="${GHCR_REGISTRY}/${GHCR_IMAGE_NAME}"
103+ GHCR_IMG_LC="$(echo "${GHCR_IMG}" | tr '[:upper:]' '[:lower:]')"
104+ DOCKERHUB_IMG_LC="$(echo "${DOCKERHUB_IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')"
105+ {
106+ echo "ghcr_ref=${GHCR_IMG_LC}"
107+ echo "dockerhub_ref=${DOCKERHUB_IMG_LC}"
108+ } >> "$GITHUB_OUTPUT"
84109
85110 - name : Build metadata
86111 id : meta
@@ -94,6 +119,25 @@ jobs:
94119 echo "build_date=${BUILD_DATE}"
95120 } >> "$GITHUB_OUTPUT"
96121
122+ - name : Build tag list
123+ id : tags
124+ env :
125+ GHCR_REF : ${{ steps.img.outputs.ghcr_ref }}
126+ DOCKERHUB_REF : ${{ steps.img.outputs.dockerhub_ref }}
127+ VERSION : ${{ steps.meta.outputs.version }}
128+ DOCKERHUB_ENABLED : ${{ steps.dockerhub.outputs.enabled }}
129+ run : |
130+ {
131+ echo "tags<<EOF"
132+ echo "${GHCR_REF}:${VERSION}"
133+ echo "${GHCR_REF}:latest"
134+ if [ "${DOCKERHUB_ENABLED}" = "true" ]; then
135+ echo "${DOCKERHUB_REF}:${VERSION}"
136+ echo "${DOCKERHUB_REF}:latest"
137+ fi
138+ echo "EOF"
139+ } >> "$GITHUB_OUTPUT"
140+
97141 - name : Build and push (multi-arch)
98142 uses : docker/build-push-action@v6
99143 with :
@@ -104,16 +148,28 @@ jobs:
104148 VERSION=${{ steps.meta.outputs.version }}
105149 COMMIT=${{ steps.meta.outputs.commit }}
106150 BUILD_DATE=${{ steps.meta.outputs.build_date }}
107- tags : |
108- ${{ steps.img.outputs.ref }}:${{ steps.meta.outputs.version }}
109- ${{ steps.img.outputs.ref }}:latest
151+ tags : ${{ steps.tags.outputs.tags }}
110152
111153 - name : Summary
154+ env :
155+ GHCR_REF : ${{ steps.img.outputs.ghcr_ref }}
156+ DOCKERHUB_REF : ${{ steps.img.outputs.dockerhub_ref }}
157+ VERSION : ${{ steps.meta.outputs.version }}
158+ DOCKERHUB_ENABLED : ${{ steps.dockerhub.outputs.enabled }}
112159 run : |
113160 {
114161 echo "## Published"
115- echo "- \`${{ steps.img.outputs.ref }}:${{ steps.meta.outputs.version }}\`"
116- echo "- \`${{ steps.img.outputs.ref }}:latest\`"
117- echo
118- echo "Pull: \`docker pull ${{ steps.img.outputs.ref }}:${{ steps.meta.outputs.version }}\`"
162+ echo "- \`${GHCR_REF}:${VERSION}\`"
163+ echo "- \`${GHCR_REF}:latest\`"
164+ if [ "${DOCKERHUB_ENABLED}" = "true" ]; then
165+ echo "- \`${DOCKERHUB_REF}:${VERSION}\`"
166+ echo "- \`${DOCKERHUB_REF}:latest\`"
167+ echo
168+ echo "Pull: \`docker pull ${DOCKERHUB_REF}:${VERSION}\`"
169+ else
170+ echo
171+ echo "Docker Hub skipped: configure \`DOCKERHUB_TOKEN\` to publish \`${DOCKERHUB_REF}\`. Set \`DOCKERHUB_USERNAME\` only if the login account is not \`kaitranntt\`."
172+ echo
173+ echo "Pull: \`docker pull ${GHCR_REF}:${VERSION}\`"
174+ fi
119175 } >> "$GITHUB_STEP_SUMMARY"
0 commit comments