Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: override artifactType #74

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pkg/mutate/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pkg/mutate/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions pkg/mutate/mutate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -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"}]}
1 change: 1 addition & 0 deletions pkg/mutate/testdata/TestApply/SetConfigEmpty/config.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -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"}]}
Loading