Skip to content

Commit

Permalink
Make more meaningful use of media types
Browse files Browse the repository at this point in the history
This ensures `artifactType` corresponds to type of contained artifact
and not config type
  • Loading branch information
errordeveloper committed Sep 18, 2023
1 parent ac736f6 commit f831da4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
30 changes: 20 additions & 10 deletions oci/artefact.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
config := mutate.Annotations(
mutate.ConfigMediaType(
mutate.MediaType(empty.Image, typesv1.OCIManifestSchema1),
ConfigMediaType,
ContentMediaType,
),
configAnnotations,
).(v1.Image)
Expand Down Expand Up @@ -222,7 +222,7 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
attest := mutate.Annotations(
mutate.ConfigMediaType(
mutate.MediaType(empty.Image, typesv1.OCIManifestSchema1),
ConfigMediaType,
AttestMediaType,
),
attestAnnotations,
).(v1.Image)
Expand All @@ -237,24 +237,34 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
)
}

digest, err := index.Digest()
// create root index that has platform selector
root := mutate.AppendManifests(mutate.Annotations(
empty.Index,
indexAnnotations,
).(v1.ImageIndex), mutate.IndexAddendum{
Descriptor: v1.Descriptor{
Platform: platform(),
},
Add: index,
})

digest, err := root.Digest()
if err != nil {
return "", fmt.Errorf("parsing index digest failed: %w", err)
}

if err := remote.WriteIndex(tag, index, crane.GetOptions(c.artefactPushOptions(ctx)...).Remote...); err != nil {
if err := remote.WriteIndex(tag, root, crane.GetOptions(c.withContext(ctx)...).Remote...); err != nil {
return "", fmt.Errorf("pushing index failed: %w", err)
}

return ref + "@" + digest.String(), err
}

func (c *Client) artefactPushOptions(ctx context.Context) []crane.Option {
return append(c.withContext(ctx),
crane.WithPlatform(&v1.Platform{
Architecture: "unknown",
OS: "unknown",
}))
func platform() *v1.Platform {
return &v1.Platform{
Architecture: "unknown",
OS: "unknown",
}
}

// based on https://github.com/fluxcd/pkg/blob/2a323d771e17af02dee2ccbbb9b445b78ab048e5/oci/client/build.go
Expand Down
10 changes: 9 additions & 1 deletion tape/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,22 @@ func Run() int {
},
{
name: "package",
short: "Create a package",
short: "Package an artefact",
long: []string{
"This command process manifests from the given dir and packages them as an artefact",
},
options: &TapePackageCommand{
tape: tape,
InputManifestDirOptions: InputManifestDirOptions{}},
},
{
name: "pull",
short: "Pull an artefact",
options: &TapePullCommand{
tape: tape,
OutputManifestDirOptions: OutputManifestDirOptions{},
},
},
}

for _, c := range commands {
Expand Down

0 comments on commit f831da4

Please sign in to comment.