Uncopypaste parsing of OCI Bundle spec file

Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
This commit is contained in:
Marat Radchenko
2023-07-11 13:44:15 +03:00
parent d5ec7286ae
commit 9e34b8b441
6 changed files with 48 additions and 34 deletions

View File

@@ -25,7 +25,8 @@ import (
"syscall"
"text/template"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/containerd/containerd/oci"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/urfave/cli"
)
@@ -37,7 +38,8 @@ var ociHook = cli.Command{
if err != nil {
return err
}
spec, err := loadSpec(state.Bundle)
specFile := filepath.Join(state.Bundle, oci.ConfigFilename)
spec, err := loadSpec(specFile)
if err != nil {
return err
}
@@ -56,14 +58,16 @@ var ociHook = cli.Command{
},
}
// hookSpec is a shallow version of [oci.Spec] containing only the
// fields we need for the hook. We use a shallow struct to reduce
// the overhead of unmarshaling.
type hookSpec struct {
Root struct {
Path string `json:"path"`
} `json:"root"`
// Root configures the container's root filesystem.
Root *specs.Root `json:"root,omitempty"`
}
func loadSpec(bundle string) (*hookSpec, error) {
f, err := os.Open(filepath.Join(bundle, "config.json"))
func loadSpec(path string) (*hookSpec, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}