mirror of https://github.com/docker/docs.git
Merge pull request #20205 from calavera/remove_last_daemon_references
Remove daemon dependency from api/server.
This commit is contained in:
commit
2658341b5f
|
@ -5,7 +5,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/backend"
|
"github.com/docker/docker/api/types/backend"
|
||||||
"github.com/docker/docker/daemon/exec"
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/version"
|
"github.com/docker/docker/pkg/version"
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
|
@ -15,7 +14,7 @@ import (
|
||||||
// execBackend includes functions to implement to provide exec functionality.
|
// execBackend includes functions to implement to provide exec functionality.
|
||||||
type execBackend interface {
|
type execBackend interface {
|
||||||
ContainerExecCreate(config *types.ExecConfig) (string, error)
|
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
|
ContainerExecResize(name string, height, width int) error
|
||||||
ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
|
ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
|
||||||
ExecExists(name string) (bool, error)
|
ExecExists(name string) (bool, error)
|
||||||
|
|
|
@ -9,14 +9,6 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/api/server/httputils"
|
"github.com/docker/docker/api/server/httputils"
|
||||||
"github.com/docker/docker/api/server/router"
|
"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/pkg/authorization"
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
"github.com/docker/go-connections/sockets"
|
"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.
|
// AddRouters initializes a list of routers for the server.
|
||||||
func (s *Server) InitRouters(d *daemon.Daemon) {
|
func (s *Server) AddRouters(routers ...router.Router) {
|
||||||
s.addRouter(container.NewRouter(d))
|
for _, r := range routers {
|
||||||
s.addRouter(image.NewRouter(d))
|
s.addRouter(r)
|
||||||
s.addRouter(network.NewRouter(d))
|
}
|
||||||
s.addRouter(system.NewRouter(d))
|
|
||||||
s.addRouter(volume.NewRouter(d))
|
|
||||||
s.addRouter(build.NewRouter(dockerfile.NewBuildManager(d)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// addRouter adds a new router to the server.
|
// addRouter adds a new router to the server.
|
||||||
|
@ -231,13 +220,13 @@ func (s *Server) initRouterSwapper() {
|
||||||
// Reload reads configuration changes and modifies the
|
// Reload reads configuration changes and modifies the
|
||||||
// server according to those changes.
|
// server according to those changes.
|
||||||
// Currently, only the --debug configuration is taken into account.
|
// 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()
|
debugEnabled := utils.IsDebugEnabled()
|
||||||
switch {
|
switch {
|
||||||
case debugEnabled && !config.Debug: // disable debug
|
case debugEnabled && !debug: // disable debug
|
||||||
utils.DisableDebug()
|
utils.DisableDebug()
|
||||||
s.routerSwapper.Swap(s.createMux())
|
s.routerSwapper.Swap(s.createMux())
|
||||||
case config.Debug && !debugEnabled: // enable debug
|
case debug && !debugEnabled: // enable debug
|
||||||
utils.EnableDebug()
|
utils.EnableDebug()
|
||||||
s.routerSwapper.Swap(s.createMux())
|
s.routerSwapper.Swap(s.createMux())
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,3 +42,28 @@ type ContainerStatsConfig struct {
|
||||||
Stop <-chan bool
|
Stop <-chan bool
|
||||||
Version string
|
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"`
|
||||||
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types/backend"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/daemon/exec"
|
|
||||||
"github.com/docker/docker/daemon/network"
|
"github.com/docker/docker/daemon/network"
|
||||||
"github.com/docker/docker/pkg/version"
|
"github.com/docker/docker/pkg/version"
|
||||||
"github.com/docker/engine-api/types"
|
"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
|
// ContainerExecInspect returns low-level information about the exec
|
||||||
// command. An error is returned if the exec cannot be found.
|
// command. An error is returned if the exec cannot be found.
|
||||||
func (daemon *Daemon) ContainerExecInspect(id string) (*exec.Config, error) {
|
func (daemon *Daemon) ContainerExecInspect(id string) (*backend.ExecInspect, error) {
|
||||||
eConfig, err := daemon.getExecConfig(id)
|
e, err := daemon.getExecConfig(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// VolumeInspect looks up a volume by name. An error is returned if
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/docker/docker/api/types/backend"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
|
"github.com/docker/docker/daemon/exec"
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
"github.com/docker/engine-api/types/versions/v1p19"
|
"github.com/docker/engine-api/types/versions/v1p19"
|
||||||
)
|
)
|
||||||
|
@ -77,3 +79,13 @@ func addMountPoints(container *container.Container) []types.MountPoint {
|
||||||
}
|
}
|
||||||
return mountPoints
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/docker/docker/api/types/backend"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
|
"github.com/docker/docker/daemon/exec"
|
||||||
"github.com/docker/engine-api/types"
|
"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) {
|
func (daemon *Daemon) containerInspectPre120(name string) (*types.ContainerJSON, error) {
|
||||||
return daemon.containerInspectCurrent(name, false)
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,13 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/distribution/uuid"
|
"github.com/docker/distribution/uuid"
|
||||||
apiserver "github.com/docker/docker/api/server"
|
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/cli"
|
||||||
"github.com/docker/docker/cliconfig"
|
"github.com/docker/docker/cliconfig"
|
||||||
"github.com/docker/docker/daemon"
|
"github.com/docker/docker/daemon"
|
||||||
|
@ -270,14 +277,14 @@ func (cli *DaemonCli) CmdDaemon(args ...string) error {
|
||||||
"graphdriver": d.GraphDriverName(),
|
"graphdriver": d.GraphDriverName(),
|
||||||
}).Info("Docker daemon")
|
}).Info("Docker daemon")
|
||||||
|
|
||||||
api.InitRouters(d)
|
initRouters(api, d)
|
||||||
|
|
||||||
reload := func(config *daemon.Config) {
|
reload := func(config *daemon.Config) {
|
||||||
if err := d.Reload(config); err != nil {
|
if err := d.Reload(config); err != nil {
|
||||||
logrus.Errorf("Error reconfiguring the daemon: %v", err)
|
logrus.Errorf("Error reconfiguring the daemon: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
api.Reload(config)
|
api.Reload(config.Debug)
|
||||||
}
|
}
|
||||||
|
|
||||||
setupConfigReloadTrap(*configFile, cli.flags, reload)
|
setupConfigReloadTrap(*configFile, cli.flags, reload)
|
||||||
|
@ -373,3 +380,12 @@ func loadDaemonCliConfig(config *daemon.Config, daemonFlags *flag.FlagSet, commo
|
||||||
|
|
||||||
return config, nil
|
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)))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue