From 13010c913ca09956f7b37f91aad4a9d4afd5dd65 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 9 Feb 2023 16:32:35 +0200 Subject: [PATCH] oci: Introduce Flux media types Signed-off-by: Stefan Prodan --- oci/client/push.go | 19 +++++++++++++++---- oci/constants.go | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/oci/client/push.go b/oci/client/push.go index 2dcf0e48..f45b162d 100644 --- a/oci/client/push.go +++ b/oci/client/push.go @@ -28,6 +28,10 @@ import ( gcrv1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/empty" "github.com/google/go-containerregistry/pkg/v1/mutate" + "github.com/google/go-containerregistry/pkg/v1/tarball" + "github.com/google/go-containerregistry/pkg/v1/types" + + "github.com/fluxcd/pkg/oci" ) // Push creates an artifact from the given directory, uploads the artifact @@ -50,14 +54,21 @@ func (c *Client) Push(ctx context.Context, url, sourceDir string, meta Metadata, return "", err } - img, err := crane.Append(empty.Image, tmpFile) + ct := time.Now() + meta.Created = ct.Format(time.RFC3339) + + img := mutate.MediaType(empty.Image, types.OCIManifestSchema1) + img = mutate.ConfigMediaType(img, oci.ConfigMediaType) + img = mutate.Annotations(img, meta.ToAnnotations()).(gcrv1.Image) + + layer, err := tarball.LayerFromFile(tmpFile, tarball.WithMediaType(oci.ContentMediaType)) if err != nil { return "", fmt.Errorf("appeding content to artifact failed: %w", err) } - ct := time.Now() - meta.Created = ct.Format(time.RFC3339) - img = mutate.Annotations(img, meta.ToAnnotations()).(gcrv1.Image) + img, err = mutate.Append(img, mutate.Addendum{ + Layer: layer, + }) if err := crane.Push(img, url, c.optionsWithContext(ctx)...); err != nil { return "", fmt.Errorf("pushing artifact failed: %w", err) diff --git a/oci/constants.go b/oci/constants.go index a79fda72..b8f3bee1 100644 --- a/oci/constants.go +++ b/oci/constants.go @@ -37,6 +37,12 @@ const ( ) const ( + // ConfigMediaType is the OCI media type for the config layer. + ConfigMediaType = "application/vnd.cncf.flux.config.v1+json" + + // ContentMediaType is the OCI media type for the content layer. + ContentMediaType = "application/vnd.cncf.flux.content.v1.tar+gzip" + // SourceAnnotation is the OpenContainers annotation for specifying // the upstream source of an OCI artifact. SourceAnnotation = "org.opencontainers.image.source"