Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dockertest.Resource.Exec fails with "Unrecognized input header: 100" #472

Open
3 of 5 tasks
thediveo opened this issue Sep 1, 2023 · 1 comment
Open
3 of 5 tasks
Labels

Comments

@thediveo
Copy link

thediveo commented Sep 1, 2023

Preflight checklist

Ory Network Project

No response

Describe the bug

dockertest.Resource.Exec(..., dockertest.ExecOptions{StdOut: ..., StdErr: ..., TTY: true}) fails with Start exec failed: Unrecognized input header: 100. This happens regardless of whether the corresponding container has been created with or without Tty: true.

Reproducing the bug

By("spinning up a Docker container with stand-alone containerd, courtesy of the KinD k8s sig")
pool := Successful(dockertest.NewPool("unix:///var/run/docker.sock"))
_ = pool.RemoveContainerByName(kindischName)
// The necessary container start arguments come from KinD's Docker node
// provisioner, see:
// https://github.com/kubernetes-sigs/kind/blob/3610f606516ccaa88aa098465d8c13af70937050/pkg/cluster/internal/providers/docker/provision.go#L133
//
// Please note that --privileged already implies switching off AppArmor.
//
// Please note further, that currently some Docker client CLI flags
// don't translate into dockertest-supported options.
//
// docker run -it --rm --name kindisch-...
//   --privileged
//   --cgroupns=private
//   --init=false
//   --volume /dev/mapper:/dev/mapper
//   --device /dev/fuse
//   --tmpfs /tmp
//   --tmpfs /run
//   --volume /var
//   --volume /lib/modules:/lib/modules:ro
//   kindisch-...
providerCntr = Successful(pool.BuildAndRunWithBuildOptions(
    &dockertest.BuildOptions{
	    ContextDir: "./test/kindisch", // sorry, couldn't resist the pun.
	    Dockerfile: "Dockerfile",
	    BuildArgs: []docker.BuildArg{
		    {Name: "KINDEST_BASE_TAG", Value: test.KindestBaseImageTag},
	    },
    },
    &dockertest.RunOptions{
	    Name:       kindischName,
	    Privileged: true,
	    Mounts: []string{
		    "/dev/mapper:/dev/mapper",
		    "/var",
		    "/lib/modules:/lib/modules:ro",
	    },
	    Tty: true,
    }, func(hc *docker.HostConfig) {
	    hc.Init = false
	    hc.Tmpfs = map[string]string{
		    "/tmp": "",
		    "/run": "",
	    }
	    hc.Devices = []docker.Device{
		    {PathOnHost: "/dev/fuse"},
	    }
    }))
func Exec(cntr *dockertest.Resource, args ...string) {
	gi.GinkgoHelper()
	exitCode, err := cntr.Exec(
		append([]string{"ctr"}, args...),
		dockertest.ExecOptions{
			StdOut: gi.GinkgoWriter,
			StdErr: gi.GinkgoWriter,
			TTY:    true,
		},
	)
	g.Expect(err).NotTo(g.HaveOccurred(), "failed: ctr %s", strings.Join(args, " "))
	g.Expect(exitCode).To(g.BeZero(), "ctr command failed with non-zero exit code")
}

Relevant log output

No response

Relevant configuration

No response

Version

v3.10.0

On which operating system are you observing this issue?

Linux

In which environment are you deploying?

Docker

Additional Context

No response

@thediveo thediveo added the bug label Sep 1, 2023
@thediveo
Copy link
Author

thediveo commented Jan 31, 2024

Never mind bothering with answering this bug issue and even fixing this obvious incompatibility with the Docker API's 100 CONTINUE.

For those stumbling upon the same problem, I've fixed it. I've simply written my own replacment for this module (not a drop-in), using the official Docker Go client, designing a neat function option API that works so much better than anticipated, and large test coverage on top, so I'm now replacing dockertest in company projects as well as my own. Now I have proper diagnosis ouput from builds, container runs, and command execs inside containers whenever a unit test fails. FYI, https://github.com/thediveo/morbyd

The above unit test excerpt now becomes as follows, properly streaming build and container output, without even needing to use a pseudo TTY:

By("spinning up a Docker container with stand-alone containerd, courtesy of the KinD k8s sig")
Expect(sess.BuildImage(ctx, "./_test/kindisch",
	build.WithTag(img.Name),
	build.WithBuildArg("KINDEST_BASE_TAG="+test.KindestBaseImageTag),
	build.WithOutput(timestamper.New(GinkgoWriter)))).
	Error().NotTo(HaveOccurred())
providerCntr = Successful(sess.Run(ctx, img.Name,
	run.WithName(kindischName),
	run.WithAutoRemove(),
	run.WithPrivileged(),
	run.WithSecurityOpt("label=disable"),
	run.WithCgroupnsMode("private"),
	run.WithVolume("/var"),
	run.WithVolume("/dev/mapper:/dev/mapper"),
	run.WithVolume("/lib/modules:/lib/modules:ro"),
	run.WithTmpfs("/tmp"),
	run.WithTmpfs("/run"),
	run.WithDevice("/dev/fuse"),
	run.WithCombinedOutput(timestamper.New(GinkgoWriter))))

Thank you for the fish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant