Fix build because of imports in package

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2016-12-01 10:47:47 -08:00
parent 2ead05e6f1
commit c2a57e2b00
8 changed files with 26 additions and 398 deletions

View file

@ -1,140 +0,0 @@
package main
import (
"flag"
"fmt"
"io"
"os"
"strconv"
"github.com/Sirupsen/logrus"
"github.com/docker/containerkit"
"github.com/docker/containerkit/osutils"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
func reloadContainer() error {
dockerContainer := &testConfig{}
container, err := containerkit.LoadContainer(dockerContainer)
if err != nil {
return err
}
// wait for it to exit and get the exit status
logrus.Info("wait container")
status, err := container.Wait()
if err != nil {
return err
}
// delete the container after it is done
logrus.Info("delete container")
if container.Delete(); err != nil {
return err
}
logrus.Infof("exit status %d", status)
return nil
}
func runContainer() error {
// create a new runtime runtime that implements the ExecutionDriver interface
dockerContainer := &testConfig{}
// create a new container
container, err := containerkit.NewContainer(dockerContainer)
if err != nil {
return err
}
// setup some stdio for our container
container.Stdin = Stdin("")
container.Stdout = Stdout("")
container.Stderr = Stderr("")
// go ahead and set the container in the create state and have it ready to start
logrus.Info("create container")
if err := container.Create(); err != nil {
return err
}
// start the user defined process in the container
logrus.Info("start container")
if err := container.Start(); err != nil {
return err
}
for i := 0; i < exec; i++ {
process, err := container.NewProcess(&specs.Process{
Args: []string{
"sh", "-c",
"echo " + fmt.Sprintf("sup from itteration %d", i),
},
Env: env,
Terminal: false,
Cwd: "/",
NoNewPrivileges: true,
Capabilities: caps,
})
process.Stdin = Stdin(strconv.Itoa(i))
stdout := Stdout(strconv.Itoa(i))
stderr := Stderr(strconv.Itoa(i))
go io.Copy(os.Stdout, stdout)
go io.Copy(os.Stdout, stderr)
process.Stdout = stdout
process.Stderr = stderr
if err := process.Start(); err != nil {
return err
}
procStatus, err := process.Wait()
if err != nil {
return err
}
logrus.Infof("process %d returned with %d", i, procStatus)
}
if load {
return nil
}
// wait for it to exit and get the exit status
logrus.Info("wait container")
status, err := container.Wait()
if err != nil {
return err
}
// delete the container after it is done
logrus.Info("delete container")
if container.Delete(); err != nil {
return err
}
logrus.Infof("exit status %d", status)
return nil
}
var (
exec int
load bool
reload bool
)
// "Hooks do optional work. Drivers do mandatory work"
func main() {
flag.IntVar(&exec, "exec", 0, "run n number of execs")
flag.BoolVar(&load, "load", false, "reload the container")
flag.BoolVar(&reload, "reload", false, "reload the container live")
flag.Parse()
if err := osutils.SetSubreaper(1); err != nil {
logrus.Fatal(err)
}
if reload {
if err := reloadContainer(); err != nil {
logrus.Fatal(err)
}
return
}
if err := runContainer(); err != nil {
logrus.Fatal(err)
}
}

View file

@ -1,232 +0,0 @@
package main
import (
"os"
"path/filepath"
"runtime"
"syscall"
"time"
"golang.org/x/sys/unix"
"github.com/docker/containerkit"
"github.com/docker/containerkit/shim"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
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",
}
)
type testConfig struct {
}
func (t *testConfig) ID() string {
return "test"
}
func (t *testConfig) Root() string {
return "/var/lib/containerkit"
}
func (t *testConfig) Runtime() (containerkit.Runtime, error) {
return shim.New(shim.Opts{
Root: "/run/cshim/test",
Name: "containerd-shim",
RuntimeName: "runc",
RuntimeRoot: "/run/runc",
Timeout: 5 * time.Second,
})
// TODO: support loading of runtime
// create a new runtime runtime that implements the ExecutionDriver interface
return shim.Load("/run/cshim/test")
}
func (t *testConfig) Spec() (*specs.Spec, error) {
var (
cgpath = filepath.Join("/containerkit", t.ID())
m = &containerkit.Mount{
Target: "/",
Type: "bind",
Source: "/containers/redis/rootfs",
Options: []string{
"rbind",
"rw",
},
}
)
return &specs.Spec{
Version: specs.Version,
Platform: specs.Platform{
OS: runtime.GOOS,
Arch: runtime.GOARCH,
},
Root: specs.Root{
Path: "rootfs",
Readonly: false,
},
Process: specs.Process{
Env: env,
Args: []string{"sleep", "30"},
Terminal: false,
Cwd: "/",
NoNewPrivileges: true,
Capabilities: caps,
},
Hostname: "containerkit",
Mounts: []specs.Mount{
{
Destination: m.Target,
Type: m.Type,
Source: m.Source,
Options: m.Options,
},
{
Destination: "/proc",
Type: "proc",
Source: "proc",
},
{
Destination: "/dev",
Type: "tmpfs",
Source: "tmpfs",
Options: []string{"nosuid", "strictatime", "mode=755", "size=65536k"},
},
{
Destination: "/dev/pts",
Type: "devpts",
Source: "devpts",
Options: []string{"nosuid", "noexec", "newinstance", "ptmxmode=0666", "mode=0620", "gid=5"},
},
{
Destination: "/dev/shm",
Type: "tmpfs",
Source: "shm",
Options: []string{"nosuid", "noexec", "nodev", "mode=1777", "size=65536k"},
},
{
Destination: "/dev/mqueue",
Type: "mqueue",
Source: "mqueue",
Options: []string{"nosuid", "noexec", "nodev"},
},
{
Destination: "/sys",
Type: "sysfs",
Source: "sysfs",
Options: []string{"nosuid", "noexec", "nodev"},
},
{
Destination: "/run",
Type: "tmpfs",
Source: "tmpfs",
Options: []string{"nosuid", "strictatime", "mode=755", "size=65536k"},
},
{
Destination: "/etc/resolv.conf",
Type: "bind",
Source: "/etc/resolv.conf",
Options: []string{"rbind", "ro"},
},
{
Destination: "/etc/hosts",
Type: "bind",
Source: "/etc/hosts",
Options: []string{"rbind", "ro"},
},
{
Destination: "/etc/localtime",
Type: "bind",
Source: "/etc/localtime",
Options: []string{"rbind", "ro"},
},
},
Linux: &specs.Linux{
CgroupsPath: &cgpath,
Resources: &specs.LinuxResources{
Devices: []specs.LinuxDeviceCgroup{
{
Allow: false,
Access: &RWM,
},
},
},
Namespaces: []specs.LinuxNamespace{
{
Type: "pid",
},
{
Type: "ipc",
},
{
Type: "uts",
},
{
Type: "mount",
},
},
},
}, nil
}
func Stdin(n string) *os.File {
abs, err := filepath.Abs("stdin" + n)
if err != nil {
panic(err)
}
if err := unix.Mkfifo(abs, 0755); err != nil && !os.IsExist(err) {
panic(err)
}
f, err := os.OpenFile(abs, syscall.O_RDWR, 0)
if err != nil {
panic(err)
}
return f
}
func Stdout(n string) *os.File {
abs, err := filepath.Abs("stdout" + n)
if err != nil {
panic(err)
}
if err := unix.Mkfifo(abs, 0755); err != nil && !os.IsExist(err) {
panic(err)
}
f, err := os.OpenFile(abs, syscall.O_RDWR, 0)
if err != nil {
panic(err)
}
return f
}
func Stderr(n string) *os.File {
abs, err := filepath.Abs("stderr" + n)
if err != nil {
panic(err)
}
if err := unix.Mkfifo(abs, 0755); err != nil && !os.IsExist(err) {
panic(err)
}
f, err := os.OpenFile(abs, syscall.O_RDWR, 0)
if err != nil {
panic(err)
}
return f
}

View file

@ -6,7 +6,7 @@ import (
"syscall"
"github.com/Sirupsen/logrus"
"github.com/docker/containerkit/epoll"
"github.com/docker/containerd/sys"
)
type Monitorable interface {
@ -23,7 +23,7 @@ type Flusher interface {
// New returns a new process monitor that emits events whenever the
// state of the fd refering to a process changes
func New() (*Monitor, error) {
fd, err := epoll.EpollCreate1(0)
fd, err := sys.EpollCreate1(0)
if err != nil {
return nil, err
}
@ -55,7 +55,7 @@ func (m *Monitor) Add(ma Monitorable) error {
Fd: int32(fd),
Events: syscall.EPOLLHUP,
}
if err := epoll.EpollCtl(m.epollFd, syscall.EPOLL_CTL_ADD, fd, &event); err != nil {
if err := sys.EpollCtl(m.epollFd, syscall.EPOLL_CTL_ADD, fd, &event); err != nil {
return err
}
m.receivers[fd] = ma
@ -87,7 +87,7 @@ func (m *Monitor) Close() error {
func (m *Monitor) Run() {
var events [128]syscall.EpollEvent
for {
n, err := epoll.EpollWait(m.epollFd, events[:], -1)
n, err := sys.EpollWait(m.epollFd, events[:], -1)
if err != nil {
if err == syscall.EINTR {
continue

View file

@ -11,7 +11,7 @@ import (
"strconv"
"time"
"github.com/docker/containerkit"
"github.com/docker/containerd"
)
var ErrRootEmpty = errors.New("oci: runtime root cannot be an empty string")
@ -58,7 +58,7 @@ func (r *OCIRuntime) Root() string {
return r.root
}
func (r *OCIRuntime) Create(c *containerkit.Container) (containerkit.ProcessDelegate, error) {
func (r *OCIRuntime) Create(c *containerd.Container) (containerd.ProcessDelegate, error) {
pidFile := fmt.Sprintf("%s/%s.pid", filepath.Join(r.root, c.ID()), "init")
cmd := r.Command("create", "--pid-file", pidFile, "--bundle", c.Path(), c.ID())
cmd.Stdin, cmd.Stdout, cmd.Stderr = c.Stdin, c.Stdout, c.Stderr
@ -76,15 +76,15 @@ func (r *OCIRuntime) Create(c *containerkit.Container) (containerkit.ProcessDele
return newProcess(i)
}
func (r *OCIRuntime) Start(c *containerkit.Container) error {
func (r *OCIRuntime) Start(c *containerd.Container) error {
return r.Command("start", c.ID()).Run()
}
func (r *OCIRuntime) Delete(c *containerkit.Container) error {
func (r *OCIRuntime) Delete(c *containerd.Container) error {
return r.Command("delete", c.ID()).Run()
}
func (r *OCIRuntime) Exec(c *containerkit.Container, p *containerkit.Process) (containerkit.ProcessDelegate, error) {
func (r *OCIRuntime) Exec(c *containerd.Container, p *containerd.Process) (containerd.ProcessDelegate, error) {
f, err := ioutil.TempFile(filepath.Join(r.root, c.ID()), "process")
if err != nil {
return nil, err
@ -122,7 +122,7 @@ type state struct {
Annotations map[string]string `json:"annotations"`
}
func (r *OCIRuntime) Load(id string) (containerkit.ProcessDelegate, error) {
func (r *OCIRuntime) Load(id string) (containerd.ProcessDelegate, error) {
data, err := r.Command("state", id).Output()
if err != nil {
return nil, err

View file

@ -8,7 +8,7 @@ import (
"path/filepath"
"syscall"
"github.com/docker/containerkit/osutils"
"github.com/docker/containerd/sys"
"github.com/docker/docker/pkg/term"
)
@ -63,7 +63,7 @@ func start(log *os.File) error {
signals := make(chan os.Signal, 2048)
signal.Notify(signals)
// set the shim as the subreaper for all orphaned processes created by the container
if err := osutils.SetSubreaper(1); err != nil {
if err := sys.SetSubreaper(1); err != nil {
return err
}
// open the exit pipe
@ -106,7 +106,7 @@ func start(log *os.File) error {
case s := <-signals:
switch s {
case syscall.SIGCHLD:
exits, _ := osutils.Reap(false)
exits, _ := sys.Reap(false)
for _, e := range exits {
// check to see if runtime is one of the processes that has exited
if e.Pid == p.pid() {

View file

@ -16,7 +16,7 @@ import (
"time"
"github.com/Sirupsen/logrus"
"github.com/docker/containerkit"
"github.com/docker/containerd"
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/sys/unix"
)
@ -35,7 +35,7 @@ type processOpts struct {
root string
noPivotRoot bool
checkpoint string
c *containerkit.Container
c *containerd.Container
cmd *exec.Cmd
exec bool
spec specs.Process

View file

@ -12,9 +12,9 @@ import (
"syscall"
"time"
"github.com/docker/containerkit"
"github.com/docker/containerkit/monitor"
"github.com/docker/containerkit/oci"
"github.com/docker/containerd"
"github.com/docker/containerd/monitor"
"github.com/docker/containerd/oci"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
@ -204,7 +204,7 @@ func (s *Shim) UnmarshalJSON(b []byte) error {
return nil
}
func (s *Shim) Create(c *containerkit.Container) (containerkit.ProcessDelegate, error) {
func (s *Shim) Create(c *containerd.Container) (containerd.ProcessDelegate, error) {
s.bundle = c.Path()
var (
root = filepath.Join(s.root, "init")
@ -247,7 +247,7 @@ func (s *Shim) Create(c *containerkit.Container) (containerkit.ProcessDelegate,
return p, err
}
func (s *Shim) Start(c *containerkit.Container) error {
func (s *Shim) Start(c *containerd.Container) error {
p, err := s.getContainerInit()
if err != nil {
return err
@ -284,14 +284,14 @@ func (s *Shim) Start(c *containerkit.Container) error {
return nil
}
func (s *Shim) Delete(c *containerkit.Container) error {
func (s *Shim) Delete(c *containerd.Container) error {
if err := s.runtime.Delete(c); err != nil {
return err
}
return os.RemoveAll(s.root)
}
func (s *Shim) Exec(c *containerkit.Container, p *containerkit.Process) (containerkit.ProcessDelegate, error) {
func (s *Shim) Exec(c *containerd.Container, p *containerd.Process) (containerd.ProcessDelegate, error) {
root, err := ioutil.TempDir(s.root, "")
if err != nil {
return nil, err
@ -325,7 +325,7 @@ func (s *Shim) Exec(c *containerkit.Container, p *containerkit.Process) (contain
return sp, nil
}
func (s *Shim) Load(id string) (containerkit.ProcessDelegate, error) {
func (s *Shim) Load(id string) (containerd.ProcessDelegate, error) {
return s.getContainerInit()
}

View file

@ -8,7 +8,7 @@ import (
"path/filepath"
"strings"
"github.com/docker/containerkit"
"github.com/docker/containerd"
)
var (
@ -146,7 +146,7 @@ func NewManager(root string) (*Manager, error) {
//
// Once the writes have completed, Manager.Commit or
// Manager.Rollback should be called on dst.
func (lm *Manager) Prepare(dst, parent string) ([]containerkit.Mount, error) {
func (lm *Manager) Prepare(dst, parent string) ([]containerd.Mount, error) {
// we want to build up lowerdir, upperdir and workdir options for the
// overlay mount.
//
@ -194,7 +194,7 @@ func (lm *Manager) Prepare(dst, parent string) ([]containerkit.Mount, error) {
opts = append(opts, "lowerdir="+strings.Join(parents, ","))
return []Mount{
return []containerd.Mount{
{
Type: "overlay",
Source: "none",