Merge pull request #373 from mikebrow/bundle-dir-310

adding support for --bundle
This commit is contained in:
Mrunal Patel 2015-11-16 12:07:01 -08:00
commit b28ec60b0e
4 changed files with 45 additions and 42 deletions

18
main.go
View File

@ -9,9 +9,11 @@ import (
) )
const ( const (
version = "0.3" version = "0.3"
usage = `Open Container Initiative runtime specConfig = "config.json"
runtimeConfig = "runtime.json"
usage = `Open Container Initiative runtime
runc is a command line client for running applications packaged according to runc is a command line client for running applications packaged according to
the Open Container Format (OCF) and is a compliant implementation of the the Open Container Format (OCF) and is a compliant implementation of the
Open Container Initiative specification. Open Container Initiative specification.
@ -21,14 +23,14 @@ container runtime environment for applications. It can be used with your
existing process monitoring tools and the container will be spawned as a existing process monitoring tools and the container will be spawned as a
direct child of the process supervisor. direct child of the process supervisor.
After creating config files for your root filesystem with runc, you can execute a After creating config files for your root filesystem with runc, you can execute
container in your shell by running: a container in your shell by running:
# cd /mycontainer # cd /mycontainer
# runc start [ -c spec-config-file ] [ -r runtime-config-file ] # runc start [ -b bundle ]
If not specified, the default value for the 'spec-config-file' is 'config.json', If not specified, the default value for the 'bundle' is the current directory.
and the default value for the 'runtime-config-file' is 'runtime.json'.` 'Bundle' is the directory where '` + specConfig + `' and '` + runtimeConfig + `' must be located.`
) )
func main() { func main() {

View File

@ -50,14 +50,9 @@ var restoreCommand = cli.Command{
Usage: "cgroups mode: 'soft' (default), 'full' and 'strict'.", Usage: "cgroups mode: 'soft' (default), 'full' and 'strict'.",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "config-file, c", Name: "bundle, b",
Value: "config.json", Value: "",
Usage: "path to spec file for writing", Usage: "path to the root of the bundle directory",
},
cli.StringFlag{
Name: "runtime-file, r",
Value: "runtime.json",
Usage: "path for runtime file for writing",
}, },
}, },
Action: func(context *cli.Context) { Action: func(context *cli.Context) {
@ -65,7 +60,13 @@ var restoreCommand = cli.Command{
if imagePath == "" { if imagePath == "" {
imagePath = getDefaultImagePath(context) imagePath = getDefaultImagePath(context)
} }
spec, rspec, err := loadSpec(context.String("config-file"), context.String("runtime-file")) bundle := context.String("bundle")
if bundle != "" {
if err := os.Chdir(bundle); err != nil {
fatal(err)
}
}
spec, rspec, err := loadSpec(specConfig, runtimeConfig)
if err != nil { if err != nil {
fatal(err) fatal(err)
} }

31
spec.go
View File

@ -26,14 +26,9 @@ var specCommand = cli.Command{
Usage: "create a new specification file", Usage: "create a new specification file",
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "config-file, c", Name: "bundle, b",
Value: "config.json", Value: "",
Usage: "path to spec config file for writing", Usage: "path to the root of the bundle directory",
},
cli.StringFlag{
Name: "runtime-file, r",
Value: "runtime.json",
Usage: "path to runtime config file for writing",
}, },
}, },
Action: func(context *cli.Context) { Action: func(context *cli.Context) {
@ -247,26 +242,30 @@ var specCommand = cli.Command{
} }
return nil return nil
} }
cName := context.String("config-file") bundle := context.String("bundle")
rName := context.String("runtime-file") if bundle != "" {
if err := checkNoFile(cName); err != nil { if err := os.Chdir(bundle); err != nil {
fatal(err)
}
}
if err := checkNoFile(specConfig); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
if err := checkNoFile(rName); err != nil { if err := checkNoFile(runtimeConfig); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
data, err := json.MarshalIndent(&spec, "", "\t") data, err := json.MarshalIndent(&spec, "", "\t")
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
if err := ioutil.WriteFile(cName, data, 0666); err != nil { if err := ioutil.WriteFile(specConfig, data, 0666); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
rdata, err := json.MarshalIndent(&rspec, "", "\t") rdata, err := json.MarshalIndent(&rspec, "", "\t")
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
if err := ioutil.WriteFile(rName, rdata, 0666); err != nil { if err := ioutil.WriteFile(runtimeConfig, rdata, 0666); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
}, },
@ -297,7 +296,7 @@ func loadSpec(cPath, rPath string) (spec *specs.LinuxSpec, rspec *specs.LinuxRun
cf, err := os.Open(cPath) cf, err := os.Open(cPath)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil, nil, fmt.Errorf("JSON specification file at %s not found", cPath) return nil, nil, fmt.Errorf("JSON specification file %s not found", cPath)
} }
return spec, rspec, err return spec, rspec, err
} }
@ -306,7 +305,7 @@ func loadSpec(cPath, rPath string) (spec *specs.LinuxSpec, rspec *specs.LinuxRun
rf, err := os.Open(rPath) rf, err := os.Open(rPath)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil, nil, fmt.Errorf("JSON runtime config file at %s not found", rPath) return nil, nil, fmt.Errorf("JSON runtime config file %s not found", rPath)
} }
return spec, rspec, err return spec, rspec, err
} }

View File

@ -22,18 +22,19 @@ var startCommand = cli.Command{
Usage: "create and run a container", Usage: "create and run a container",
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "config-file, c", Name: "bundle, b",
Value: "config.json", Value: "",
Usage: "path to spec config file", Usage: "path to the root of the bundle directory",
},
cli.StringFlag{
Name: "runtime-file, r",
Value: "runtime.json",
Usage: "path to runtime config file",
}, },
}, },
Action: func(context *cli.Context) { Action: func(context *cli.Context) {
spec, rspec, err := loadSpec(context.String("config-file"), context.String("runtime-file")) bundle := context.String("bundle")
if bundle != "" {
if err := os.Chdir(bundle); err != nil {
fatal(err)
}
}
spec, rspec, err := loadSpec(specConfig, runtimeConfig)
if err != nil { if err != nil {
fatal(err) fatal(err)
} }