fix: use docker lib for image ref parsing (#877)

Signed-off-by: hackercat <me@hackerc.at>
This commit is contained in:
Ryan
2021-11-13 20:35:45 +01:00
committed by GitHub
parent 62d2167f3b
commit ec34eb9532
3 changed files with 10 additions and 8 deletions

View File

@@ -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()
}