@@ -11,51 +11,48 @@ import (
1111 "github.com/opencontainers/runtime-tools/generate"
1212)
1313
14- // Runtime represents the basic requirement of a container runtime
15- type Runtime struct {
16- RuntimeCommand string
17- BundleDir string
18- ID string
14+ // Runc represents runtime runc
15+ type Runc struct {
16+ Runtime
1917}
2018
21- // NewRuntime create a runtime by command and the bundle directory
22- func NewRuntime (runtimeCommand string , bundleDir string ) (Runtime , error ) {
23- var r Runtime
19+ // NewRunc creates a Runc runtime
20+ func NewRunc (runtimeCommand string , bundleDir string ) (* Runc , error ) {
2421 var err error
22+ r := & Runc {}
2523 r .RuntimeCommand , err = exec .LookPath (runtimeCommand )
2624 if err != nil {
27- return Runtime {} , err
25+ return r , err
2826 }
29-
3027 r .BundleDir = bundleDir
28+
3129 return r , err
3230}
3331
3432// SetConfig creates a 'config.json' by the generator
35- func (r * Runtime ) SetConfig (g * generate.Generator ) error {
33+ func (r * Runc ) SetConfig (g * generate.Generator ) error {
3634 if r .BundleDir == "" {
3735 return errors .New ("Please set the bundle directory first" )
3836 }
3937 return g .SaveToFile (filepath .Join (r .BundleDir , "config.json" ), generate.ExportOptions {})
4038}
4139
4240// SetID sets the container ID
43- func (r * Runtime ) SetID (id string ) {
41+ func (r * Runc ) SetID (id string ) {
4442 r .ID = id
4543}
4644
4745// Create a container
48- func (r * Runtime ) Create () error {
46+ func (r * Runc ) Create () error {
4947 var args []string
5048 args = append (args , "create" )
49+ if r .BundleDir != "" {
50+ args = append (args , "--bundle=" + r .BundleDir )
51+ }
5152 if r .ID != "" {
5253 args = append (args , r .ID )
5354 }
5455
55- // TODO: following the spec, we need define the bundle, but 'runc' does not..
56- // if r.BundleDir != "" {
57- // args = append(args, r.BundleDir)
58- // }
5956 cmd := exec .Command (r .RuntimeCommand , args ... )
6057 cmd .Dir = r .BundleDir
6158 cmd .Stdin = os .Stdin
@@ -65,7 +62,7 @@ func (r *Runtime) Create() error {
6562}
6663
6764// Start a container
68- func (r * Runtime ) Start () error {
65+ func (r * Runc ) Start () error {
6966 var args []string
7067 args = append (args , "start" )
7168 if r .ID != "" {
@@ -80,7 +77,7 @@ func (r *Runtime) Start() error {
8077}
8178
8279// State a container information
83- func (r * Runtime ) State () (rspecs.State , error ) {
80+ func (r * Runc ) State () (rspecs.State , error ) {
8481 var args []string
8582 args = append (args , "state" )
8683 if r .ID != "" {
@@ -98,7 +95,7 @@ func (r *Runtime) State() (rspecs.State, error) {
9895}
9996
10097// Delete a container
101- func (r * Runtime ) Delete () error {
98+ func (r * Runc ) Delete () error {
10299 var args []string
103100 args = append (args , "delete" )
104101 if r .ID != "" {
@@ -110,7 +107,7 @@ func (r *Runtime) Delete() error {
110107}
111108
112109// Clean deletes the container and removes the bundle file according to the input parameter
113- func (r * Runtime ) Clean (removeBundle bool ) error {
110+ func (r * Runc ) Clean (removeBundle bool ) error {
114111 err := r .Delete ()
115112 if err != nil {
116113 return err
0 commit comments