Skip to content

Commit

Permalink
Add a "daemon" build tag and toggle it with the already-existing "DOC…
Browse files Browse the repository at this point in the history
…KER_CLIENTONLY" build variable

This works mostly by refactoring our "main" package to be careful about what it imports based on the daemon build tag. :)

Also, I've updated Travis to test "client-only" compilation after it tests the daemon version.

Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)
  • Loading branch information
tianon committed Aug 4, 2014
1 parent 0af135e commit 1b95590
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 183 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ sudo: false
# Disable the normal go build.
install:
- export DOCKER_BUILDTAGS='exclude_graphdriver_btrfs exclude_graphdriver_devicemapper' # btrfs and devicemapper fail to compile thanks to a couple missing headers (which we can't install thanks to "sudo: false")
- export AUTO_GOPATH=1

before_script:
- env | sort

script:
- hack/make.sh validate-dco
- hack/make.sh validate-gofmt
- AUTO_GOPATH=1 ./hack/make.sh dynbinary
- ./hack/make.sh dynbinary
- DOCKER_CLIENTONLY=1 ./hack/make.sh dynbinary

# vim:set sw=2 ts=2:
17 changes: 17 additions & 0 deletions docker/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// +build !daemon

package main

import (
"log"
)

const CanDaemon = false

func mainSysinit() {
log.Fatal("This is a client-only binary - running it as 'dockerinit' is not supported.")
}

func mainDaemon() {
log.Fatal("This is a client-only binary - running the Docker daemon is not supported.")
}
112 changes: 112 additions & 0 deletions docker/daemon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// +build daemon

package main

import (
"log"
"net"

"github.com/docker/docker/builtins"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/engine"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/sysinit"
)

const CanDaemon = true

func mainSysinit() {
// Running in init mode
sysinit.SysInit()
}

func mainDaemon() {
if flag.NArg() != 0 {
flag.Usage()
return
}

if *bridgeName != "" && *bridgeIp != "" {
log.Fatal("You specified -b & --bip, mutually exclusive options. Please specify only one.")
}

if !*flEnableIptables && !*flInterContainerComm {
log.Fatal("You specified --iptables=false with --icc=false. ICC uses iptables to function. Please set --icc or --iptables to true.")
}

if net.ParseIP(*flDefaultIp) == nil {
log.Fatalf("Specified --ip=%s is not in correct format \"0.0.0.0\".", *flDefaultIp)
}

eng := engine.New()
// Load builtins
if err := builtins.Register(eng); err != nil {
log.Fatal(err)
}

// handle the pidfile early. https://github.com/docker/docker/issues/6973
if len(*pidfile) > 0 {
job := eng.Job("initserverpidfile", *pidfile)
if err := job.Run(); err != nil {
log.Fatal(err)
}
}

// 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
go func() {
// Load plugin: httpapi
job := eng.Job("initserver")
// include the variable here too, for the server config
job.Setenv("Pidfile", *pidfile)
job.Setenv("Root", *flRoot)
job.SetenvBool("AutoRestart", *flAutoRestart)
job.SetenvList("Dns", flDns.GetAll())
job.SetenvList("DnsSearch", flDnsSearch.GetAll())
job.SetenvBool("EnableIptables", *flEnableIptables)
job.SetenvBool("EnableIpForward", *flEnableIpForward)
job.Setenv("BridgeIface", *bridgeName)
job.Setenv("BridgeIP", *bridgeIp)
job.Setenv("DefaultIp", *flDefaultIp)
job.SetenvBool("InterContainerCommunication", *flInterContainerComm)
job.Setenv("GraphDriver", *flGraphDriver)
job.SetenvList("GraphOptions", flGraphOpts.GetAll())
job.Setenv("ExecDriver", *flExecDriver)
job.SetenvInt("Mtu", *flMtu)
job.SetenvBool("EnableSelinuxSupport", *flSelinuxEnabled)
job.SetenvList("Sockets", flHosts.GetAll())
if err := job.Run(); err != nil {
log.Fatal(err)
}
// after the daemon is done setting up we can tell the api to start
// accepting connections
if err := eng.Job("acceptconnections").Run(); err != nil {
log.Fatal(err)
}
}()

// TODO actually have a resolved graphdriver to show?
log.Printf("docker daemon: %s %s; execdriver: %s; graphdriver: %s",
dockerversion.VERSION,
dockerversion.GITCOMMIT,
*flExecDriver,
*flGraphDriver)

// Serve api
job := eng.Job("serveapi", flHosts.GetAll()...)
job.SetenvBool("Logging", true)
job.SetenvBool("EnableCors", *flEnableCors)
job.Setenv("Version", dockerversion.VERSION)
job.Setenv("SocketGroup", *flSocketGroup)

job.SetenvBool("Tls", *flTls)
job.SetenvBool("TlsVerify", *flTlsVerify)
job.Setenv("TlsCa", *flCa)
job.Setenv("TlsCert", *flCert)
job.Setenv("TlsKey", *flKey)
job.SetenvBool("BufferRequests", true)
if err := job.Run(); err != nil {
log.Fatal(err)
}
}
Loading

0 comments on commit 1b95590

Please sign in to comment.