Register built-in engine commands at runtime instead of compile-time

This allows selective loading of commands, and paves the way to dynamic
plugins.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-02-19 15:27:57 -08:00
parent aed7fe1cda
commit 919665a20a
6 changed files with 45 additions and 21 deletions

View file

@ -50,10 +50,6 @@ func ValidateHost(val string) (string, error) {
type HttpApiFunc func(eng *engine.Engine, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error
func init() {
engine.Register("serveapi", ServeApi)
}
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
conn, _, err := w.(http.Hijacker).Hijack()
if err != nil {

40
builtins/builtins.go Normal file
View file

@ -0,0 +1,40 @@
package builtins
import (
"github.com/dotcloud/docker/engine"
"github.com/dotcloud/docker"
"github.com/dotcloud/docker/api"
"github.com/dotcloud/docker/networkdriver/lxc"
)
func Register(eng *engine.Engine) {
daemon(eng)
remote(eng)
}
// remote: a RESTful api for cross-docker communication
func remote(eng *engine.Engine) {
eng.Register("serveapi", api.ServeApi)
}
// daemon: a default execution and storage backend for Docker on Linux,
// with the following underlying components:
//
// * Pluggable storage drivers including aufs, vfs, lvm and btrfs.
// * Pluggable execution drivers including lxc and chroot.
//
// In practice `daemon` still includes most core Docker components, including:
//
// * The reference registry client implementation
// * Image management
// * The build facility
// * Logging
//
// These components should be broken off into plugins of their own.
//
func daemon(eng *engine.Engine) {
eng.Register("initserver", docker.InitServer)
eng.Register("init_networkdriver", lxc.InitDriver)
eng.Register("version", docker.GetVersion)
}

View file

@ -6,8 +6,8 @@ import (
"os"
"strings"
_ "github.com/dotcloud/docker"
"github.com/dotcloud/docker/api"
"github.com/dotcloud/docker/builtins"
"github.com/dotcloud/docker/dockerversion"
"github.com/dotcloud/docker/engine"
flag "github.com/dotcloud/docker/pkg/mflag"
@ -81,6 +81,8 @@ func main() {
if err != nil {
log.Fatal(err)
}
// Load builtins
builtins.Register(eng)
// load the daemon in the background so we can immediately start
// the http api so that connections don't fail while the daemon
// is booting

View file

@ -57,12 +57,6 @@ var (
currentInterfaces = make(map[string]*networkInterface)
)
func init() {
if err := engine.Register("init_networkdriver", InitDriver); err != nil {
panic(err)
}
}
func InitDriver(job *engine.Job) engine.Status {
var (
network *net.IPNet

View file

@ -34,14 +34,10 @@ func (srv *Server) Close() error {
return srv.runtime.Close()
}
func init() {
engine.Register("initserver", jobInitServer)
}
// jobInitApi runs the remote api server `srv` as a daemon,
// Only one api server can run at the same time - this is enforced by a pidfile.
// The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup.
func jobInitServer(job *engine.Job) engine.Status {
func InitServer(job *engine.Job) engine.Status {
job.Logf("Creating server")
srv, err := NewServer(job.Eng, DaemonConfigFromJob(job))
if err != nil {

View file

@ -7,11 +7,7 @@ import (
"runtime"
)
func init() {
engine.Register("version", jobVersion)
}
func jobVersion(job *engine.Job) engine.Status {
func GetVersion(job *engine.Job) engine.Status {
if _, err := dockerVersion().WriteTo(job.Stdout); err != nil {
job.Errorf("%s", err)
return engine.StatusErr