Skip to content

Commit

Permalink
Merge branch 'main' into remove-GetInexpensiveContentVersionIdentity
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianburth authored Jul 31, 2024
2 parents 8ce90ed + 3d4c539 commit 195e460
Show file tree
Hide file tree
Showing 153 changed files with 5,643 additions and 987 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ The OCI and OCM support can be found in packages

## Installation

Install the latest release via [Homebrew](https://brew.sh), [Nix](https://nixos.org), [Docker](https://www.docker.com/)/[Podman](https://podman.io/) or directly from [GitHub Releases](https://github.com/open-component-model/ocm/releases).
Install the latest release from any of

- [Homebrew](https://brew.sh)
- [Nix](https://nixos.org)
- [AUR](https://aur.archlinux.org/packages/ocm-cli)
- [Docker](https://www.docker.com/)
- [Podman](https://podman.io/)
- [GitHub Releases](https://github.com/open-component-model/ocm/releases)

### Bash

Expand Down Expand Up @@ -86,6 +93,20 @@ nix profile list | grep ocm
ocm --help
```

### Install from AUR (Arch Linux User Repository)

git-url: https://aur.archlinux.org/ocm-cli.git
package-url: https://aur.archlinux.org/packages/ocm-cli

```
# if not using a helper util
git clone https://aur.archlinux.org/ocm-cli.git
cd ocm-cli
makepkg -i
```

[AUR Documentation](https://wiki.archlinux.org/title/Arch_User_Repository)

### Usage via Docker / Podman

```sh
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.0-dev
0.13.0-dev
7 changes: 7 additions & 0 deletions cmds/ocm/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/componentarchive"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/components"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/plugins"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/pubsub"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/references"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/resources"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/routingslips"
Expand All @@ -44,6 +45,7 @@ import (
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/hash"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/install"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/list"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/set"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/show"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/sign"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/transfer"
Expand All @@ -57,6 +59,7 @@ import (
topicocmaccessmethods "github.com/open-component-model/ocm/cmds/ocm/topics/ocm/accessmethods"
topicocmdownloaders "github.com/open-component-model/ocm/cmds/ocm/topics/ocm/downloadhandlers"
topicocmlabels "github.com/open-component-model/ocm/cmds/ocm/topics/ocm/labels"
topicocmpubsub "github.com/open-component-model/ocm/cmds/ocm/topics/ocm/pubsub"
topicocmrefs "github.com/open-component-model/ocm/cmds/ocm/topics/ocm/refs"
topicocmuploaders "github.com/open-component-model/ocm/cmds/ocm/topics/ocm/uploadhandlers"
topicbootstrap "github.com/open-component-model/ocm/cmds/ocm/topics/toi/bootstrapping"
Expand Down Expand Up @@ -222,6 +225,7 @@ func newCliCommand(opts *CLIOptions, mod ...func(clictx.Context, *cobra.Command)

cmd.AddCommand(check.NewCommand(opts.Context))
cmd.AddCommand(get.NewCommand(opts.Context))
cmd.AddCommand(set.NewCommand(opts.Context))
cmd.AddCommand(list.NewCommand(opts.Context))
cmd.AddCommand(create.NewCommand(opts.Context))
cmd.AddCommand(add.NewCommand(opts.Context))
Expand All @@ -246,6 +250,7 @@ func newCliCommand(opts *CLIOptions, mod ...func(clictx.Context, *cobra.Command)
cmd.AddCommand(cmdutils.HideCommand(plugins.NewCommand(opts.Context)))
cmd.AddCommand(cmdutils.HideCommand(action.NewCommand(opts.Context)))
cmd.AddCommand(cmdutils.HideCommand(routingslips.NewCommand(opts.Context)))
cmd.AddCommand(cmdutils.HideCommand(pubsub.NewCommand(opts.Context)))

cmd.AddCommand(cmdutils.OverviewCommand(cachecmds.NewCommand(opts.Context)))
cmd.AddCommand(cmdutils.OverviewCommand(ocicmds.NewCommand(opts.Context)))
Expand All @@ -268,6 +273,7 @@ func newCliCommand(opts *CLIOptions, mod ...func(clictx.Context, *cobra.Command)
cmd.AddCommand(topicocmuploaders.New(ctx))
cmd.AddCommand(topicocmdownloaders.New(ctx))
cmd.AddCommand(topicocmlabels.New(ctx))
cmd.AddCommand(topicocmpubsub.New(ctx))
cmd.AddCommand(attributes.New(ctx))
cmd.AddCommand(topicbootstrap.New(ctx, "toi-bootstrapping"))

Expand All @@ -280,6 +286,7 @@ func newCliCommand(opts *CLIOptions, mod ...func(clictx.Context, *cobra.Command)
help.AddCommand(topicocmuploaders.New(ctx))
help.AddCommand(topicocmdownloaders.New(ctx))
help.AddCommand(topicocmlabels.New(ctx))
help.AddCommand(topicocmpubsub.New(ctx))
help.AddCommand(attributes.New(ctx))
help.AddCommand(topicbootstrap.New(ctx, "toi-bootstrapping"))

Expand Down
3 changes: 2 additions & 1 deletion cmds/ocm/commands/common/options/formatoption/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func (o *Option) Usage() string {
o.setDefault()
s := `
The <code>--type</code> option accepts a file format for the
target archive to use. The following formats are supported:
target archive to use. It is only evaluated if the target
archive does not exist yet. The following formats are supported:
`
list := []string{}
for k := range accessobj.GetFormats() {
Expand Down
2 changes: 2 additions & 0 deletions cmds/ocm/commands/ocmcmds/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/components"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/ctf"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/plugins"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/pubsub"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/references"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/resourceconfig"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/resources"
Expand Down Expand Up @@ -38,6 +39,7 @@ func NewCommand(ctx clictx.Context) *cobra.Command {
cmd.AddCommand(versions.NewCommand(ctx))
cmd.AddCommand(plugins.NewCommand(ctx))
cmd.AddCommand(routingslips.NewCommand(ctx))
cmd.AddCommand(pubsub.NewCommand(ctx))

cmd.AddCommand(topicocmrefs.New(ctx))
cmd.AddCommand(topicocmaccessmethods.New(ctx))
Expand Down
39 changes: 39 additions & 0 deletions cmds/ocm/commands/ocmcmds/common/addhdlrs/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package addhdlrs

import (
"github.com/spf13/pflag"

"github.com/open-component-model/ocm/cmds/ocm/pkg/options"
"github.com/open-component-model/ocm/pkg/contexts/ocm"
)

type ResourceSpecHandlerBase struct {
options options.OptionSet
}

var _ options.Options = (*ResourceSpecHandlerBase)(nil)

func NewBase(opts ...options.Options) ResourceSpecHandlerBase {
return ResourceSpecHandlerBase{options: opts}
}

func (*ResourceSpecHandlerBase) RequireInputs() bool {
return false
}

func (h *ResourceSpecHandlerBase) WithCLIOptions(opts ...options.Options) ResourceSpecHandlerBase {
h.options = append(h.options, opts...)
return *h
}

func (h *ResourceSpecHandlerBase) GetOptions() options.OptionSet {
return h.options
}

func (h *ResourceSpecHandlerBase) AddFlags(opts *pflag.FlagSet) {
h.options.AddFlags(opts)
}

func (h *ResourceSpecHandlerBase) GetTargetOpts() []ocm.TargetOption {
return options.FindOptions[ocm.TargetOption](h.options)
}
30 changes: 27 additions & 3 deletions cmds/ocm/commands/ocmcmds/common/addhdlrs/comp/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (

type ResourceSpecHandler struct {
rschandler *rscs.ResourceSpecHandler
srchandler *srcs.ResourceSpecHandler
refhandler *refs.ResourceSpecHandler
version string
schema string
}
Expand All @@ -41,11 +43,26 @@ var (
)

func New(v string, schema string, opts ...ocm.ModificationOption) *ResourceSpecHandler {
return &ResourceSpecHandler{rschandler: rscs.New(opts...), version: v, schema: schema}
return &ResourceSpecHandler{
rschandler: rscs.New(opts...),
srchandler: srcs.New(),
refhandler: refs.New(),
version: v,
schema: schema,
}
}

func (h *ResourceSpecHandler) AddFlags(fs *pflag.FlagSet) {
h.rschandler.AddFlags(fs)
h.srchandler.AddFlags(fs)
h.refhandler.AddFlags(fs)
}

func (h *ResourceSpecHandler) WithCLIOptions(opts ...options.Options) *ResourceSpecHandler {
h.rschandler.WithCLIOptions(opts...)
h.srchandler.WithCLIOptions(opts...)
h.refhandler.WithCLIOptions(opts...)
return h
}

func (*ResourceSpecHandler) Key() string {
Expand Down Expand Up @@ -94,6 +111,13 @@ func (h *ResourceSpecHandler) Add(ctx clictx.Context, ictx inputs.Context, elem

cd := cv.GetDescriptor()

opts := h.srchandler.GetOptions()[0].(*addhdlrs.Options)
if !opts.Replace {
cd.Resources = nil
cd.Sources = nil
cd.References = nil
}

schema := h.schema
if r.Meta.ConfiguredVersion != "" {
schema = r.Meta.ConfiguredVersion
Expand All @@ -111,15 +135,15 @@ func (h *ResourceSpecHandler) Add(ctx clictx.Context, ictx inputs.Context, elem
cd.CreationTime = metav1.NewTimestampP()
}

err = handle(ctx, ictx, elem.Source(), cv, r.Sources, srcs.ResourceSpecHandler{})
err = handle(ctx, ictx, elem.Source(), cv, r.Sources, h.srchandler)
if err != nil {
return err
}
err = handle(ctx, ictx, elem.Source(), cv, r.Resources, h.rschandler)
if err != nil {
return err
}
err = handle(ctx, ictx, elem.Source(), cv, r.References, refs.ResourceSpecHandler{})
err = handle(ctx, ictx, elem.Source(), cv, r.References, h.refhandler)
if err != nil {
return err
}
Expand Down
46 changes: 46 additions & 0 deletions cmds/ocm/commands/ocmcmds/common/addhdlrs/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package addhdlrs

import (
"github.com/mandelsoft/goutils/generics"
"github.com/spf13/pflag"

"github.com/open-component-model/ocm/pkg/contexts/ocm"
)

type Options struct {
Replace bool
}

var _ ocm.ModificationOption = (*Options)(nil)

func (o *Options) AddFlags(fs *pflag.FlagSet) {
f := fs.Lookup("replace")
if f != nil {
if bp := generics.Cast[*bool](f.Value); bp != nil {
return
}
}
fs.BoolVarP(&o.Replace, "replace", "R", false, "replace existing elements")
}

func (o *Options) ApplyBlobModificationOption(opts *ocm.BlobModificationOptions) {
o.ApplyTargetOption(&opts.TargetOptions)
}

func (o *Options) ApplyModificationOption(opts *ocm.ModificationOptions) {
o.ApplyTargetOption(&opts.TargetOptions)
}

func (o *Options) ApplyTargetOption(opts *ocm.TargetOptions) {
if !o.Replace {
opts.TargetElement = ocm.AppendElement
}
}

func (o *Options) Description() string {
return `
The <code>--replace</code> option allows users to specify whether adding an
element with the same name and extra identity but different version as an
existing element append (false) or replace (true) the existing element.
`
}
28 changes: 20 additions & 8 deletions cmds/ocm/commands/ocmcmds/common/addhdlrs/refs/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/addhdlrs"
"github.com/open-component-model/ocm/cmds/ocm/pkg/options"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/contexts/ocm"
"github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc"
Expand All @@ -15,19 +16,30 @@ import (
"github.com/open-component-model/ocm/pkg/runtime"
)

type ResourceSpecHandler struct{}
type ResourceSpecHandler struct {
addhdlrs.ResourceSpecHandlerBase
}

var _ common.ResourceSpecHandler = (*ResourceSpecHandler)(nil)
var (
_ common.ResourceSpecHandler = (*ResourceSpecHandler)(nil)
_ options.Options = (*ResourceSpecHandler)(nil)
)

func (ResourceSpecHandler) Key() string {
func New(opts ...options.Options) *ResourceSpecHandler {
return &ResourceSpecHandler{addhdlrs.NewBase(opts...)}
}

func (*ResourceSpecHandler) Key() string {
return "reference"
}

func (ResourceSpecHandler) RequireInputs() bool {
return false
func (h *ResourceSpecHandler) WithCLIOptions(opts ...options.Options) *ResourceSpecHandler {
return &ResourceSpecHandler{
h.ResourceSpecHandlerBase.WithCLIOptions(opts...),
}
}

func (ResourceSpecHandler) Decode(data []byte) (addhdlrs.ElementSpec, error) {
func (*ResourceSpecHandler) Decode(data []byte) (addhdlrs.ElementSpec, error) {
var desc ResourceSpec
err := runtime.DefaultYAMLEncoding.Unmarshal(data, &desc)
if err != nil {
Expand All @@ -36,7 +48,7 @@ func (ResourceSpecHandler) Decode(data []byte) (addhdlrs.ElementSpec, error) {
return &desc, nil
}

func (ResourceSpecHandler) Set(v ocm.ComponentVersionAccess, r addhdlrs.Element, acc compdesc.AccessSpec) error {
func (h *ResourceSpecHandler) Set(v ocm.ComponentVersionAccess, r addhdlrs.Element, acc compdesc.AccessSpec) error {
spec, ok := r.Spec().(*ResourceSpec)
if !ok {
return fmt.Errorf("element spec is not a valid resource spec, failed to assert type %T to ResourceSpec", r.Spec())
Expand All @@ -54,7 +66,7 @@ func (ResourceSpecHandler) Set(v ocm.ComponentVersionAccess, r addhdlrs.Element,
},
ComponentName: spec.ComponentName,
}
return v.SetReference(meta)
return v.SetReference(meta, h.GetTargetOpts()...)
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
20 changes: 10 additions & 10 deletions cmds/ocm/commands/ocmcmds/common/addhdlrs/rscs/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/mandelsoft/goutils/errors"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/validation/field"

"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common"
Expand All @@ -24,8 +23,8 @@ const (
)

type ResourceSpecHandler struct {
options options.OptionSet
opts *ocm.ModificationOptions
addhdlrs.ResourceSpecHandlerBase
opts *ocm.ModificationOptions
}

var (
Expand All @@ -34,21 +33,22 @@ var (
)

func New(opts ...ocm.ModificationOption) *ResourceSpecHandler {
h := &ResourceSpecHandler{ResourceSpecHandlerBase: addhdlrs.NewBase(options.OptionSet{skipdigestoption.New()})}
if len(opts) > 0 {
return &ResourceSpecHandler{opts: ocm.NewModificationOptions(opts...)}
h.opts = ocm.NewModificationOptions(opts...)
}
return &ResourceSpecHandler{}
return h
}

func (h *ResourceSpecHandler) AddFlags(opts *pflag.FlagSet) {
if len(h.options) == 0 {
h.options = options.OptionSet{skipdigestoption.New()}
func (h *ResourceSpecHandler) WithCLIOptions(opts ...options.Options) *ResourceSpecHandler {
return &ResourceSpecHandler{
h.ResourceSpecHandlerBase.WithCLIOptions(opts...),
h.opts,
}
h.options.AddFlags(opts)
}

func (h *ResourceSpecHandler) getModOpts() []ocm.ModificationOption {
opts := options.FindOptions[ocm.ModificationOption](h.options)
opts := options.FindOptions[ocm.ModificationOption](h.GetOptions())
if h.opts != nil {
opts = append(opts, h.opts)
}
Expand Down
Loading

0 comments on commit 195e460

Please sign in to comment.