Skip to content

Commit

Permalink
buildctl: add integration test for containerd exporter
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Dec 1, 2017
1 parent 02d01c0 commit c29f08d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
34 changes: 34 additions & 0 deletions cmd/buildctl/build_test.go
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"

Expand Down Expand Up @@ -64,6 +65,39 @@ func testBuildLocalExporter(t *testing.T, sb integration.Sandbox) {
require.Equal(t, string(dt), "bar")
}

func testBuildContainerdExporter(t *testing.T, sb integration.Sandbox) {
t.Parallel()

var cdAddress string
if cd, ok := sb.(interface {
ContainerDAddress() string
}); !ok {
t.Skip("only for containerd worker")
} else {
cdAddress = cd.ContainerDAddress()
}

st := llb.Image("busybox").
Run(llb.Shlex("sh -c 'echo -n bar > /foo'"))

rdr, err := marshal(st.Root())
require.NoError(t, err)

cmd := sb.Cmd("build --no-progress --exporter=image --exporter-opt name=docker.io/moby/imageexporter:test")
cmd.Stdin = rdr
err = cmd.Run()
require.NoError(t, err)

cmd = exec.Command("ctr", "--address", cdAddress, "--namespace=buildkit", "images", "ls")
stdout := new(bytes.Buffer)
cmd.Stdout = stdout

err = cmd.Run()
require.NoError(t, err)

require.Contains(t, stdout.String(), "docker.io/moby/imageexporter:test")
}

func marshal(st llb.State) (io.Reader, error) {
def, err := st.Marshal()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/buildctl/buildctl_test.go
Expand Up @@ -11,5 +11,6 @@ func TestCLIIntegration(t *testing.T) {
testDiskUsage,
testBuildWithLocalFiles,
testBuildLocalExporter,
testBuildContainerdExporter,
})
}
4 changes: 3 additions & 1 deletion hack/dockerfiles/test.Dockerfile
Expand Up @@ -20,7 +20,8 @@ RUN git clone https://github.com/containerd/containerd.git "$GOPATH/src/github.c
&& cd "$GOPATH/src/github.com/containerd/containerd" \
&& git checkout -q "$CONTAINERD_VERSION" \
&& make bin/containerd \
&& make bin/containerd-shim
&& make bin/containerd-shim \
&& make bin/ctr

FROM gobuild-base AS unit-tests
COPY --from=runc /usr/bin/runc /usr/bin/runc
Expand All @@ -45,6 +46,7 @@ FROM unit-tests AS integration-tests
COPY --from=buildctl /usr/bin/buildctl /usr/bin/
COPY --from=buildd-containerd /usr/bin/buildd-containerd /usr/bin
COPY --from=buildd-standalone /usr/bin/buildd-standalone /usr/bin
COPY --from=containerd /go/src/github.com/containerd/containerd/bin/ctr /usr/bin/

FROM gobuild-base AS cross-windows
ENV GOOS=windows
Expand Down
11 changes: 10 additions & 1 deletion util/testutil/integration/containerd.go
Expand Up @@ -70,5 +70,14 @@ func (c *containerd) New() (sb Sandbox, cl func() error, err error) {
}
deferF.append(stop)

return &sandbox{address: builddSock, logs: logs}, cl, nil
return &cdsandbox{address: address, sandbox: sandbox{address: builddSock, logs: logs}}, cl, nil
}

type cdsandbox struct {
sandbox
address string
}

func (s *cdsandbox) ContainerDAddress() string {
return s.address
}

0 comments on commit c29f08d

Please sign in to comment.