Skip to content

Commit

Permalink
feat: make OCI Manifest Version configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
thepabloaguilar committed Mar 27, 2024
1 parent e059af6 commit 43e989d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cmd/flipt/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"os"
"text/tabwriter"

"oras.land/oras-go/v2"

"github.com/spf13/cobra"
"go.flipt.io/flipt/internal/config"
"go.flipt.io/flipt/internal/containers"
Expand Down Expand Up @@ -166,6 +168,11 @@ func (c *bundleCommand) getStore() (*oci.Store, error) {
))
}

// The default is the 1.1 version, this is why we don't need to check it in here.
if cfg.ManifestVersion == config.OCIManifestVersion10 {
opts = append(opts, oci.WithManifestVersion(oras.PackManifestVersion1_0))
}

if cfg.BundlesDirectory != "" {
dir = cfg.BundlesDirectory
}
Expand Down
17 changes: 13 additions & 4 deletions internal/oci/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ type Store struct {
// This shouldn't be handled directory, instead use one of the function options
// e.g. WithBundleDir or WithCredentials
type StoreOptions struct {
bundleDir string
auth *struct {
bundleDir string
manifestVersion oras.PackManifestVersion
auth *struct {
username string
password string
}
Expand All @@ -69,11 +70,19 @@ func WithCredentials(user, pass string) containers.Option[StoreOptions] {
}
}

// WithManifestVersion configures what OCI Manifest version to build the bundle.
func WithManifestVersion(version oras.PackManifestVersion) containers.Option[StoreOptions] {
return func(s *StoreOptions) {
s.manifestVersion = version
}
}

// NewStore constructs and configures an instance of *Store for the provided config
func NewStore(logger *zap.Logger, dir string, opts ...containers.Option[StoreOptions]) (*Store, error) {
store := &Store{
opts: StoreOptions{
bundleDir: dir,
bundleDir: dir,
manifestVersion: oras.PackManifestVersion1_1,
},
logger: logger,
local: memory.New(),
Expand Down Expand Up @@ -365,7 +374,7 @@ func (s *Store) Build(ctx context.Context, src fs.FS, ref Reference) (Bundle, er
return Bundle{}, err
}

desc, err := oras.PackManifest(ctx, store, oras.PackManifestVersion1_1_RC4, MediaTypeFliptFeatures, oras.PackManifestOptions{
desc, err := oras.PackManifest(ctx, store, s.opts.manifestVersion, MediaTypeFliptFeatures, oras.PackManifestOptions{
ManifestAnnotations: map[string]string{},
Layers: layers,
})
Expand Down
7 changes: 7 additions & 0 deletions internal/storage/fs/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"strconv"

"oras.land/oras-go/v2"

"github.com/go-git/go-git/v5/plumbing/transport/http"
gitssh "github.com/go-git/go-git/v5/plumbing/transport/ssh"
"go.flipt.io/flipt/internal/config"
Expand Down Expand Up @@ -112,6 +114,11 @@ func NewStore(ctx context.Context, logger *zap.Logger, cfg *config.Config) (_ st
))
}

// The default is the 1.1 version, this is why we don't need to check it in here.
if cfg.Storage.OCI.ManifestVersion == config.OCIManifestVersion10 {
opts = append(opts, oci.WithManifestVersion(oras.PackManifestVersion1_0))
}

ocistore, err := oci.NewStore(logger, cfg.Storage.OCI.BundlesDirectory, opts...)
if err != nil {
return nil, err
Expand Down

0 comments on commit 43e989d

Please sign in to comment.