Skip to content

Commit

Permalink
Build two binaries client and daemon.
Browse files Browse the repository at this point in the history
Add a proxy to support 'docker daemon'
Fix configFile option, and remove a test that is no longer relevant.
Remove daemon build tag.
Remove DOCKER_CLIENTONLY from build scripts.

Signed-off-by: Daniel Nephin <[email protected]>

Change docker-daemon to dockerd.

Signed-off-by: Daniel Nephin <[email protected]>
  • Loading branch information
dnephin committed Apr 22, 2016
1 parent 9b00817 commit 9e7651d
Show file tree
Hide file tree
Showing 37 changed files with 412 additions and 237 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo
DOCKERFILE := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKERFILE}')

# env vars passed through directly to Docker's build scripts
# to allow things like `make DOCKER_CLIENTONLY=1 binary` easily
# to allow things like `make KEEPBUNDLE=1 binary` easily
# `docs/sources/contributing/devenvironment.md ` and `project/PACKAGERS.md` have some limited documentation of some of these
DOCKER_ENVS := \
-e BUILDFLAGS \
-e KEEPBUNDLE \
-e DOCKER_BUILD_GOGC \
-e DOCKER_BUILD_PKGS \
-e DOCKER_CLIENTONLY \
-e DOCKER_DEBUG \
-e DOCKER_EXPERIMENTAL \
-e DOCKER_GITCOMMIT \
Expand Down
46 changes: 28 additions & 18 deletions docker/common.go → cli/flags/common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package flags

import (
"fmt"
Expand All @@ -14,26 +14,32 @@ import (
)

const (
defaultTrustKeyFile = "key.json"
defaultCaFile = "ca.pem"
defaultKeyFile = "key.pem"
defaultCertFile = "cert.pem"
tlsVerifyKey = "tlsverify"
// DefaultTrustKeyFile is the default filename for the trust key
DefaultTrustKeyFile = "key.json"
// DefaultCaFile is the default filename for the CA pem file
DefaultCaFile = "ca.pem"
// DefaultKeyFile is the default filename for the key pem file
DefaultKeyFile = "key.pem"
// DefaultCertFile is the default filename for the cert pem file
DefaultCertFile = "cert.pem"
// TLSVerifyKey is the default flag name for the tls verification option
TLSVerifyKey = "tlsverify"
)

var (
commonFlags = &cli.CommonFlags{FlagSet: new(flag.FlagSet)}

dockerCertPath = os.Getenv("DOCKER_CERT_PATH")
dockerTLSVerify = os.Getenv("DOCKER_TLS_VERIFY") != ""
)

func init() {
// InitCommonFlags initializes flags common to both client and daemon
func InitCommonFlags() *cli.CommonFlags {
var commonFlags = &cli.CommonFlags{FlagSet: new(flag.FlagSet)}

if dockerCertPath == "" {
dockerCertPath = cliconfig.ConfigDir()
}

commonFlags.PostParse = postParseCommon
commonFlags.PostParse = func() { postParseCommon(commonFlags) }

cmd := commonFlags.FlagSet

Expand All @@ -46,22 +52,24 @@ func init() {

var tlsOptions tlsconfig.Options
commonFlags.TLSOptions = &tlsOptions
cmd.StringVar(&tlsOptions.CAFile, []string{"-tlscacert"}, filepath.Join(dockerCertPath, defaultCaFile), "Trust certs signed only by this CA")
cmd.StringVar(&tlsOptions.CertFile, []string{"-tlscert"}, filepath.Join(dockerCertPath, defaultCertFile), "Path to TLS certificate file")
cmd.StringVar(&tlsOptions.KeyFile, []string{"-tlskey"}, filepath.Join(dockerCertPath, defaultKeyFile), "Path to TLS key file")
cmd.StringVar(&tlsOptions.CAFile, []string{"-tlscacert"}, filepath.Join(dockerCertPath, DefaultCaFile), "Trust certs signed only by this CA")
cmd.StringVar(&tlsOptions.CertFile, []string{"-tlscert"}, filepath.Join(dockerCertPath, DefaultCertFile), "Path to TLS certificate file")
cmd.StringVar(&tlsOptions.KeyFile, []string{"-tlskey"}, filepath.Join(dockerCertPath, DefaultKeyFile), "Path to TLS key file")

cmd.Var(opts.NewNamedListOptsRef("hosts", &commonFlags.Hosts, opts.ValidateHost), []string{"H", "-host"}, "Daemon socket(s) to connect to")
return commonFlags
}

func postParseCommon() {
func postParseCommon(commonFlags *cli.CommonFlags) {
cmd := commonFlags.FlagSet

setDaemonLogLevel(commonFlags.LogLevel)
SetDaemonLogLevel(commonFlags.LogLevel)

// Regardless of whether the user sets it to true or false, if they
// specify --tlsverify at all then we need to turn on tls
// TLSVerify can be true even if not set due to DOCKER_TLS_VERIFY env var, so we need to check that here as well
if cmd.IsSet("-"+tlsVerifyKey) || commonFlags.TLSVerify {
// TLSVerify can be true even if not set due to DOCKER_TLS_VERIFY env var, so we need
// to check that here as well
if cmd.IsSet("-"+TLSVerifyKey) || commonFlags.TLSVerify {
commonFlags.TLS = true
}

Expand All @@ -86,7 +94,9 @@ func postParseCommon() {
}
}

func setDaemonLogLevel(logLevel string) {
// SetDaemonLogLevel sets the logrus logging level
// TODO: this is a bad name, it applies to the client as well.
func SetDaemonLogLevel(logLevel string) {
if logLevel != "" {
lvl, err := logrus.ParseLevel(logLevel)
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions docker/client.go → client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import (
"path/filepath"

"github.com/docker/docker/cli"
cliflags "github.com/docker/docker/cli/flags"
"github.com/docker/docker/cliconfig"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/utils"
)

var clientFlags = &cli.ClientFlags{FlagSet: new(flag.FlagSet), Common: commonFlags}
var (
commonFlags = cliflags.InitCommonFlags()
clientFlags = &cli.ClientFlags{FlagSet: new(flag.FlagSet), Common: commonFlags}
)

func init() {

client := clientFlags.FlagSet
client.StringVar(&clientFlags.ConfigDir, []string{"-config"}, cliconfig.ConfigDir(), "Location of client config files")

Expand All @@ -23,7 +28,7 @@ func init() {
}

if clientFlags.Common.TrustKey == "" {
clientFlags.Common.TrustKey = filepath.Join(cliconfig.ConfigDir(), defaultTrustKeyFile)
clientFlags.Common.TrustKey = filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile)
}

if clientFlags.Common.Debug {
Expand Down
File renamed without changes.
43 changes: 43 additions & 0 deletions client/daemon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"os"
"os/exec"
"syscall"
)

const daemonBinary = "dockerd"

// DaemonProxy acts as a cli.Handler to proxy calls to the daemon binary
type DaemonProxy struct{}

// NewDaemonProxy returns a new handler
func NewDaemonProxy() DaemonProxy {
return DaemonProxy{}
}

// CmdDaemon execs dockerd with the same flags
// TODO: add a deprecation warning?
func (p DaemonProxy) CmdDaemon(args ...string) error {
args = stripDaemonArg(os.Args[1:])

binaryAbsPath, err := exec.LookPath(daemonBinary)
if err != nil {
return err
}

return syscall.Exec(
binaryAbsPath,
append([]string{daemonBinary}, args...),
os.Environ())
}

// stripDaemonArg removes the `daemon` argument from the list
func stripDaemonArg(args []string) []string {
for i, arg := range args {
if arg == "daemon" {
return append(args[:i], args[i+1:]...)
}
}
return args
}
82 changes: 82 additions & 0 deletions client/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package main

import (
"fmt"
"os"

"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/client"
"github.com/docker/docker/cli"
"github.com/docker/docker/dockerversion"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/reexec"
"github.com/docker/docker/pkg/term"
"github.com/docker/docker/utils"
)

func main() {
if reexec.Init() {
return
}

// Set terminal emulation based on platform as required.
stdin, stdout, stderr := term.StdStreams()

logrus.SetOutput(stderr)

flag.Merge(flag.CommandLine, clientFlags.FlagSet, commonFlags.FlagSet)

flag.Usage = func() {
fmt.Fprint(stdout, "Usage: docker [OPTIONS] COMMAND [arg...]\n docker [ --help | -v | --version ]\n\n")
fmt.Fprint(stdout, "A self-sufficient runtime for containers.\n\nOptions:\n")

flag.CommandLine.SetOutput(stdout)
flag.PrintDefaults()

help := "\nCommands:\n"

for _, cmd := range dockerCommands {
help += fmt.Sprintf(" %-10.10s%s\n", cmd.Name, cmd.Description)
}

help += "\nRun 'docker COMMAND --help' for more information on a command."
fmt.Fprintf(stdout, "%s\n", help)
}

flag.Parse()

if *flVersion {
showVersion()
return
}

if *flHelp {
// if global flag --help is present, regardless of what other options and commands there are,
// just print the usage.
flag.Usage()
return
}

clientCli := client.NewDockerCli(stdin, stdout, stderr, clientFlags)

c := cli.New(clientCli, NewDaemonProxy())
if err := c.Run(flag.Args()...); err != nil {
if sterr, ok := err.(cli.StatusError); ok {
if sterr.Status != "" {
fmt.Fprintln(stderr, sterr.Status)
os.Exit(1)
}
os.Exit(sterr.StatusCode)
}
fmt.Fprintln(stderr, err)
os.Exit(1)
}
}

func showVersion() {
if utils.ExperimentalBuild() {
fmt.Printf("Docker version %s, build %s, experimental\n", dockerversion.Version, dockerversion.GitCommit)
} else {
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
}
}
5 changes: 5 additions & 0 deletions client/docker_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

import (
_ "github.com/docker/docker/autogen/winresources"
)
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9e7651d

Please sign in to comment.