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:
Stephen Day
2018-07-19 12:38:00 -07:00
parent c8017d0275
commit 2a1bd7414b
9 changed files with 162 additions and 44 deletions

View File

@@ -76,12 +76,13 @@ func defaultNamespaces() []specs.LinuxNamespace {
}
}
func createDefaultSpec(ctx context.Context, id string) (*Spec, error) {
func populateDefaultSpec(ctx context.Context, s *Spec, id string) error {
ns, err := namespaces.NamespaceRequired(ctx)
if err != nil {
return nil, err
return err
}
s := &Spec{
*s = Spec{
Version: specs.Version,
Root: &specs.Root{
Path: defaultRootfsPath,
@@ -183,5 +184,5 @@ func createDefaultSpec(ctx context.Context, id string) (*Spec, error) {
Namespaces: defaultNamespaces(),
},
}
return s, nil
return nil
}