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:
@@ -19,9 +19,7 @@ package run
|
||||
import (
|
||||
gocontext "context"
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/console"
|
||||
@@ -37,17 +35,6 @@ import (
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func loadSpec(path string, s *specs.Spec) error {
|
||||
raw, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return errors.New("cannot load spec config file")
|
||||
}
|
||||
if err := json.Unmarshal(raw, s); err != nil {
|
||||
return errors.Errorf("decoding spec config file failed, current supported OCI runtime-spec : v%s", specs.Version)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withMounts(context *cli.Context) oci.SpecOpts {
|
||||
return func(ctx gocontext.Context, client oci.Client, container *containers.Container, s *specs.Spec) error {
|
||||
mounts := make([]specs.Mount, 0)
|
||||
|
Reference in New Issue
Block a user