Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Merge component 'engine' from [email protected]:docker/engine 19.03
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonTheTurtle committed Apr 24, 2019
2 parents 023838e + 3a0b4ba commit 14dffdb
Show file tree
Hide file tree
Showing 72 changed files with 2,633 additions and 603 deletions.
46 changes: 31 additions & 15 deletions components/engine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,45 @@ RUN /download-frozen-image-v2.sh /build \
hello-world:latest@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
# See also ensureFrozenImagesLinux() in "integration-cli/fixtures_linux_daemon_test.go" (which needs to be updated when adding images to this list)

# Just a little hack so we don't have to install these deps twice, once for runc and once for dockerd
FROM base AS runtime-dev-cross-false
RUN apt-get update && apt-get install -y \
libapparmor-dev \
libseccomp-dev
FROM base AS cross-false

FROM runtime-dev-cross-false AS runtime-dev-cross-true
FROM base AS cross-true
RUN dpkg --add-architecture armhf
RUN dpkg --add-architecture arm64
RUN dpkg --add-architecture armel
RUN if [ "$(go env GOHOSTARCH)" = "amd64" ]; then \
apt-get update \
&& apt-get install -y --no-install-recommends \
crossbuild-essential-armhf \
crossbuild-essential-arm64 \
crossbuild-essential-armel; \
fi

FROM cross-${CROSS} as dev-base

FROM dev-base AS runtime-dev-cross-false
RUN apt-get update && apt-get install -y \
libapparmor-dev \
libseccomp-dev

FROM cross-true AS runtime-dev-cross-true
# These crossbuild packages rely on gcc-<arch>, but this doesn't want to install
# on non-amd64 systems.
# Additionally, the crossbuild-amd64 is currently only on debian:buster, so
# other architectures cannnot crossbuild amd64.
RUN if [ "$(go env GOHOSTARCH)" = "amd64" ]; then \
apt-get update \
&& apt-get install -y \
crossbuild-essential-armhf \
crossbuild-essential-arm64 \
crossbuild-essential-armel \
libseccomp-dev:armhf \
libseccomp-dev:arm64 \
libseccomp-dev:armel; \
libseccomp-dev:armel \
libapparmor-dev:armhf \
libapparmor-dev:arm64 \
libapparmor-dev:armel \
# install this arches seccomp here due to compat issues with the v0 builder
# This is as opposed to inheriting from runtime-dev-cross-false
libapparmor-dev \
libseccomp-dev; \
fi

FROM runtime-dev-cross-${CROSS} AS runtime-dev
Expand All @@ -133,14 +149,14 @@ COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME

FROM base AS containerd
FROM dev-base AS containerd
RUN apt-get update && apt-get install -y btrfs-tools
ENV INSTALL_BINARY_NAME=containerd
COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME

FROM base AS proxy
FROM dev-base AS proxy
ENV INSTALL_BINARY_NAME=proxy
COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
Expand All @@ -152,7 +168,7 @@ COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME

FROM base AS dockercli
FROM dev-base AS dockercli
ENV INSTALL_BINARY_NAME=dockercli
COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
Expand All @@ -164,14 +180,14 @@ COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME

FROM base AS tini
FROM dev-base AS tini
RUN apt-get update && apt-get install -y cmake vim-common
COPY hack/dockerfile/install/install.sh ./install.sh
ENV INSTALL_BINARY_NAME=tini
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME

FROM base AS rootlesskit
FROM dev-base AS rootlesskit
ENV INSTALL_BINARY_NAME=rootlesskit
COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
Expand Down
2 changes: 2 additions & 0 deletions components/engine/builder/builder-next/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/moby/buildkit/cache/metadata"
"github.com/moby/buildkit/cache/remotecache"
inlineremotecache "github.com/moby/buildkit/cache/remotecache/inline"
localremotecache "github.com/moby/buildkit/cache/remotecache/local"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/control"
"github.com/moby/buildkit/frontend"
Expand Down Expand Up @@ -186,6 +187,7 @@ func newController(rt http.RoundTripper, opt Opt) (*control.Controller, error) {
CacheKeyStorage: cacheStorage,
ResolveCacheImporterFuncs: map[string]remotecache.ResolveCacheImporterFunc{
"registry": localinlinecache.ResolveCacheImporterFunc(opt.SessionManager, opt.ResolverOpt, dist.ReferenceStore, dist.ImageStore),
"local": localremotecache.ResolveCacheImporterFunc(opt.SessionManager),
},
ResolveCacheExporterFuncs: map[string]remotecache.ResolveCacheExporterFunc{
"inline": inlineremotecache.ResolveCacheExporterFunc(),
Expand Down
44 changes: 37 additions & 7 deletions components/engine/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ type Client struct {
customHTTPHeaders map[string]string
// manualOverride is set to true when the version was set by users.
manualOverride bool

// negotiateVersion indicates if the client should automatically negotiate
// the API version to use when making requests. API version negotiation is
// performed on the first request, after which negotiated is set to "true"
// so that subsequent requests do not re-negotiate.
negotiateVersion bool

// negotiated indicates that API version negotiation took place
negotiated bool
}

// CheckRedirect specifies the policy for dealing with redirect responses:
Expand Down Expand Up @@ -169,8 +178,11 @@ func (cli *Client) Close() error {

// getAPIPath returns the versioned request path to call the api.
// It appends the query parameters to the path if they are not empty.
func (cli *Client) getAPIPath(p string, query url.Values) string {
func (cli *Client) getAPIPath(ctx context.Context, p string, query url.Values) string {
var apiPath string
if cli.negotiateVersion && !cli.negotiated {
cli.NegotiateAPIVersion(ctx)
}
if cli.version != "" {
v := strings.TrimPrefix(cli.version, "v")
apiPath = path.Join(cli.basePath, "/v"+v, p)
Expand All @@ -186,19 +198,31 @@ func (cli *Client) ClientVersion() string {
}

// NegotiateAPIVersion queries the API and updates the version to match the
// API version. Any errors are silently ignored.
// API version. Any errors are silently ignored. If a manual override is in place,
// either through the `DOCKER_API_VERSION` environment variable, or if the client
// was initialized with a fixed version (`opts.WithVersion(xx)`), no negotiation
// will be performed.
func (cli *Client) NegotiateAPIVersion(ctx context.Context) {
ping, _ := cli.Ping(ctx)
cli.NegotiateAPIVersionPing(ping)
if !cli.manualOverride {
ping, _ := cli.Ping(ctx)
cli.negotiateAPIVersionPing(ping)
}
}

// NegotiateAPIVersionPing updates the client version to match the Ping.APIVersion
// if the ping version is less than the default version.
// if the ping version is less than the default version. If a manual override is
// in place, either through the `DOCKER_API_VERSION` environment variable, or if
// the client was initialized with a fixed version (`opts.WithVersion(xx)`), no
// negotiation is performed.
func (cli *Client) NegotiateAPIVersionPing(p types.Ping) {
if cli.manualOverride {
return
if !cli.manualOverride {
cli.negotiateAPIVersionPing(p)
}
}

// negotiateAPIVersionPing queries the API and updates the version to match the
// API version. Any errors are silently ignored.
func (cli *Client) negotiateAPIVersionPing(p types.Ping) {
// try the latest version before versioning headers existed
if p.APIVersion == "" {
p.APIVersion = "1.24"
Expand All @@ -213,6 +237,12 @@ func (cli *Client) NegotiateAPIVersionPing(p types.Ping) {
if versions.LessThan(p.APIVersion, cli.version) {
cli.version = p.APIVersion
}

// Store the results, so that automatic API version negotiation (if enabled)
// won't be performed on the next request.
if cli.negotiateVersion {
cli.negotiated = true
}
}

// DaemonHost returns the host address used by the client
Expand Down
35 changes: 34 additions & 1 deletion components/engine/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package client // import "github.com/docker/docker/client"

import (
"bytes"
"context"
"io/ioutil"
"net/http"
"net/url"
"os"
"runtime"
"strings"
"testing"

"github.com/docker/docker/api"
Expand Down Expand Up @@ -123,9 +126,10 @@ func TestGetAPIPath(t *testing.T) {
{"v1.22", "/networks/kiwl$%^", nil, "/v1.22/networks/kiwl$%25%5E"},
}

ctx := context.TODO()
for _, testcase := range testcases {
c := Client{version: testcase.version, basePath: "/"}
actual := c.getAPIPath(testcase.path, testcase.query)
actual := c.getAPIPath(ctx, testcase.path, testcase.query)
assert.Check(t, is.Equal(actual, testcase.expected))
}
}
Expand Down Expand Up @@ -265,6 +269,35 @@ func TestNegotiateAPVersionOverride(t *testing.T) {
assert.Check(t, is.Equal(expected, client.version))
}

func TestNegotiateAPIVersionAutomatic(t *testing.T) {
var pingVersion string
httpClient := newMockClient(func(req *http.Request) (*http.Response, error) {
resp := &http.Response{StatusCode: http.StatusOK, Header: http.Header{}}
resp.Header.Set("API-Version", pingVersion)
resp.Body = ioutil.NopCloser(strings.NewReader("OK"))
return resp, nil
})

client, err := NewClientWithOpts(
WithHTTPClient(httpClient),
WithAPIVersionNegotiation(),
)
assert.NilError(t, err)

ctx := context.Background()
assert.Equal(t, client.ClientVersion(), api.DefaultVersion)

// First request should trigger negotiation
pingVersion = "1.35"
_, _ = client.Info(ctx)
assert.Equal(t, client.ClientVersion(), "1.35")

// Once successfully negotiated, subsequent requests should not re-negotiate
pingVersion = "1.25"
_, _ = client.Info(ctx)
assert.Equal(t, client.ClientVersion(), "1.35")
}

// TestNegotiateAPIVersionWithEmptyVersion asserts that initializing a client
// with an empty version string does still allow API-version negotiation
func TestNegotiateAPIVersionWithEmptyVersion(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion components/engine/client/hijack.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu
return types.HijackedResponse{}, err
}

apiPath := cli.getAPIPath(path, query)
apiPath := cli.getAPIPath(ctx, path, query)
req, err := http.NewRequest("POST", apiPath, bodyEncoded)
if err != nil {
return types.HijackedResponse{}, err
Expand Down
11 changes: 11 additions & 0 deletions components/engine/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,14 @@ func WithVersion(version string) Opt {
return nil
}
}

// WithAPIVersionNegotiation enables automatic API version negotiation for the client.
// With this option enabled, the client automatically negotiates the API version
// to use when making requests. API version negotiation is performed on the first
// request; subsequent requests will not re-negotiate.
func WithAPIVersionNegotiation() Opt {
return func(c *Client) error {
c.negotiateVersion = true
return nil
}
}
2 changes: 1 addition & 1 deletion components/engine/client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (cli *Client) buildRequest(method, path string, body io.Reader, headers hea
}

func (cli *Client) sendRequest(ctx context.Context, method, path string, query url.Values, body io.Reader, headers headers) (serverResponse, error) {
req, err := cli.buildRequest(method, cli.getAPIPath(path, query), body, headers)
req, err := cli.buildRequest(method, cli.getAPIPath(ctx, path, query), body, headers)
if err != nil {
return serverResponse{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion components/engine/daemon/cluster/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (c *Cluster) Info() types.Info {
default:
if info.Managers == 2 {
const warn string = `WARNING: Running Swarm in a two-manager configuration. This configuration provides
no fault tolerance, and poses a high risk to loose control over the cluster.
no fault tolerance, and poses a high risk to lose control over the cluster.
Refer to https://docs.docker.com/engine/swarm/admin_guide/ to configure the
Swarm for fault-tolerance.`

Expand Down
2 changes: 1 addition & 1 deletion components/engine/daemon/logger/fluentd/fluentd.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func New(info logger.Info) (logger.Logger, error) {
BufferLimit: bufferLimit,
RetryWait: retryWait,
MaxRetry: maxRetries,
AsyncConnect: asyncConnect,
Async: asyncConnect,
SubSecondPrecision: subSecondPrecision,
}

Expand Down
2 changes: 1 addition & 1 deletion components/engine/hack/dockerfile/install/proxy.installer
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# LIBNETWORK_COMMIT is used to build the docker-userland-proxy binary. When
# updating the binary version, consider updating github.com/docker/libnetwork
# in vendor.conf accordingly
LIBNETWORK_COMMIT=ebcade70ad1059b070d0040d798ecca359bc5fed
LIBNETWORK_COMMIT=9ff9b57c344df5cd47443ad9e65702ec85c5aeb0

install_proxy() {
case "$1" in
Expand Down
2 changes: 2 additions & 0 deletions components/engine/hack/make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ Try {

# Get the version of docker (eg 17.04.0-dev)
$dockerVersion="0.0.0-dev"
# Overwrite dockerVersion if VERSION Environment variable is available
if (Test-Path Env:\VERSION) { $dockerVersion=$env:VERSION }

# Give a warning if we are not running in a container and are building binaries or running unit tests.
# Not relevant for validation tests as these are fine to run outside of a container.
Expand Down
3 changes: 3 additions & 0 deletions components/engine/pkg/namesgenerator/names-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ var (
// Mildred Sanderson - American mathematician best known for Sanderson's theorem concerning modular invariants. https://en.wikipedia.org/wiki/Mildred_Sanderson
"sanderson",

// Satoshi Nakamoto is the name used by the unknown person or group of people who developed bitcoin, authored the bitcoin white paper, and created and deployed bitcoin's original reference implementation. https://en.wikipedia.org/wiki/Satoshi_Nakamoto
"satoshi",

// Adi Shamir - Israeli cryptographer whose numerous inventions and contributions to cryptography include the Ferge Fiat Shamir identification scheme, the Rivest Shamir Adleman (RSA) public-key cryptosystem, the Shamir's secret sharing scheme, the breaking of the Merkle-Hellman cryptosystem, the TWINKLE and TWIRL factoring devices and the discovery of differential cryptanalysis (with Eli Biham). https://en.wikipedia.org/wiki/Adi_Shamir
"shamir",

Expand Down
5 changes: 3 additions & 2 deletions components/engine/pkg/system/init_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package system // import "github.com/docker/docker/pkg/system"
import (
"os"

"github.com/Microsoft/hcsshim/osversion"
"github.com/sirupsen/logrus"
)

Expand All @@ -15,10 +16,10 @@ var (
containerdRuntimeSupported = false
)

// InitLCOW sets whether LCOW is supported or not
// InitLCOW sets whether LCOW is supported or not. Requires RS5+
func InitLCOW(experimental bool) {
v := GetOSVersion()
if experimental && v.Build >= 16299 {
if experimental && v.Build >= osversion.RS5 {
lcowSupported = true
}
}
Expand Down
Loading

0 comments on commit 14dffdb

Please sign in to comment.