oci: introduce WithSpecFromFile combinator
We introduce a WithSpecFromFile option combinator to allow creation simpler creation of OCI specs from a file name. Often used as the first option in a `SpecOpts` slice, it simplifies choosing between a local file and the built-in default. The code in `ctr run` has been updated to use the new option, with out changing the order of operations or functionality present there. Signed-off-by: Stephen Day <stephen.day@getcruise.com>
This commit is contained in:
@@ -197,11 +197,10 @@ func WithNewSpec(opts ...oci.SpecOpts) NewContainerOpts {
|
||||
// WithSpec sets the provided spec on the container
|
||||
func WithSpec(s *oci.Spec, opts ...oci.SpecOpts) NewContainerOpts {
|
||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||
for _, o := range opts {
|
||||
if err := o(ctx, client, c, s); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := oci.ApplyOpts(ctx, client, c, s, opts...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var err error
|
||||
c.Spec, err = typeurl.MarshalAny(s)
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user