Move service to execution package
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
c857213b4c
commit
bde30191f4
4 changed files with 8 additions and 30 deletions
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/containerd"
|
"github.com/docker/containerd"
|
||||||
api "github.com/docker/containerd/api/execution"
|
api "github.com/docker/containerd/api/execution"
|
||||||
"github.com/docker/containerd/services/execution"
|
"github.com/docker/containerd/execution"
|
||||||
// metrics "github.com/docker/go-metrics"
|
// metrics "github.com/docker/go-metrics"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package executors
|
|
||||||
|
|
||||||
import "github.com/docker/containerd/execution"
|
|
||||||
|
|
||||||
var executors = make(map[string]func() execution.Executor)
|
|
||||||
|
|
||||||
func Register(name string, e func() execution.Executor) {
|
|
||||||
executors[name] = e
|
|
||||||
}
|
|
||||||
|
|
||||||
func Get(name string) func() execution.Executor {
|
|
||||||
return executors[name]
|
|
||||||
}
|
|
|
@ -10,16 +10,10 @@ import (
|
||||||
|
|
||||||
"github.com/crosbymichael/go-runc"
|
"github.com/crosbymichael/go-runc"
|
||||||
"github.com/docker/containerd/execution"
|
"github.com/docker/containerd/execution"
|
||||||
"github.com/docker/containerd/executors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrRootEmpty = errors.New("oci: runtime root cannot be an empty string")
|
var ErrRootEmpty = errors.New("oci: runtime root cannot be an empty string")
|
||||||
|
|
||||||
func init() {
|
|
||||||
executors.Register("oci", New)
|
|
||||||
executors.Register("runc", New)
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(root string) *OCIRuntime {
|
func New(root string) *OCIRuntime {
|
||||||
return &OCIRuntime{
|
return &OCIRuntime{
|
||||||
root: root,
|
root: root,
|
||||||
|
|
|
@ -4,35 +4,32 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
api "github.com/docker/containerd/api/execution"
|
api "github.com/docker/containerd/api/execution"
|
||||||
"github.com/docker/containerd/execution"
|
|
||||||
"github.com/docker/containerd/execution/executors"
|
|
||||||
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Opts struct {
|
type ServiceOpts struct {
|
||||||
Root string
|
Root string
|
||||||
Runtime string
|
Runtime string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(o Opts) (*Service, error) {
|
func New(opts ServiceOpts, executor Executor) (*Service, error) {
|
||||||
executor := executors.Get(o.Runtime)()
|
|
||||||
return &Service{
|
return &Service{
|
||||||
o: o,
|
o: opts,
|
||||||
executor: executor,
|
executor: executor,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
o Opts
|
o ServiceOpts
|
||||||
executor execution.Executor
|
executor Executor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Create(ctx context.Context, r *api.CreateContainerRequest) (*api.CreateContainerResponse, error) {
|
func (s *Service) Create(ctx context.Context, r *api.CreateContainerRequest) (*api.CreateContainerResponse, error) {
|
||||||
// TODO: write io and bundle path to dir
|
// TODO: write io and bundle path to dir
|
||||||
// TODO: open IOs
|
// TODO: open IOs
|
||||||
container, err := s.executor.Create(r.ID, execution.CreateOpts{
|
container, err := s.executor.Create(r.ID, CreateOpts{
|
||||||
Bundle: r.BundlePath,
|
Bundle: r.BundlePath,
|
||||||
// Stdin: r.Stdin,
|
// Stdin: r.Stdin,
|
||||||
// Stdout: r.Stdout,
|
// Stdout: r.Stdout,
|
||||||
|
@ -111,7 +108,7 @@ func (s *Service) StartProcess(ctx context.Context, r *api.StartProcessRequest)
|
||||||
// TODO: generate spec
|
// TODO: generate spec
|
||||||
var spec specs.Process
|
var spec specs.Process
|
||||||
// TODO: open IOs
|
// TODO: open IOs
|
||||||
process, err := s.executor.StartProcess(container, execution.CreateProcessOpts{
|
process, err := s.executor.StartProcess(container, CreateProcessOpts{
|
||||||
Spec: spec,
|
Spec: spec,
|
||||||
// Stdin: r.Stdin,
|
// Stdin: r.Stdin,
|
||||||
// Stdout: r.Stdout,
|
// Stdout: r.Stdout,
|
Loading…
Add table
Reference in a new issue