Skip to content

Commit 23e715e

Browse files
committed
add: override artifactType
Signed-off-by: Adrian Wobito <[email protected]>
1 parent d41f36e commit 23e715e

File tree

7 files changed

+38
-5
lines changed

7 files changed

+38
-5
lines changed

pkg/mutate/image.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ import (
1717
)
1818

1919
type image struct {
20-
base v1.Image
21-
overrides []v1.Layer
22-
history *v1.History
23-
configFileOverride any
24-
configTypeOverride types.MediaType
20+
base v1.Image
21+
overrides []v1.Layer
22+
history *v1.History
23+
configFileOverride any
24+
configTypeOverride types.MediaType
25+
artifactTypeOverride string
2526

2627
computed bool
2728
diffIDs []v1.Hash
@@ -86,6 +87,7 @@ func (img *image) populate() error {
8687

8788
configFile := img.configFileOverride
8889
configType := img.configTypeOverride
90+
artifactType := img.artifactTypeOverride
8991

9092
// If configFile is not overridden, populate from the base image.
9193
if configFile == nil {
@@ -151,6 +153,10 @@ func (img *image) populate() error {
151153
manifest.Config.Data = config
152154
}
153155

156+
if artifactType != "" {
157+
manifest.Config.ArtifactType = artifactType
158+
}
159+
154160
img.computed = true
155161
img.diffIDs = diffIDs
156162
img.byDiffID = byDiffID

pkg/mutate/mutate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ func SetConfig(configFile any, configType types.MediaType) Mutation {
7979
}
8080
}
8181

82+
// SetArtifactType replaces the artifact type with the specified value.
83+
func SetArtifactType(artifactType string) Mutation {
84+
return func(img *image) error {
85+
img.artifactTypeOverride = artifactType
86+
return nil
87+
}
88+
}
89+
8290
// Apply performs the specified mutation(s) to a base image, returning the resulting image.
8391
func Apply(base v1.Image, ms ...Mutation) (v1.Image, error) {
8492
if len(ms) == 0 {

pkg/mutate/mutate_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ func TestApply(t *testing.T) {
7171
SetConfig(&v1.ConfigFile{Author: "Author"}, types.DockerConfigJSON),
7272
},
7373
},
74+
{
75+
name: "SetConfigEmpty",
76+
base: img,
77+
ms: []Mutation{
78+
SetConfig(struct{}{}, "application/vnd.oci.empty.v1+json"),
79+
},
80+
},
81+
{
82+
name: "SetConfigArtifactType",
83+
base: img,
84+
ms: []Mutation{
85+
SetConfig(struct{}{}, "application/vnd.oci.empty.v1+json"),
86+
SetArtifactType("application/vnd.sylabs.container"),
87+
},
88+
},
7489
}
7590
for _, tt := range tests {
7691
t.Run(tt.name, func(t *testing.T) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"schemaVersion":2,"mediaType":"application/vnd.docker.distribution.manifest.v2+json","config":{"mediaType":"application/vnd.oci.empty.v1+json","size":2,"digest":"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a","artifactType":"application/vnd.sylabs.container"},"layers":[{"mediaType":"application/vnd.docker.image.rootfs.diff.tar.gzip","size":3208,"digest":"sha256:7050e35b49f5e348c4809f5eff915842962cb813f32062d3bbdd35c750dd7d01"}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"schemaVersion":2,"mediaType":"application/vnd.docker.distribution.manifest.v2+json","config":{"mediaType":"application/vnd.oci.empty.v1+json","size":2,"digest":"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"},"layers":[{"mediaType":"application/vnd.docker.image.rootfs.diff.tar.gzip","size":3208,"digest":"sha256:7050e35b49f5e348c4809f5eff915842962cb813f32062d3bbdd35c750dd7d01"}]}

0 commit comments

Comments
 (0)