From c82cbd5b5bb272b7ec13583b3e31b60f8b2ff565 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 13 Nov 2021 20:35:45 +0100 Subject: [PATCH] fix: use docker lib for image ref parsing (#877) Signed-off-by: hackercat --- act/container/docker_pull.go | 14 ++++++-------- act/container/docker_pull_test.go | 3 +++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/act/container/docker_pull.go b/act/container/docker_pull.go index 399e4604..99cbdcdb 100644 --- a/act/container/docker_pull.go +++ b/act/container/docker_pull.go @@ -4,9 +4,8 @@ import ( "context" "encoding/base64" "encoding/json" - "fmt" - "strings" + "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -99,12 +98,11 @@ func getImagePullOptions(ctx context.Context, input NewDockerPullExecutorInput) } func cleanImage(image string) string { - imageParts := len(strings.Split(image, "/")) - if imageParts == 1 { - image = fmt.Sprintf("docker.io/library/%s", image) - } else if imageParts == 2 { - image = fmt.Sprintf("docker.io/%s", image) + ref, err := reference.ParseAnyReference(image) + if err != nil { + log.Error(err) + return "" } - return image + return ref.String() } diff --git a/act/container/docker_pull_test.go b/act/container/docker_pull_test.go index 58707b78..e242865c 100644 --- a/act/container/docker_pull_test.go +++ b/act/container/docker_pull_test.go @@ -18,6 +18,9 @@ func TestCleanImage(t *testing.T) { imageOut string }{ {"myhost.com/foo/bar", "myhost.com/foo/bar"}, + {"localhost:8000/canonical/ubuntu", "localhost:8000/canonical/ubuntu"}, + {"localhost/canonical/ubuntu:latest", "localhost/canonical/ubuntu:latest"}, + {"localhost:8000/canonical/ubuntu:latest", "localhost:8000/canonical/ubuntu:latest"}, {"ubuntu", "docker.io/library/ubuntu"}, {"ubuntu:18.04", "docker.io/library/ubuntu:18.04"}, {"cibuilds/hugo:0.53", "docker.io/cibuilds/hugo:0.53"},