Skip to content

Commit

Permalink
adding support for --bundle-dir -b to start, restore, and spec; fixes…
Browse files Browse the repository at this point in the history
… issue #310

Signed-off-by: Mike Brown <[email protected]>
  • Loading branch information
mikebrow committed Oct 27, 2015
1 parent db21ac7 commit 2f6b109
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 40 deletions.
18 changes: 10 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
)

const (
version = "0.3"
usage = `Open Container Initiative runtime
version = "0.3"
specConfig = "config.json"
runtimeConfig = "runtime.json"
usage = `Open Container Initiative runtime
runc is a command line client for running applications packaged according to
the Open Container Format (OCF) and is a compliant implementation of the
Open Container Initiative specification.
Expand All @@ -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
direct child of the process supervisor.
After creating config files for your root filesystem with runc, you can execute a
container in your shell by running:
After creating config files for your root filesystem with runc, you can execute
a container in your shell by running:
# cd /mycontainer
# runc start [ -c spec-config-file ] [ -r runtime-config-file ]
# runc start [ -b bundle-dir ]
If not specified, the default value for the 'spec-config-file' is 'config.json',
and the default value for the 'runtime-config-file' is 'runtime.json'.`
If not specified, the default value for the 'bundle-dir' is './'. 'Bundle-dir'
is the location where '` + specConfig + `' and '` + runtimeConfig + `' must be located.`
)

func main() {
Expand Down
19 changes: 10 additions & 9 deletions restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,23 @@ var restoreCommand = cli.Command{
Usage: "cgroups mode: 'soft' (default), 'full' and 'strict'.",
},
cli.StringFlag{
Name: "config-file, c",
Value: "config.json",
Usage: "path to spec file for writing",
},
cli.StringFlag{
Name: "runtime-file, r",
Value: "runtime.json",
Usage: "path for runtime file for writing",
Name: "bundle-dir, b",
Value: "./",
Usage: "path to the root of the bundle directory",
},
},
Action: func(context *cli.Context) {
imagePath := context.String("image-path")
if imagePath == "" {
imagePath = getDefaultImagePath(context)
}
spec, rspec, err := loadSpec(context.String("config-file"), context.String("runtime-file"))
bundleDir := context.String("bundle-dir")
if bundleDir != "./" {
if err := os.Chdir(bundleDir); err != nil {
fatal(err)
}
}
spec, rspec, err := loadSpec(specConfig, runtimeConfig)
if err != nil {
fatal(err)
}
Expand Down
27 changes: 13 additions & 14 deletions spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ var specCommand = cli.Command{
Usage: "create a new specification file",
Flags: []cli.Flag{
cli.StringFlag{
Name: "config-file, c",
Value: "config.json",
Usage: "path to spec config file for writing",
},
cli.StringFlag{
Name: "runtime-file, r",
Value: "runtime.json",
Usage: "path to runtime config file for writing",
Name: "bundle-dir, b",
Value: "./",
Usage: "path to the root of the bundle directory",
},
},
Action: func(context *cli.Context) {
Expand Down Expand Up @@ -247,26 +242,30 @@ var specCommand = cli.Command{
}
return nil
}
cName := context.String("config-file")
rName := context.String("runtime-file")
if err := checkNoFile(cName); err != nil {
bundleDir := context.String("bundle-dir")
if bundleDir != "./" {
if err := os.Chdir(bundleDir); err != nil {
fatal(err)
}
}
if err := checkNoFile(specConfig); err != nil {
logrus.Fatal(err)
}
if err := checkNoFile(rName); err != nil {
if err := checkNoFile(runtimeConfig); err != nil {
logrus.Fatal(err)
}
data, err := json.MarshalIndent(&spec, "", "\t")
if err != nil {
logrus.Fatal(err)
}
if err := ioutil.WriteFile(cName, data, 0666); err != nil {
if err := ioutil.WriteFile(specConfig, data, 0666); err != nil {
logrus.Fatal(err)
}
rdata, err := json.MarshalIndent(&rspec, "", "\t")
if err != nil {
logrus.Fatal(err)
}
if err := ioutil.WriteFile(rName, rdata, 0666); err != nil {
if err := ioutil.WriteFile(runtimeConfig, rdata, 0666); err != nil {
logrus.Fatal(err)
}
},
Expand Down
19 changes: 10 additions & 9 deletions start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ var startCommand = cli.Command{
Usage: "create and run a container",
Flags: []cli.Flag{
cli.StringFlag{
Name: "config-file, c",
Value: "config.json",
Usage: "path to spec config file",
},
cli.StringFlag{
Name: "runtime-file, r",
Value: "runtime.json",
Usage: "path to runtime config file",
Name: "bundle-dir, b",
Value: "./",
Usage: "path to the root of the bundle directory",
},
},
Action: func(context *cli.Context) {
spec, rspec, err := loadSpec(context.String("config-file"), context.String("runtime-file"))
bundleDir := context.String("bundle-dir")
if bundleDir != "./" {
if err := os.Chdir(bundleDir); err != nil {
fatal(err)
}
}
spec, rspec, err := loadSpec(specConfig, runtimeConfig)
if err != nil {
fatal(err)
}
Expand Down

0 comments on commit 2f6b109

Please sign in to comment.