diff --git a/oci/client/push.go b/oci/client/push.go index 2dcf0e488..f45b162d0 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 a79fda72d..b8f3bee13 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"