fix: use docker lib for image ref parsing (#877)
Signed-off-by: hackercat <me@hackerc.at>
This commit is contained in:
parent
62d2167f3b
commit
ec34eb9532
3 changed files with 10 additions and 8 deletions
1
go.mod
1
go.mod
|
@ -11,6 +11,7 @@ require (
|
||||||
github.com/containerd/containerd v1.5.5 // indirect
|
github.com/containerd/containerd v1.5.5 // indirect
|
||||||
github.com/containerd/continuity v0.2.0 // indirect
|
github.com/containerd/continuity v0.2.0 // indirect
|
||||||
github.com/docker/cli v20.10.10+incompatible
|
github.com/docker/cli v20.10.10+incompatible
|
||||||
|
github.com/docker/distribution v2.7.1+incompatible
|
||||||
github.com/docker/docker v20.10.10+incompatible
|
github.com/docker/docker v20.10.10+incompatible
|
||||||
github.com/go-git/go-billy/v5 v5.3.1
|
github.com/go-git/go-billy/v5 v5.3.1
|
||||||
github.com/go-git/go-git/v5 v5.4.2
|
github.com/go-git/go-git/v5 v5.4.2
|
||||||
|
|
|
@ -4,9 +4,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -99,12 +98,11 @@ func getImagePullOptions(ctx context.Context, input NewDockerPullExecutorInput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanImage(image string) string {
|
func cleanImage(image string) string {
|
||||||
imageParts := len(strings.Split(image, "/"))
|
ref, err := reference.ParseAnyReference(image)
|
||||||
if imageParts == 1 {
|
if err != nil {
|
||||||
image = fmt.Sprintf("docker.io/library/%s", image)
|
log.Error(err)
|
||||||
} else if imageParts == 2 {
|
return ""
|
||||||
image = fmt.Sprintf("docker.io/%s", image)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return image
|
return ref.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@ func TestCleanImage(t *testing.T) {
|
||||||
imageOut string
|
imageOut string
|
||||||
}{
|
}{
|
||||||
{"myhost.com/foo/bar", "myhost.com/foo/bar"},
|
{"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", "docker.io/library/ubuntu"},
|
||||||
{"ubuntu:18.04", "docker.io/library/ubuntu:18.04"},
|
{"ubuntu:18.04", "docker.io/library/ubuntu:18.04"},
|
||||||
{"cibuilds/hugo:0.53", "docker.io/cibuilds/hugo:0.53"},
|
{"cibuilds/hugo:0.53", "docker.io/cibuilds/hugo:0.53"},
|
||||||
|
|
Loading…
Reference in a new issue