Skip to content

Commit

Permalink
oci: Introduce Flux media types
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
  • Loading branch information
stefanprodan committed Feb 13, 2023
1 parent 6c2b10b commit 13010c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 15 additions & 4 deletions oci/client/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions oci/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 13010c9

Please sign in to comment.