diff options
author | Brian Goff <cpuguy@hey.com> | 2022-07-29 09:35:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-29 09:35:22 -0700 |
commit | 6e213899177faac5c4bf9bdc68ac2899fb0916e1 (patch) | |
tree | 2950b9fe6cc3ee3552a297f141abe394635e404e /integration | |
parent | f34567bf41ad65102a8b1f05496dc92b500a3056 (diff) | |
parent | 547da0d575519a197fbf4e0543555d508d176084 (diff) | |
download | docker-6e213899177faac5c4bf9bdc68ac2899fb0916e1.tar.gz |
Merge pull request #43800 from corhere/implicit-runtime-config
daemon: support alternative runtimes MVP
Diffstat (limited to 'integration')
-rw-r--r-- | integration/container/run_linux_test.go | 57 | ||||
-rw-r--r-- | integration/internal/container/ops.go | 7 |
2 files changed, 64 insertions, 0 deletions
diff --git a/integration/container/run_linux_test.go b/integration/container/run_linux_test.go index e0316dde3b..0325c4050e 100644 --- a/integration/container/run_linux_test.go +++ b/integration/container/run_linux_test.go @@ -5,6 +5,7 @@ import ( "context" "io" "os" + "os/exec" "path/filepath" "strings" "testing" @@ -15,7 +16,9 @@ import ( "github.com/docker/docker/api/types/versions" "github.com/docker/docker/integration/internal/container" net "github.com/docker/docker/integration/internal/network" + "github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/system" + "github.com/docker/docker/testutil/daemon" "golang.org/x/sys/unix" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -214,3 +217,57 @@ func TestRunConsoleSize(t *testing.T) { assert.Equal(t, strings.TrimSpace(b.String()), "123 57") } + +func TestRunWithAlternativeContainerdShim(t *testing.T) { + skip.If(t, testEnv.IsRemoteDaemon) + skip.If(t, testEnv.DaemonInfo.OSType != "linux") + + realShimPath, err := exec.LookPath("containerd-shim-runc-v2") + assert.Assert(t, err) + realShimPath, err = filepath.Abs(realShimPath) + assert.Assert(t, err) + + // t.TempDir() can't be used here as the temporary directory returned by + // that function cannot be accessed by the fake-root user for rootless + // Docker. It creates a nested hierarchy of directories where the + // outermost has permission 0700. + shimDir, err := os.MkdirTemp("", t.Name()) + assert.Assert(t, err) + t.Cleanup(func() { + if err := os.RemoveAll(shimDir); err != nil { + t.Errorf("shimDir RemoveAll cleanup: %v", err) + } + }) + assert.Assert(t, os.Chmod(shimDir, 0777)) + shimDir, err = filepath.Abs(shimDir) + assert.Assert(t, err) + assert.Assert(t, os.Symlink(realShimPath, filepath.Join(shimDir, "containerd-shim-realfake-v42"))) + + d := daemon.New(t, + daemon.WithEnvVars("PATH="+shimDir+":"+os.Getenv("PATH")), + daemon.WithContainerdSocket(""), // A new containerd instance needs to be started which inherits the PATH env var defined above. + ) + d.StartWithBusybox(t) + defer d.Stop(t) + + client := d.NewClientT(t) + ctx := context.Background() + + cID := container.Run(ctx, t, client, + container.WithImage("busybox"), + container.WithCmd("sh", "-c", `echo 'Hello, world!'`), + container.WithRuntime("io.containerd.realfake.v42"), + ) + + poll.WaitOn(t, container.IsStopped(ctx, client, cID), poll.WithDelay(100*time.Millisecond)) + + out, err := client.ContainerLogs(ctx, cID, types.ContainerLogsOptions{ShowStdout: true}) + assert.NilError(t, err) + defer out.Close() + + var b bytes.Buffer + _, err = stdcopy.StdCopy(&b, io.Discard, out) + assert.NilError(t, err) + + assert.Equal(t, strings.TrimSpace(b.String()), "Hello, world!") +} diff --git a/integration/internal/container/ops.go b/integration/internal/container/ops.go index 0d94a4ebf7..f3101a816c 100644 --- a/integration/internal/container/ops.go +++ b/integration/internal/container/ops.go @@ -234,3 +234,10 @@ func WithConsoleSize(width, height uint) func(*TestContainerConfig) { c.HostConfig.ConsoleSize = [2]uint{height, width} } } + +// WithRuntime sets the runtime to use to start the container +func WithRuntime(name string) func(*TestContainerConfig) { + return func(c *TestContainerConfig) { + c.HostConfig.Runtime = name + } +} |