mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #50010 from dmcgowan/dockerd-command-daemon
Split dockerd main command to package under daemon
This commit is contained in:
1
cmd/dockerd/builtins/builtins.go
Normal file
1
cmd/dockerd/builtins/builtins.go
Normal file
@@ -0,0 +1 @@
|
||||
package builtins
|
||||
@@ -1,5 +1,5 @@
|
||||
//go:generate go-winres make --arch=386,amd64,arm,arm64 --in=../../cli/winresources/dockerd/winres.json --out=../../cli/winresources/dockerd/resource
|
||||
//go:generate go-winres make --arch=386,amd64,arm,arm64 --in=../../../cli/winresources/dockerd/winres.json --out=../../../cli/winresources/dockerd/resource
|
||||
|
||||
package main
|
||||
package builtins
|
||||
|
||||
import _ "github.com/docker/docker/cli/winresources/dockerd"
|
||||
43
cmd/dockerd/main.go
Normal file
43
cmd/dockerd/main.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/moby/sys/reexec"
|
||||
"github.com/moby/term"
|
||||
|
||||
"github.com/docker/docker/daemon/command"
|
||||
|
||||
_ "github.com/docker/docker/cmd/dockerd/builtins"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if reexec.Init() {
|
||||
return
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
// Ignore SIGPIPE events. These are generated by systemd when journald is restarted while
|
||||
// the docker daemon is not restarted and also running under systemd.
|
||||
// Fixes https://github.com/docker/docker/issues/19728
|
||||
signal.Ignore(syscall.SIGPIPE)
|
||||
|
||||
// Set terminal emulation based on platform as required.
|
||||
_, stdout, stderr := term.StdStreams()
|
||||
onError := func(err error) {
|
||||
fmt.Fprintf(stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
r, err := command.NewDaemonRunner(stdout, stderr)
|
||||
if err != nil {
|
||||
onError(err)
|
||||
}
|
||||
if err := r.Run(ctx); err != nil {
|
||||
onError(err)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build linux || freebsd
|
||||
//go:build unix
|
||||
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"net"
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build linux || freebsd
|
||||
//go:build unix
|
||||
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/daemon/config"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -39,10 +39,10 @@ import (
|
||||
buildkit "github.com/docker/docker/builder/builder-next"
|
||||
"github.com/docker/docker/builder/builder-next/exporter"
|
||||
"github.com/docker/docker/builder/dockerfile"
|
||||
"github.com/docker/docker/cmd/dockerd/debug"
|
||||
"github.com/docker/docker/cmd/dockerd/trap"
|
||||
"github.com/docker/docker/daemon"
|
||||
"github.com/docker/docker/daemon/cluster"
|
||||
"github.com/docker/docker/daemon/command/debug"
|
||||
"github.com/docker/docker/daemon/command/trap"
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/daemon/listeners"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import "github.com/docker/docker/daemon/config"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
cdcgroups "github.com/containerd/cgroups/v3"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build !windows
|
||||
//go:build unix
|
||||
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build !windows
|
||||
//go:build unix
|
||||
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,25 +1,21 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"io"
|
||||
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/pkg/rootless"
|
||||
"github.com/moby/buildkit/util/apicaps"
|
||||
"github.com/moby/sys/reexec"
|
||||
"github.com/moby/term"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var honorXDG bool
|
||||
|
||||
func newDaemonCommand() (*cobra.Command, error) {
|
||||
func newDaemonCommand(stderr io.Writer) (*cobra.Command, error) {
|
||||
// FIXME(thaJeztah): config.New also looks up default binary-path, but this code is also executed when running "--version".
|
||||
cfg, err := config.New()
|
||||
if err != nil {
|
||||
@@ -42,7 +38,7 @@ func newDaemonCommand() (*cobra.Command, error) {
|
||||
}
|
||||
if opts.Validate {
|
||||
// If config wasn't OK we wouldn't have made it this far.
|
||||
_, _ = fmt.Fprintln(os.Stderr, "configuration OK")
|
||||
_, _ = fmt.Fprintln(stderr, "configuration OK")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -100,39 +96,36 @@ func init() {
|
||||
honorXDG = rootless.RunningWithRootlessKit()
|
||||
}
|
||||
|
||||
func main() {
|
||||
if reexec.Init() {
|
||||
return
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
// Ignore SIGPIPE events. These are generated by systemd when journald is restarted while
|
||||
// the docker daemon is not restarted and also running under systemd.
|
||||
// Fixes https://github.com/docker/docker/issues/19728
|
||||
signal.Ignore(syscall.SIGPIPE)
|
||||
|
||||
// Set terminal emulation based on platform as required.
|
||||
_, stdout, stderr := term.StdStreams()
|
||||
onError := func(err error) {
|
||||
fmt.Fprintf(stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
// Runner is used to run the daemon command
|
||||
type Runner interface {
|
||||
Run(context.Context) error
|
||||
}
|
||||
|
||||
// initial log formatting; this setting is updated after the daemon configuration is loaded.
|
||||
type daemonRunner struct {
|
||||
*cobra.Command
|
||||
}
|
||||
|
||||
func (d daemonRunner) Run(ctx context.Context) error {
|
||||
configureGRPCLog(ctx)
|
||||
|
||||
return d.ExecuteContext(ctx)
|
||||
}
|
||||
|
||||
// NewDaemonRunner creates a new daemon runner with the given
|
||||
// stdout and stderr writers.
|
||||
func NewDaemonRunner(stdout, stderr io.Writer) (Runner, error) {
|
||||
err := log.SetFormat(log.TextFormat)
|
||||
if err != nil {
|
||||
onError(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
initLogging(stdout, stderr)
|
||||
configureGRPCLog()
|
||||
|
||||
cmd, err := newDaemonCommand()
|
||||
cmd, err := newDaemonCommand(stderr)
|
||||
if err != nil {
|
||||
onError(err)
|
||||
return nil, err
|
||||
}
|
||||
cmd.SetOut(stdout)
|
||||
if err := cmd.ExecuteContext(ctx); err != nil {
|
||||
onError(err)
|
||||
}
|
||||
|
||||
return daemonRunner{cmd}, nil
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build !windows
|
||||
//go:build unix
|
||||
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// info => trace
|
||||
// warn => debug
|
||||
// error => warn
|
||||
func configureGRPCLog() {
|
||||
l := log.G(context.TODO()).WithField("library", "grpc")
|
||||
func configureGRPCLog(ctx context.Context) {
|
||||
l := log.G(ctx).WithField("library", "grpc")
|
||||
grpclog.SetLoggerV2(grpclog.NewLoggerV2(l.WriterLevel(log.TraceLevel), l.WriterLevel(log.DebugLevel), l.WriterLevel(log.WarnLevel)))
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"strings"
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build !windows
|
||||
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/spf13/pflag"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/cmd/dockerd/trap"
|
||||
"github.com/docker/docker/daemon/command/trap"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/system"
|
||||
"github.com/docker/docker/cmd/dockerd/debug"
|
||||
"github.com/docker/docker/daemon/command/debug"
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/daemon/internal/filedescriptors"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
|
||||
Reference in New Issue
Block a user