-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.go
More file actions
49 lines (42 loc) · 1.13 KB
/
Copy pathbundle.go
File metadata and controls
49 lines (42 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package gvisorexec
import (
"fmt"
"os"
"path/filepath"
)
// Bundle is an on-disk OCI bundle directory containing a config.json ready
// for runsc to run.
type Bundle struct {
// Dir is the absolute path to the bundle directory.
Dir string
// ID is the container ID runsc will use.
ID string
}
// NewBundle creates a fresh bundle in a new temp directory and writes the
// config.json derived from c. The caller owns the returned bundle and should
// call Cleanup when the container has exited.
func NewBundle(c Config) (*Bundle, error) {
spec, err := buildSpec(c)
if err != nil {
return nil, err
}
dir, err := os.MkdirTemp("", "gvisor-exec-*")
if err != nil {
return nil, fmt.Errorf("gvisorexec: create bundle dir: %w", err)
}
if err := os.WriteFile(filepath.Join(dir, "config.json"), spec, 0o600); err != nil {
_ = os.RemoveAll(dir)
return nil, fmt.Errorf("gvisorexec: write config.json: %w", err)
}
return &Bundle{
Dir: dir,
ID: "gve-" + filepath.Base(dir),
}, nil
}
// Cleanup removes the bundle directory.
func (b *Bundle) Cleanup() error {
if b == nil || b.Dir == "" {
return nil
}
return os.RemoveAll(b.Dir)
}