Cleanup example usage and defaults
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
df79231bdf
commit
49710435b7
1 changed files with 54 additions and 50 deletions
100
example/main.go
100
example/main.go
|
@ -13,19 +13,21 @@ import (
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var RWM = "rwm"
|
// this demos how the graph/layer subsystem will create the rootfs and
|
||||||
|
// provide it to the container, the Mount type ties the execution and
|
||||||
// "Hooks do optional work. Drivers do mandatory work"
|
// filesystem layers together
|
||||||
func main() {
|
func getContainerRootfs() containerkit.Mount {
|
||||||
if err := osutils.SetSubreaper(1); err != nil {
|
return containerkit.Mount{
|
||||||
logrus.Fatal(err)
|
Type: "bind",
|
||||||
}
|
Source: "/containers/redis/rootfs",
|
||||||
if err := runTest(); err != nil {
|
Options: []string{
|
||||||
logrus.Fatal(err)
|
"rbind",
|
||||||
|
"rw",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTest() error {
|
func runContainer() error {
|
||||||
// create a new runc runtime that implements the ExecutionDriver interface
|
// create a new runc runtime that implements the ExecutionDriver interface
|
||||||
driver, err := runc.New("/run/runc", "/tmp/runc")
|
driver, err := runc.New("/run/runc", "/tmp/runc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -35,14 +37,7 @@ func runTest() error {
|
||||||
container, err := containerkit.NewContainer(
|
container, err := containerkit.NewContainer(
|
||||||
"/var/lib/containerkit", /* container root */
|
"/var/lib/containerkit", /* container root */
|
||||||
"test", /* container id */
|
"test", /* container id */
|
||||||
containerkit.Mount{
|
getContainerRootfs(), /* mount from the graph subsystem for the container */
|
||||||
Type: "bind",
|
|
||||||
Source: "/containers/redis/rootfs",
|
|
||||||
Options: []string{
|
|
||||||
"rbind",
|
|
||||||
"rw",
|
|
||||||
},
|
|
||||||
}, /* mount from the graph subsystem for the container */
|
|
||||||
spec("test"), /* the spec for the container */
|
spec("test"), /* the spec for the container */
|
||||||
driver, /* the exec driver to use for the container */
|
driver, /* the exec driver to use for the container */
|
||||||
)
|
)
|
||||||
|
@ -66,36 +61,27 @@ func runTest() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start 10 exec processes giving the go var i to exec to stdout
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
process, err := container.NewProcess(&specs.Process{
|
process, err := container.NewProcess(&specs.Process{
|
||||||
Args: []string{
|
Args: []string{
|
||||||
"echo", fmt.Sprintf("sup from itteration %d", i),
|
"echo", fmt.Sprintf("sup from itteration %d", i),
|
||||||
},
|
},
|
||||||
Env: []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"},
|
Env: env,
|
||||||
Terminal: false,
|
Terminal: false,
|
||||||
Cwd: "/",
|
Cwd: "/",
|
||||||
NoNewPrivileges: true,
|
NoNewPrivileges: true,
|
||||||
Capabilities: []string{
|
Capabilities: caps,
|
||||||
"CAP_AUDIT_WRITE",
|
|
||||||
"CAP_KILL",
|
|
||||||
"CAP_FOWNER",
|
|
||||||
"CAP_CHOWN",
|
|
||||||
"CAP_MKNOD",
|
|
||||||
"CAP_FSETID",
|
|
||||||
"CAP_DAC_OVERRIDE",
|
|
||||||
"CAP_SETFCAP",
|
|
||||||
"CAP_SETPCAP",
|
|
||||||
"CAP_SETGID",
|
|
||||||
"CAP_SETUID",
|
|
||||||
"CAP_NET_BIND_SERVICE",
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
process.Stdin = os.Stdin
|
process.Stdin = os.Stdin
|
||||||
process.Stdout = os.Stdout
|
process.Stdout = os.Stdout
|
||||||
process.Stderr = os.Stderr
|
process.Stderr = os.Stderr
|
||||||
|
|
||||||
if err := process.Start(); err != nil {
|
if err := process.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
procStatus, err := process.Wait()
|
procStatus, err := process.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -119,6 +105,37 @@ func runTest() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "Hooks do optional work. Drivers do mandatory work"
|
||||||
|
func main() {
|
||||||
|
if err := osutils.SetSubreaper(1); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := runContainer(); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
RWM = "rwm"
|
||||||
|
caps = []string{
|
||||||
|
"CAP_AUDIT_WRITE",
|
||||||
|
"CAP_KILL",
|
||||||
|
"CAP_FOWNER",
|
||||||
|
"CAP_CHOWN",
|
||||||
|
"CAP_MKNOD",
|
||||||
|
"CAP_FSETID",
|
||||||
|
"CAP_DAC_OVERRIDE",
|
||||||
|
"CAP_SETFCAP",
|
||||||
|
"CAP_SETPCAP",
|
||||||
|
"CAP_SETGID",
|
||||||
|
"CAP_SETUID",
|
||||||
|
"CAP_NET_BIND_SERVICE",
|
||||||
|
}
|
||||||
|
env = []string{
|
||||||
|
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// bla bla bla spec stuff
|
// bla bla bla spec stuff
|
||||||
func spec(id string) *specs.Spec {
|
func spec(id string) *specs.Spec {
|
||||||
cgpath := filepath.Join("/containerkit", id)
|
cgpath := filepath.Join("/containerkit", id)
|
||||||
|
@ -133,25 +150,12 @@ func spec(id string) *specs.Spec {
|
||||||
Readonly: false,
|
Readonly: false,
|
||||||
},
|
},
|
||||||
Process: specs.Process{
|
Process: specs.Process{
|
||||||
Env: []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"},
|
Env: env,
|
||||||
Args: []string{"sleep", "10"},
|
Args: []string{"sleep", "10"},
|
||||||
Terminal: false,
|
Terminal: false,
|
||||||
Cwd: "/",
|
Cwd: "/",
|
||||||
NoNewPrivileges: true,
|
NoNewPrivileges: true,
|
||||||
Capabilities: []string{
|
Capabilities: caps,
|
||||||
"CAP_AUDIT_WRITE",
|
|
||||||
"CAP_KILL",
|
|
||||||
"CAP_FOWNER",
|
|
||||||
"CAP_CHOWN",
|
|
||||||
"CAP_MKNOD",
|
|
||||||
"CAP_FSETID",
|
|
||||||
"CAP_DAC_OVERRIDE",
|
|
||||||
"CAP_SETFCAP",
|
|
||||||
"CAP_SETPCAP",
|
|
||||||
"CAP_SETGID",
|
|
||||||
"CAP_SETUID",
|
|
||||||
"CAP_NET_BIND_SERVICE",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Hostname: "containerkit",
|
Hostname: "containerkit",
|
||||||
Mounts: []specs.Mount{
|
Mounts: []specs.Mount{
|
||||||
|
|
Loading…
Reference in a new issue