Merge pull request #27955 from mlaventure/runc-docker-info

Add external binaries version to docker info
This commit is contained in:
Victor Vieux 2016-11-10 21:27:14 -08:00 committed by GitHub
commit 0427afa409
21 changed files with 157 additions and 13 deletions

View file

@ -236,6 +236,7 @@ RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
# Install tomlv, vndr, runc, containerd, tini, docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy

View file

@ -164,6 +164,7 @@ RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
# Install tomlv, vndr, runc, containerd, tini, docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy

View file

@ -168,6 +168,7 @@ RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
# Install tomlv, vndr, runc, containerd, tini, docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy

View file

@ -187,6 +187,7 @@ RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
# Install tomlv, vndr, runc, containerd, tini, docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy

View file

@ -179,6 +179,7 @@ RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
# Install tomlv, vndr, runc, containerd, tini, docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy

View file

@ -60,6 +60,7 @@ ENV CGO_LDFLAGS -L/lib
# Install runc, containerd, tini and docker-proxy
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh runc containerd tini proxy

View file

@ -151,6 +151,13 @@ type Version struct {
BuildTime string `json:",omitempty"`
}
// Commit records a external tool actual commit id version along the
// one expect by dockerd as set at build time
type Commit struct {
ID string
Expected string
}
// InfoBase contains the base response of Remote API:
// GET "/info"
type InfoBase struct {
@ -208,6 +215,10 @@ type InfoBase struct {
// running containers are detected
LiveRestoreEnabled bool
Isolation container.Isolation
InitBinary string
ContainerdCommit Commit
RuncCommit Commit
InitCommit Commit
}
// SecurityOpt holds key/value pair about a security option

View file

@ -143,6 +143,22 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error {
}
if info.OSType == "linux" {
fmt.Fprintf(dockerCli.Out(), "Init Binary: %v\n", info.InitBinary)
for _, ci := range []struct {
Name string
Commit types.Commit
}{
{"containerd", info.ContainerdCommit},
{"runc", info.RuncCommit},
{"init", info.InitCommit},
} {
fmt.Fprintf(dockerCli.Out(), "%s version: %s", ci.Name, ci.Commit.ID)
if ci.Commit.ID != ci.Commit.Expected {
fmt.Fprintf(dockerCli.Out(), " (expected: %s)", ci.Commit.Expected)
}
fmt.Fprintf(dockerCli.Out(), "\n")
}
if len(info.SecurityOptions) != 0 {
fmt.Fprintf(dockerCli.Out(), "Security Options:\n")
for _, o := range info.SecurityOptions {

View file

@ -78,3 +78,13 @@ func (config *Config) GetAllRuntimes() map[string]types.Runtime {
func (config *Config) GetExecRoot() string {
return config.ExecRoot
}
// GetInitPath returns the configure docker-init path
func (config *Config) GetInitPath() string {
config.reloadLock.Lock()
defer config.reloadLock.Unlock()
if config.InitPath != "" {
return config.InitPath
}
return DefaultInitBinary
}

View file

@ -46,6 +46,11 @@ func (config *Config) GetRuntime(name string) *types.Runtime {
return nil
}
// GetInitPath returns the configure docker-init path
func (config *Config) GetInitPath() string {
return ""
}
// GetDefaultRuntimeName returns the current default runtime
func (config *Config) GetDefaultRuntimeName() string {
return stockRuntimeName

View file

@ -67,6 +67,9 @@ var (
// containerd if none is specified
DefaultRuntimeBinary = "docker-runc"
// DefaultInitBinary is the name of the default init binary
DefaultInitBinary = "docker-init"
errSystemNotSupported = fmt.Errorf("The Docker daemon is not supported on this platform.")
)

View file

@ -1,8 +1,11 @@
package daemon
import (
"context"
"os"
"os/exec"
"runtime"
"strings"
"sync/atomic"
"time"
@ -147,6 +150,47 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
v.CPUSet = sysInfo.Cpuset
v.Runtimes = daemon.configStore.GetAllRuntimes()
v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
v.InitBinary = daemon.configStore.GetInitPath()
v.ContainerdCommit.Expected = dockerversion.ContainerdCommitID
if sv, err := daemon.containerd.GetServerVersion(context.Background()); err == nil {
v.ContainerdCommit.ID = sv.Revision
} else {
logrus.Warnf("failed to retrieve containerd version: %v", err)
v.ContainerdCommit.ID = "N/A"
}
v.RuncCommit.Expected = dockerversion.RuncCommitID
if rv, err := exec.Command(DefaultRuntimeBinary, "--version").Output(); err == nil {
parts := strings.Split(strings.TrimSpace(string(rv)), "\n")
if len(parts) == 3 {
parts = strings.Split(parts[1], ": ")
if len(parts) == 2 {
v.RuncCommit.ID = strings.TrimSpace(parts[1])
}
}
} else {
logrus.Warnf("failed to retrieve %s version: %v", DefaultRuntimeBinary, err)
v.RuncCommit.ID = "N/A"
}
if v.RuncCommit.ID == "" {
logrus.Warnf("failed to retrieve %s version: unknown output format", DefaultRuntimeBinary)
v.RuncCommit.ID = "N/A"
}
v.InitCommit.Expected = dockerversion.InitCommitID
if rv, err := exec.Command(DefaultInitBinary, "--version").Output(); err == nil {
parts := strings.Split(string(rv), " ")
if len(parts) == 3 {
v.InitCommit.ID = strings.TrimSpace(parts[2])
} else {
logrus.Warnf("failed to retrieve %s version: unknown output format", DefaultInitBinary)
v.InitCommit.ID = "N/A"
}
} else {
logrus.Warnf("failed to retrieve %s version", DefaultInitBinary)
v.InitCommit.ID = "N/A"
}
}
hostname := ""

View file

@ -596,7 +596,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
s.Process.Args = append([]string{"/dev/init", c.Path}, c.Args...)
var path string
if daemon.configStore.InitPath == "" && c.HostConfig.InitPath == "" {
path, err = exec.LookPath("docker-init")
path, err = exec.LookPath(DefaultInitBinary)
if err != nil {
return err
}

View file

@ -0,0 +1,8 @@
#!/bin/sh
TOMLV_COMMIT=9baf8a8a9f2ed20a8e54160840c492f937eeaf9a
RUNC_COMMIT=ac031b5bf1cc92239461125f4c1ffb760522bbf2
CONTAINERD_COMMIT=8517738ba4b82aff5662c97ca4627e7e4d03b531
TINI_COMMIT=v0.13.0
LIBNETWORK_COMMIT=0f534354b813003a754606689722fe253101bc4e
VNDR_COMMIT=f56bd4504b4fad07a357913687fb652ee54bb3b0

View file

@ -2,12 +2,7 @@
set -e
set -x
TOMLV_COMMIT=9baf8a8a9f2ed20a8e54160840c492f937eeaf9a
RUNC_COMMIT=ac031b5bf1cc92239461125f4c1ffb760522bbf2
CONTAINERD_COMMIT=8517738ba4b82aff5662c97ca4627e7e4d03b531
TINI_COMMIT=v0.13.0
LIBNETWORK_COMMIT=0f534354b813003a754606689722fe253101bc4e
VNDR_COMMIT=f56bd4504b4fad07a357913687fb652ee54bb3b0
. $(dirname "$0")/binaries-commits
RM_GOPATH=0

View file

@ -2,6 +2,8 @@
rm -rf autogen
source hack/dockerfile/binaries-commits
cat > dockerversion/version_autogen.go <<DVEOF
// +build autogen
@ -11,12 +13,16 @@ package dockerversion
// Default build-time variable for library-import.
// This file is overridden on build with build-time informations.
const (
GitCommit string = "$GITCOMMIT"
Version string = "$VERSION"
BuildTime string = "$BUILDTIME"
IAmStatic string = "${IAMSTATIC:-true}"
GitCommit string = "$GITCOMMIT"
Version string = "$VERSION"
BuildTime string = "$BUILDTIME"
IAmStatic string = "${IAMSTATIC:-true}"
ContainerdCommitID string = "${CONTAINERD_COMMIT}"
RuncCommitID string = "${RUNC_COMMIT}"
InitCommitID string = "${TINI_COMMIT}"
)
// AUTOGENERATED FILE; see $BASH_SOURCE
// AUTOGENERATED FILE; see /go/src/github.com/docker/docker/hack/make/.go-autogen
DVEOF
# Compile the Windows resources into the sources

View file

@ -36,7 +36,7 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
}
if daemonPlatform == "linux" {
stringsToCheck = append(stringsToCheck, "Security Options:")
stringsToCheck = append(stringsToCheck, "Init Binary:", "Security Options:", "containerd version:", "runc version:", "init version:")
}
if DaemonIsLinux.Condition() {

View file

@ -28,6 +28,20 @@ type client struct {
liveRestore bool
}
// GetServerVersion returns the connected server version information
func (clnt *client) GetServerVersion(ctx context.Context) (*ServerVersion, error) {
resp, err := clnt.remote.apiClient.GetServerVersion(ctx, &containerd.GetServerVersionRequest{})
if err != nil {
return nil, err
}
sv := &ServerVersion{
GetServerVersionResponse: *resp,
}
return sv, nil
}
// AddProcess is the handler for adding a process to an already running
// container. It's called through docker exec. It returns the system pid of the
// exec'd process.

View file

@ -12,6 +12,20 @@ type client struct {
liveRestore bool
}
// GetServerVersion returns the connected server version information
func (clnt *client) GetServerVersion(ctx context.Context) (*ServerVersion, error) {
resp, err := clnt.remote.apiClient.GetServerVersion(ctx, &containerd.GetServerVersionRequest{})
if err != nil {
return nil, err
}
sv := &ServerVersion{
GetServerVersionResponse: *resp,
}
return sv, nil
}
func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendlyName string, specp Process, attachStdio StdioCallback) (int, error) {
return -1, nil
}

View file

@ -625,3 +625,7 @@ func (clnt *client) DeleteCheckpoint(containerID string, checkpointID string, ch
func (clnt *client) ListCheckpoints(containerID string, checkpointDir string) (*Checkpoints, error) {
return nil, errors.New("Windows: Containers do not support checkpoints")
}
func (clnt *client) GetServerVersion(ctx context.Context) (*ServerVersion, error) {
return &ServerVersion{}, nil
}

View file

@ -3,6 +3,7 @@ package libcontainerd
import (
"io"
containerd "github.com/docker/containerd/api/grpc/types"
"github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"
)
@ -33,6 +34,7 @@ type Backend interface {
// Client provides access to containerd features.
type Client interface {
GetServerVersion(ctx context.Context) (*ServerVersion, error)
Create(containerID string, checkpoint string, checkpointDir string, spec specs.Spec, attachStdio StdioCallback, options ...CreateOption) error
Signal(containerID string, sig int) error
SignalProcess(containerID string, processFriendlyName string, sig int) error
@ -65,3 +67,9 @@ type IOPipe struct {
Stderr io.ReadCloser
Terminal bool // Whether stderr is connected on Windows
}
// ServerVersion contains version information as retrieved from the
// server
type ServerVersion struct {
containerd.GetServerVersionResponse
}