Skip to content

Commit 0f2cbae

Browse files
committed
Remove hardcoded refs from ociartifact code
Fixes: https://issues.redhat.com/browse/RUN-3578 Signed-off-by: Nicola Sella <[email protected]>
1 parent 23e6a89 commit 0f2cbae

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

pkg/machine/ocipull/ociartifact.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ import (
2424
)
2525

2626
const (
27-
artifactRegistry = "quay.io"
28-
artifactRepo = "podman"
29-
artifactImageName = "machine-os"
3027
artifactOriginalName = specV1.AnnotationTitle
3128
machineOS = "linux"
3229
)
@@ -92,9 +89,23 @@ func NewOCIArtifactPull(ctx context.Context, dirs *define.MachineDirs, endpoint
9289

9390
cache := false
9491
if endpoint == "" {
95-
imageName := artifactImageName
96-
endpoint = fmt.Sprintf("docker://%s/%s/%s:%s", artifactRegistry, artifactRepo, imageName, artifactVersion.majorMinor())
97-
cache = true
92+
return nil, fmt.Errorf("no machine image endpoint provided")
93+
}
94+
95+
// Strip docker:// prefix to parse the reference
96+
if strings.HasPrefix(endpoint, "docker://") {
97+
ref, err := reference.ParseNormalizedNamed(strings.TrimPrefix(endpoint, "docker://"))
98+
if err == nil {
99+
// Check if the reference has neither a tag nor a digest
100+
if _, hasTag := ref.(reference.Tagged); !hasTag {
101+
taggedRef, err := reference.WithTag(ref, artifactVersion.majorMinor())
102+
if err != nil {
103+
return nil, fmt.Errorf("failed to add version tag: %w", err)
104+
}
105+
endpoint = "docker://" + taggedRef.String()
106+
}
107+
}
108+
// If parsing failed, just continue with the original endpoint
98109
}
99110

100111
ociDisk := OCIArtifactDisk{

0 commit comments

Comments
 (0)