From 7645aafc10aacf90d23384dca96d7c1c8165712b Mon Sep 17 00:00:00 2001 From: Yadong Ding Date: Fri, 12 Jan 2024 15:58:43 +0800 Subject: [PATCH] feat: support sha256 format image convert source image such as `repo:tag@sha256xxxxxx` or `repo@sha256xxxxxx`. Signed-off-by: Yadong Ding --- pkg/adapter/rule.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/adapter/rule.go b/pkg/adapter/rule.go index fb0d9593..b60d5ec9 100644 --- a/pkg/adapter/rule.go +++ b/pkg/adapter/rule.go @@ -16,6 +16,7 @@ package adapter import ( "fmt" + "regexp" "strings" "github.com/containerd/containerd/reference/docker" @@ -34,7 +35,8 @@ const ( // Source: 192.168.1.1/nginx:latest // Target: 192.168.1.1/nginx:latest-suffix func addSuffix(ref, suffix string) (string, error) { - named, err := docker.ParseDockerRef(ref) + re := regexp.MustCompile(`@sha256.*`) + named, err := docker.ParseDockerRef(re.ReplaceAllString(ref, "")) if err != nil { return "", errors.Wrap(err, "invalid source image reference") } @@ -50,7 +52,8 @@ func addSuffix(ref, suffix string) (string, error) { // Source:192.168.1.1/nginx:latest // Target:192.168.1.1/nginx:tag func setReferenceTag(ref, tag string) (string, error) { - named, err := docker.ParseDockerRef(ref) + re := regexp.MustCompile(`@sha256.*`) + named, err := docker.ParseDockerRef(re.ReplaceAllString(ref, "")) if err != nil { return "", errors.Wrap(err, "invalid source image reference") }