From 2815c36f92fd88bcb55a5d9a084d26c07cba3180 Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Mon, 10 Feb 2025 10:26:00 +0800 Subject: [PATCH] Fix target sync image --- .github/workflows/sync-image.yml | 9 ++------- hack/real-image.sh | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100755 hack/real-image.sh diff --git a/.github/workflows/sync-image.yml b/.github/workflows/sync-image.yml index 5868be5..1e3a72b 100644 --- a/.github/workflows/sync-image.yml +++ b/.github/workflows/sync-image.yml @@ -46,14 +46,9 @@ jobs: exit 1 fi echo "image=${ORIGIN_IMAGE}" >> $GITHUB_OUTPUT - if [[ "${ORIGIN_IMAGE}" =~ ^docker.io/ ]]; then - ORIGIN_IMAGE="registry-1.${ORIGIN_IMAGE}" - fi - if [[ "${ORIGIN_IMAGE}" =~ ^registry-1\.docker\.io/[^/]+$ ]]; then - ORIGIN_IMAGE="registry-1.docker.io/library/${ORIGIN_IMAGE#registry-1.docker.io/}" - fi - echo "sync_image=${ORIGIN_IMAGE}" >> $GITHUB_OUTPUT + SYNC_IMAGE="$(./hack/real-image.sh "${ORIGIN_IMAGE}")" + echo "sync_image=${SYNC_IMAGE}" >> $GITHUB_OUTPUT - name: Set up crproxy run: | diff --git a/hack/real-image.sh b/hack/real-image.sh new file mode 100755 index 0000000..eb5601d --- /dev/null +++ b/hack/real-image.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +function guess_image() { + local image="${1}" + + if [[ -z "${image}" ]]; then + return + fi + + if [[ "${image}" =~ ^"docker.io/"* ]]; then + image="registry-1.${image}" + fi + + if [[ "${image}" =~ ^"registry-1.docker.io/"[^/]+$ ]]; then + image="registry-1.docker.io/library/${image#*/}" + fi + + echo "${image}" +} + +guess_image "${1}"