Skip to content

Commit

Permalink
all: run integration tests against dockerd
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Whited <sam@samwhited.com>
  • Loading branch information
SamWhited committed Nov 7, 2019
1 parent 800b067 commit 3412fcf
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Expand Up @@ -78,14 +78,14 @@ RUN --mount=target=. \
echo "-X ${PKG}/version.Version=${VERSION} -X ${PKG}/version.Revision=${REVISION} -X ${PKG}/version.Package=${PKG}" | tee /tmp/.ldflags; \
echo -n "${VERSION}" | tee /tmp/.version;

# build buildctl binary
# build buildctl binary
FROM buildkit-base AS buildctl
ENV CGO_ENABLED=0
ARG TARGETPLATFORM
RUN --mount=target=. --mount=target=/root/.cache,type=cache \
--mount=target=/go/pkg/mod,type=cache \
--mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=buildkit-version \
set -x; go build -ldflags "$(cat /tmp/.ldflags)" -o /usr/bin/buildctl ./cmd/buildctl && \
set -x; go build -ldflags "$(cat /tmp/.ldflags)" -tags 'osusergo' -o /usr/bin/buildctl ./cmd/buildctl && \
file /usr/bin/buildctl && file /usr/bin/buildctl | egrep "statically linked|Mach-O|Windows"

# build buildkitd binary
Expand Down
35 changes: 33 additions & 2 deletions client/client_test.go
Expand Up @@ -47,8 +47,12 @@ import (
)

func init() {
integration.InitOCIWorker()
integration.InitContainerdWorker()
if os.Getenv("TEST_DOCKERD") == "1" {
integration.InitDockerdWorker()
} else {
integration.InitOCIWorker()
integration.InitContainerdWorker()
}
}

type nopWriteCloser struct {
Expand Down Expand Up @@ -253,6 +257,7 @@ func testStdinClosed(t *testing.T, sb integration.Sandbox) {
}

func testSSHMount(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
defer c.Close()
Expand Down Expand Up @@ -462,6 +467,7 @@ func testNetworkMode(t *testing.T, sb integration.Sandbox) {
}

func testPushByDigest(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
requiresLinux(t)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -519,6 +525,7 @@ func testSecurityMode(t *testing.T, sb integration.Sandbox) {
command = `sh -c 'cat /proc/self/status | grep CapEff | grep "00000000a80425fb"'`
allowedEntitlements = []entitlements.Entitlement{}
} else {
skipDockerd(t, sb)
/*
$ capsh --decode=0000003fffffffff
0x0000003fffffffff=cap_chown,cap_dac_override,cap_dac_read_search,cap_fowner,cap_fsetid,cap_kill,cap_setgid,
Expand Down Expand Up @@ -561,6 +568,7 @@ func testSecurityModeSysfs(t *testing.T, sb integration.Sandbox) {
if secMode == securitySandbox {
allowedEntitlements = []entitlements.Entitlement{}
} else {
skipDockerd(t, sb)
mode = llb.SecurityModeInsecure
allowedEntitlements = []entitlements.Entitlement{entitlements.EntitlementSecurityInsecure}
}
Expand Down Expand Up @@ -624,6 +632,7 @@ func testSecurityModeErrors(t *testing.T, sb integration.Sandbox) {
}

func testFrontendImageNaming(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
requiresLinux(t)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -1327,6 +1336,7 @@ func testUser(t *testing.T, sb integration.Sandbox) {
}

func testOCIExporter(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
requiresLinux(t)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -1430,6 +1440,7 @@ func testOCIExporter(t *testing.T, sb integration.Sandbox) {
}

func testFrontendMetadataReturn(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
requiresLinux(t)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -1460,7 +1471,16 @@ func testFrontendMetadataReturn(t *testing.T, sb integration.Sandbox) {
checkAllReleasable(t, c, sb, true)
}

func skipDockerd(t *testing.T, sb integration.Sandbox) {
// TODO: remove me once dockerd supports the image and exporter.
t.Helper()
if os.Getenv("TEST_DOCKERD") == "1" {
t.Skip("dockerd missing a required exporter, cache exporter, or entitlement")
}
}

func testExporterTargetExists(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
requiresLinux(t)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -1491,6 +1511,10 @@ func testExporterTargetExists(t *testing.T, sb integration.Sandbox) {
}

func testTarExporterWithSocket(t *testing.T, sb integration.Sandbox) {
if os.Getenv("TEST_DOCKERD") == "1" {
t.Skip("tar exporter is temporarily broken on dockerd")
}

requiresLinux(t)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
Expand All @@ -1515,6 +1539,7 @@ func testTarExporterWithSocket(t *testing.T, sb integration.Sandbox) {
}

func testBuildPushAndValidate(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
requiresLinux(t)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -1785,6 +1810,7 @@ func testBasicCacheImportExport(t *testing.T, sb integration.Sandbox, cacheOptio
}

func testBasicRegistryCacheImportExport(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
registry, err := sb.NewRegistry()
if errors.Cause(err) == integration.ErrorRequirements {
t.Skip(err.Error())
Expand All @@ -1801,6 +1827,7 @@ func testBasicRegistryCacheImportExport(t *testing.T, sb integration.Sandbox) {
}

func testMultipleRegistryCacheImportExport(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
registry, err := sb.NewRegistry()
if errors.Cause(err) == integration.ErrorRequirements {
t.Skip(err.Error())
Expand All @@ -1823,6 +1850,7 @@ func testMultipleRegistryCacheImportExport(t *testing.T, sb integration.Sandbox)
}

func testBasicLocalCacheImportExport(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
dir, err := ioutil.TempDir("", "buildkit")
require.NoError(t, err)
defer os.RemoveAll(dir)
Expand All @@ -1842,6 +1870,7 @@ func testBasicLocalCacheImportExport(t *testing.T, sb integration.Sandbox) {
}

func testBasicInlineCacheImportExport(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
requiresLinux(t)
registry, err := sb.NewRegistry()
if errors.Cause(err) == integration.ErrorRequirements {
Expand Down Expand Up @@ -2162,6 +2191,7 @@ func testCacheMountNoCache(t *testing.T, sb integration.Sandbox) {

// containerd/containerd#2119
func testDuplicateWhiteouts(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
requiresLinux(t)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -2233,6 +2263,7 @@ func testDuplicateWhiteouts(t *testing.T, sb integration.Sandbox) {

// #276
func testWhiteoutParentDir(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
requiresLinux(t)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion client/connhelper/connhelper.go
@@ -1,4 +1,5 @@
// Package connhelper provides helpers for connecting to a remote daemon host with custom logic.
// Package connhelper provides helpers for connecting to a remote daemon host
// with custom logic.
package connhelper

import (
Expand Down
31 changes: 29 additions & 2 deletions frontend/dockerfile/dockerfile_test.go
Expand Up @@ -44,8 +44,12 @@ import (
)

func init() {
integration.InitOCIWorker()
integration.InitContainerdWorker()
if os.Getenv("TEST_DOCKERD") == "1" {
integration.InitDockerdWorker()
} else {
integration.InitOCIWorker()
integration.InitContainerdWorker()
}
}

var allTests = []integration.Test{
Expand Down Expand Up @@ -1147,6 +1151,7 @@ COPY --from=build /out .
}

func testExportMultiPlatform(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)

dockerfile := []byte(`
Expand Down Expand Up @@ -1823,6 +1828,7 @@ FROM busybox:${tag}
}

func testDockerfileDirs(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)
f.RequiresBuildctl(t)

Expand Down Expand Up @@ -1891,6 +1897,7 @@ func testDockerfileDirs(t *testing.T, sb integration.Sandbox) {
}

func testDockerfileInvalidCommand(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)
f.RequiresBuildctl(t)
dockerfile := []byte(`
Expand All @@ -1917,6 +1924,7 @@ func testDockerfileInvalidCommand(t *testing.T, sb integration.Sandbox) {
}

func testDockerfileADDFromURL(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)
f.RequiresBuildctl(t)

Expand Down Expand Up @@ -1999,6 +2007,7 @@ ADD %s /dest/
}

func testDockerfileAddArchive(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)
f.RequiresBuildctl(t)

Expand Down Expand Up @@ -2245,6 +2254,7 @@ ADD *.tar /dest
}

func testSymlinkDestination(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)
f.RequiresBuildctl(t)

Expand Down Expand Up @@ -2362,6 +2372,8 @@ ENV foo=bar
}

func testExposeExpansion(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)

f := getFrontend(t, sb)

dockerfile := []byte(`
Expand Down Expand Up @@ -2551,6 +2563,7 @@ COPY . .
}

func testExportedHistory(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)
f.RequiresBuildctl(t)

Expand Down Expand Up @@ -2633,7 +2646,17 @@ RUN ["ls"]
require.NotNil(t, ociimg.History[6].Created)
}

func skipDockerd(t *testing.T, sb integration.Sandbox) {
// TODO: remove me once dockerd supports the image and exporter.
t.Helper()
if os.Getenv("TEST_DOCKERD") == "1" {
t.Skip("dockerd missing a required exporter, cache exporter, or entitlement")
}
}

func testUser(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)

f := getFrontend(t, sb)

dockerfile := []byte(`
Expand Down Expand Up @@ -3394,6 +3417,7 @@ COPY --from=stage1 baz bax
}

func testLabels(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)

dockerfile := []byte(`
Expand Down Expand Up @@ -3472,6 +3496,7 @@ LABEL foo=bar
}

func testCacheMultiPlatformImportExport(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)

registry, err := sb.NewRegistry()
Expand Down Expand Up @@ -3597,6 +3622,7 @@ COPY --from=base arch /
}

func testCacheImportExport(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)

registry, err := sb.NewRegistry()
Expand Down Expand Up @@ -3699,6 +3725,7 @@ COPY --from=base unique /
}

func testReproducibleIDs(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)

dockerfile := []byte(`
Expand Down
8 changes: 6 additions & 2 deletions frontend/frontend_test.go
Expand Up @@ -24,8 +24,12 @@ var (
)

func init() {
integration.InitOCIWorker()
integration.InitContainerdWorker()
if os.Getenv("TEST_DOCKERD") == "1" {
integration.InitDockerdWorker()
} else {
integration.InitOCIWorker()
integration.InitContainerdWorker()
}
}

func TestFrontendIntegration(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Expand Up @@ -3,6 +3,7 @@ module github.com/moby/buildkit
go 1.11

require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/BurntSushi/toml v0.3.1
github.com/Microsoft/go-winio v0.4.14
github.com/Microsoft/hcsshim v0.8.7-0.20190419161850-2226e083fc39 // indirect
Expand All @@ -19,7 +20,7 @@ require (
github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd // indirect
github.com/containernetworking/cni v0.7.1 // indirect
github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a
github.com/docker/cli v0.0.0-20190321234815-f40f9c240ab0
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible
github.com/docker/docker v1.14.0-0.20191106232431-31abc6c089eb
github.com/docker/docker-credential-helpers v0.6.0 // indirect
Expand All @@ -33,6 +34,7 @@ require (
github.com/golang/protobuf v1.2.0
github.com/google/go-cmp v0.3.0
github.com/google/shlex v0.0.0-20150127133951-6f45313302b9
github.com/gorilla/mux v1.7.3 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
github.com/hashicorp/go-immutable-radix v1.0.0
github.com/hashicorp/golang-lru v0.0.0-20160207214719-a0d98a5f2880
Expand Down
8 changes: 6 additions & 2 deletions go.sum
@@ -1,4 +1,6 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
Expand Down Expand Up @@ -40,8 +42,8 @@ github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a/go.mod h1:F5haX7
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/cli v0.0.0-20190321234815-f40f9c240ab0 h1:E7NTtHfZYV+iu35yZ49AbrxqhMHpiOl3FstDYm38vQ0=
github.com/docker/cli v0.0.0-20190321234815-f40f9c240ab0/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017 h1:2HQmlpI3yI9deH18Q6xiSOIjXD4sLI55Y/gfpa8/558=
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible h1:dvc1KSkIYTVjZgHf/CTC2diTYC8PzhaA5sFISRfNVrE=
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v0.0.0-20180531152204-71cd53e4a197/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
Expand Down Expand Up @@ -79,6 +81,8 @@ github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/shlex v0.0.0-20150127133951-6f45313302b9 h1:JM174NTeGNJ2m/oLH3UOWOvWQQKd+BoL3hcSCUWFLt0=
github.com/google/shlex v0.0.0-20150127133951-6f45313302b9/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY=
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 h1:MJG/KsmcqMwFAkh8mTnAwhyKoB+sTAnY4CACC110tbU=
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw=
Expand Down
10 changes: 9 additions & 1 deletion hack/test
Expand Up @@ -4,6 +4,8 @@
set -eu -o pipefail

: ${TEST_INTEGRATION=}
: ${EXTRA_INTEGRATION_DOCKER_FLAGS=}
: ${TEST_DOCKERD=0}
: ${TEST_GATEWAY=}
: ${TEST_DOCKERFILE=}
: ${DOCKERFILE_RELEASES=}
Expand Down Expand Up @@ -67,7 +69,13 @@ esac
cacheVolume=$(docker create -v /root/.cache -v /root/.cache/registry -v /go/pkg/mod alpine)

if [ "$TEST_INTEGRATION" == 1 ]; then
docker run --rm -v /tmp --volumes-from=$cacheVolume -e SKIP_INTEGRATION_TESTS -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $iid go test ${TESTFLAGS:--v} ${TESTPKGS:-./...}
docker run --rm -v /tmp ${EXTRA_INTEGRATION_DOCKER_FLAGS} \
--volumes-from=$cacheVolume \
-e TEST_DOCKERD \
-e SKIP_INTEGRATION_TESTS \
-e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry \
--privileged $iid \
/bin/sh -c "export PATH=\${PATH}${EXTRA_PATH:-}; go test ${TESTFLAGS:--v} ${TESTPKGS:-./...}"
fi


Expand Down

0 comments on commit 3412fcf

Please sign in to comment.