2017-11-27 22:24:29 +00:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
register(&containerd{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type containerd struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *containerd) Name() string {
|
|
|
|
return "containerd"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *containerd) New() (sb Sandbox, cl func() error, err error) {
|
|
|
|
if err := lookupBinary("containerd"); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2017-12-15 07:00:13 +00:00
|
|
|
if err := lookupBinary("buildd"); err != nil {
|
2017-11-27 22:24:29 +00:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
if err := requireRoot(); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
deferF := &multiCloser{}
|
|
|
|
cl = deferF.F()
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
deferF.F()()
|
|
|
|
cl = nil
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
tmpdir, err := ioutil.TempDir("", "bktest_containerd")
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
deferF.append(func() error { return os.RemoveAll(tmpdir) })
|
|
|
|
|
|
|
|
address := filepath.Join(tmpdir, "containerd.sock")
|
2017-11-30 02:15:01 +00:00
|
|
|
args := append([]string{}, "containerd", "--root", filepath.Join(tmpdir, "root"), "--log-level", "debug", "--root", filepath.Join(tmpdir, "state"), "--address", address)
|
2017-11-27 22:24:29 +00:00
|
|
|
|
|
|
|
cmd := exec.Command(args[0], args[1:]...)
|
|
|
|
|
|
|
|
logs := map[string]*bytes.Buffer{}
|
|
|
|
|
|
|
|
if stop, err := startCmd(cmd, logs); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
} else {
|
|
|
|
deferF.append(stop)
|
|
|
|
}
|
|
|
|
if err := waitUnix(address, 5*time.Second); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2017-12-15 07:00:13 +00:00
|
|
|
builddSock, stop, err := runBuildd([]string{"buildd",
|
|
|
|
"--oci-worker=false",
|
|
|
|
"--containerd-worker=true",
|
|
|
|
"--containerd-worker-addr", address}, logs)
|
2017-11-27 22:24:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
deferF.append(stop)
|
|
|
|
|
2017-12-05 19:46:04 +00:00
|
|
|
return &cdsandbox{address: address, sandbox: sandbox{address: builddSock, logs: logs, cleanup: deferF}}, cl, nil
|
2017-12-01 00:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cdsandbox struct {
|
|
|
|
sandbox
|
|
|
|
address string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *cdsandbox) ContainerdAddress() string {
|
|
|
|
return s.address
|
2017-11-27 22:24:29 +00:00
|
|
|
}
|