diff --git a/pkg/mutate/image.go b/pkg/mutate/image.go index 0305e39..3f2b048 100644 --- a/pkg/mutate/image.go +++ b/pkg/mutate/image.go @@ -17,11 +17,12 @@ import ( ) type image struct { - base v1.Image - overrides []v1.Layer - history *v1.History - configFileOverride any - configTypeOverride types.MediaType + base v1.Image + overrides []v1.Layer + history *v1.History + configFileOverride any + configTypeOverride types.MediaType + artifactTypeOverride string computed bool diffIDs []v1.Hash @@ -86,6 +87,7 @@ func (img *image) populate() error { configFile := img.configFileOverride configType := img.configTypeOverride + artifactType := img.artifactTypeOverride // If configFile is not overridden, populate from the base image. if configFile == nil { @@ -151,6 +153,10 @@ func (img *image) populate() error { manifest.Config.Data = config } + if artifactType != "" { + manifest.Config.ArtifactType = artifactType + } + img.computed = true img.diffIDs = diffIDs img.byDiffID = byDiffID diff --git a/pkg/mutate/mutate.go b/pkg/mutate/mutate.go index 0e1f66e..42b4ca0 100644 --- a/pkg/mutate/mutate.go +++ b/pkg/mutate/mutate.go @@ -79,6 +79,14 @@ func SetConfig(configFile any, configType types.MediaType) Mutation { } } +// SetArtifactType replaces the artifact type with the specified value. +func SetArtifactType(artifactType string) Mutation { + return func(img *image) error { + img.artifactTypeOverride = artifactType + return nil + } +} + // Apply performs the specified mutation(s) to a base image, returning the resulting image. func Apply(base v1.Image, ms ...Mutation) (v1.Image, error) { if len(ms) == 0 { diff --git a/pkg/mutate/mutate_test.go b/pkg/mutate/mutate_test.go index 45c7206..99183de 100644 --- a/pkg/mutate/mutate_test.go +++ b/pkg/mutate/mutate_test.go @@ -71,6 +71,21 @@ func TestApply(t *testing.T) { SetConfig(&v1.ConfigFile{Author: "Author"}, types.DockerConfigJSON), }, }, + { + name: "SetConfigEmpty", + base: img, + ms: []Mutation{ + SetConfig(struct{}{}, "application/vnd.oci.empty.v1+json"), + }, + }, + { + name: "SetArtifactType", + base: img, + ms: []Mutation{ + SetConfig(struct{}{}, "application/vnd.oci.empty.v1+json"), + SetArtifactType("application/vnd.sylabs.container"), + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/mutate/testdata/TestApply/SetArtifactType/config.golden b/pkg/mutate/testdata/TestApply/SetArtifactType/config.golden new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/pkg/mutate/testdata/TestApply/SetArtifactType/config.golden @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/pkg/mutate/testdata/TestApply/SetArtifactType/manifest.golden b/pkg/mutate/testdata/TestApply/SetArtifactType/manifest.golden new file mode 100644 index 0000000..c12cfb7 --- /dev/null +++ b/pkg/mutate/testdata/TestApply/SetArtifactType/manifest.golden @@ -0,0 +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"}]} \ No newline at end of file diff --git a/pkg/mutate/testdata/TestApply/SetConfigEmpty/config.golden b/pkg/mutate/testdata/TestApply/SetConfigEmpty/config.golden new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/pkg/mutate/testdata/TestApply/SetConfigEmpty/config.golden @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/pkg/mutate/testdata/TestApply/SetConfigEmpty/manifest.golden b/pkg/mutate/testdata/TestApply/SetConfigEmpty/manifest.golden new file mode 100644 index 0000000..54b0d97 --- /dev/null +++ b/pkg/mutate/testdata/TestApply/SetConfigEmpty/manifest.golden @@ -0,0 +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"}]} \ No newline at end of file