Skip to content

Commit 2c6bb39

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 4609271 commit 2c6bb39

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

pkg/machine/ocipull/ociartifact.go

Lines changed: 19 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,25 @@ 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+
// Automatically append the current version as a tag if endpoint has no tag.
96+
// This allows endpoints in containers.conf to be version-agnostic: they won't need to be
97+
// updated on each version bump, while still pulling the correct version-specific image.
98+
if image, ok := strings.CutPrefix(endpoint, "docker://"); ok {
99+
ref, err := reference.ParseNormalizedNamed(image)
100+
if err == nil {
101+
// Only add version tag if no tag is specified (digest-only refs are left alone)
102+
if _, hasTag := ref.(reference.Tagged); !hasTag {
103+
taggedRef, err := reference.WithTag(ref, artifactVersion.majorMinor())
104+
if err != nil {
105+
return nil, fmt.Errorf("failed to add version tag to %q: %w", endpoint, err)
106+
}
107+
endpoint = "docker://" + taggedRef.String()
108+
}
109+
}
110+
// If parsing failed, just continue with the original endpoint
98111
}
99112

100113
ociDisk := OCIArtifactDisk{

0 commit comments

Comments
 (0)