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

@@ -18,6 +18,8 @@ package oci
import (
"context"
"encoding/json"
"os"
"path/filepath"
"runtime"
@@ -46,6 +48,22 @@ var (
// to be created without the "issues" with go vendoring and package imports
type Spec = specs.Spec
const ConfigFilename = "config.json"
// ReadSpec deserializes JSON into an OCI runtime Spec from a given path.
func ReadSpec(path string) (*Spec, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
var s Spec
if err := json.NewDecoder(f).Decode(&s); err != nil {
return nil, err
}
return &s, nil
}
// GenerateSpec will generate a default spec from the provided image
// for use as a containerd container
func GenerateSpec(ctx context.Context, client Client, c *containers.Container, opts ...SpecOpts) (*Spec, error) {