From 1af76ef5970202bdbc7024d825c0fcfcc4ec6ede Mon Sep 17 00:00:00 2001 From: David Calavera Date: Wed, 10 Feb 2016 15:16:59 -0500 Subject: [PATCH] Remove daemon dependency from api/server. Signed-off-by: David Calavera --- api/server/router/container/backend.go | 3 +-- api/server/server.go | 27 ++++++++------------------ api/types/backend/backend.go | 25 ++++++++++++++++++++++++ daemon/inspect.go | 22 +++++++++++++++++---- daemon/inspect_unix.go | 12 ++++++++++++ daemon/inspect_windows.go | 10 ++++++++++ docker/daemon.go | 20 +++++++++++++++++-- 7 files changed, 92 insertions(+), 27 deletions(-) diff --git a/api/server/router/container/backend.go b/api/server/router/container/backend.go index cc25f10919..bd8919759c 100644 --- a/api/server/router/container/backend.go +++ b/api/server/router/container/backend.go @@ -5,7 +5,6 @@ import ( "time" "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/daemon/exec" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/version" "github.com/docker/engine-api/types" @@ -15,7 +14,7 @@ import ( // execBackend includes functions to implement to provide exec functionality. type execBackend interface { ContainerExecCreate(config *types.ExecConfig) (string, error) - ContainerExecInspect(id string) (*exec.Config, error) + ContainerExecInspect(id string) (*backend.ExecInspect, error) ContainerExecResize(name string, height, width int) error ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error ExecExists(name string) (bool, error) diff --git a/api/server/server.go b/api/server/server.go index 5e8337a7c2..c15d268484 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -9,14 +9,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/server/router" - "github.com/docker/docker/api/server/router/build" - "github.com/docker/docker/api/server/router/container" - "github.com/docker/docker/api/server/router/image" - "github.com/docker/docker/api/server/router/network" - "github.com/docker/docker/api/server/router/system" - "github.com/docker/docker/api/server/router/volume" - "github.com/docker/docker/builder/dockerfile" - "github.com/docker/docker/daemon" "github.com/docker/docker/pkg/authorization" "github.com/docker/docker/utils" "github.com/docker/go-connections/sockets" @@ -174,14 +166,11 @@ func (s *Server) makeHTTPHandler(handler httputils.APIFunc) http.HandlerFunc { } } -// InitRouters initializes a list of routers for the server. -func (s *Server) InitRouters(d *daemon.Daemon) { - s.addRouter(container.NewRouter(d)) - s.addRouter(image.NewRouter(d)) - s.addRouter(network.NewRouter(d)) - s.addRouter(system.NewRouter(d)) - s.addRouter(volume.NewRouter(d)) - s.addRouter(build.NewRouter(dockerfile.NewBuildManager(d))) +// AddRouters initializes a list of routers for the server. +func (s *Server) AddRouters(routers ...router.Router) { + for _, r := range routers { + s.addRouter(r) + } } // addRouter adds a new router to the server. @@ -231,13 +220,13 @@ func (s *Server) initRouterSwapper() { // Reload reads configuration changes and modifies the // server according to those changes. // Currently, only the --debug configuration is taken into account. -func (s *Server) Reload(config *daemon.Config) { +func (s *Server) Reload(debug bool) { debugEnabled := utils.IsDebugEnabled() switch { - case debugEnabled && !config.Debug: // disable debug + case debugEnabled && !debug: // disable debug utils.DisableDebug() s.routerSwapper.Swap(s.createMux()) - case config.Debug && !debugEnabled: // enable debug + case debug && !debugEnabled: // enable debug utils.EnableDebug() s.routerSwapper.Swap(s.createMux()) } diff --git a/api/types/backend/backend.go b/api/types/backend/backend.go index c871a148c4..ffe9b709e1 100644 --- a/api/types/backend/backend.go +++ b/api/types/backend/backend.go @@ -42,3 +42,28 @@ type ContainerStatsConfig struct { Stop <-chan bool Version string } + +// ExecInspect holds information about a running process started +// with docker exec. +type ExecInspect struct { + ID string + Running bool + ExitCode *int + ProcessConfig *ExecProcessConfig + OpenStdin bool + OpenStderr bool + OpenStdout bool + CanRemove bool + ContainerID string + DetachKeys []byte +} + +// ExecProcessConfig holds information about the exec process +// running on the host. +type ExecProcessConfig struct { + Tty bool `json:"tty"` + Entrypoint string `json:"entrypoint"` + Arguments []string `json:"arguments"` + Privileged *bool `json:"privileged,omitempty"` + User string `json:"user,omitempty"` +} diff --git a/daemon/inspect.go b/daemon/inspect.go index feb7de28f1..511454f9c7 100644 --- a/daemon/inspect.go +++ b/daemon/inspect.go @@ -4,8 +4,8 @@ import ( "fmt" "time" + "github.com/docker/docker/api/types/backend" "github.com/docker/docker/container" - "github.com/docker/docker/daemon/exec" "github.com/docker/docker/daemon/network" "github.com/docker/docker/pkg/version" "github.com/docker/engine-api/types" @@ -175,12 +175,26 @@ func (daemon *Daemon) getInspectData(container *container.Container, size bool) // ContainerExecInspect returns low-level information about the exec // command. An error is returned if the exec cannot be found. -func (daemon *Daemon) ContainerExecInspect(id string) (*exec.Config, error) { - eConfig, err := daemon.getExecConfig(id) +func (daemon *Daemon) ContainerExecInspect(id string) (*backend.ExecInspect, error) { + e, err := daemon.getExecConfig(id) if err != nil { return nil, err } - return eConfig, nil + + pc := inspectExecProcessConfig(e) + + return &backend.ExecInspect{ + ID: e.ID, + Running: e.Running, + ExitCode: e.ExitCode, + ProcessConfig: pc, + OpenStdin: e.OpenStdin, + OpenStdout: e.OpenStdout, + OpenStderr: e.OpenStderr, + CanRemove: e.CanRemove, + ContainerID: e.ContainerID, + DetachKeys: e.DetachKeys, + }, nil } // VolumeInspect looks up a volume by name. An error is returned if diff --git a/daemon/inspect_unix.go b/daemon/inspect_unix.go index b9321f34c3..bb224c8796 100644 --- a/daemon/inspect_unix.go +++ b/daemon/inspect_unix.go @@ -3,7 +3,9 @@ package daemon import ( + "github.com/docker/docker/api/types/backend" "github.com/docker/docker/container" + "github.com/docker/docker/daemon/exec" "github.com/docker/engine-api/types" "github.com/docker/engine-api/types/versions/v1p19" ) @@ -77,3 +79,13 @@ func addMountPoints(container *container.Container) []types.MountPoint { } return mountPoints } + +func inspectExecProcessConfig(e *exec.Config) *backend.ExecProcessConfig { + return &backend.ExecProcessConfig{ + Tty: e.ProcessConfig.Tty, + Entrypoint: e.ProcessConfig.Entrypoint, + Arguments: e.ProcessConfig.Arguments, + Privileged: &e.ProcessConfig.Privileged, + User: e.ProcessConfig.User, + } +} diff --git a/daemon/inspect_windows.go b/daemon/inspect_windows.go index e42a61dadc..f20571d052 100644 --- a/daemon/inspect_windows.go +++ b/daemon/inspect_windows.go @@ -1,7 +1,9 @@ package daemon import ( + "github.com/docker/docker/api/types/backend" "github.com/docker/docker/container" + "github.com/docker/docker/daemon/exec" "github.com/docker/engine-api/types" ) @@ -28,3 +30,11 @@ func addMountPoints(container *container.Container) []types.MountPoint { func (daemon *Daemon) containerInspectPre120(name string) (*types.ContainerJSON, error) { return daemon.containerInspectCurrent(name, false) } + +func inspectExecProcessConfig(e *exec.Config) *backend.ExecProcessConfig { + return &backend.ExecProcessConfig{ + Tty: e.ProcessConfig.Tty, + Entrypoint: e.ProcessConfig.Entrypoint, + Arguments: e.ProcessConfig.Arguments, + } +} diff --git a/docker/daemon.go b/docker/daemon.go index 821b3f993b..7289948692 100644 --- a/docker/daemon.go +++ b/docker/daemon.go @@ -14,6 +14,13 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/distribution/uuid" apiserver "github.com/docker/docker/api/server" + "github.com/docker/docker/api/server/router/build" + "github.com/docker/docker/api/server/router/container" + "github.com/docker/docker/api/server/router/image" + "github.com/docker/docker/api/server/router/network" + systemrouter "github.com/docker/docker/api/server/router/system" + "github.com/docker/docker/api/server/router/volume" + "github.com/docker/docker/builder/dockerfile" "github.com/docker/docker/cli" "github.com/docker/docker/cliconfig" "github.com/docker/docker/daemon" @@ -270,14 +277,14 @@ func (cli *DaemonCli) CmdDaemon(args ...string) error { "graphdriver": d.GraphDriverName(), }).Info("Docker daemon") - api.InitRouters(d) + initRouters(api, d) reload := func(config *daemon.Config) { if err := d.Reload(config); err != nil { logrus.Errorf("Error reconfiguring the daemon: %v", err) return } - api.Reload(config) + api.Reload(config.Debug) } setupConfigReloadTrap(*configFile, cli.flags, reload) @@ -373,3 +380,12 @@ func loadDaemonCliConfig(config *daemon.Config, daemonFlags *flag.FlagSet, commo return config, nil } + +func initRouters(s *apiserver.Server, d *daemon.Daemon) { + s.AddRouters(container.NewRouter(d), + image.NewRouter(d), + network.NewRouter(d), + systemrouter.NewRouter(d), + volume.NewRouter(d), + build.NewRouter(dockerfile.NewBuildManager(d))) +}