#How to run integration tests inside the container?

1 messages Β· Page 1 of 1 (latest)

pale cipher
#

First I'm here say Go SDK is absolutely game changer. Thank you dev team for all the hard work!

We've been using Earthly to develop our CI pipelines to test and build servers, and we really like the WITH DOCKER feature with which a docker environment is provided during the test so that we can side run something like mysql to test integration.

However I'm not very sure how a similar process can be done for now with dagger. It seems that at least it should allow running privileged container so that dind is able to run. Is this a thing yet?

tawny geyser
pale cipher
magic mango
#

Hi @pale cipher , in the very short term (hopefully by next week) we will add support for mounting unix sockets from the host into the container. This will allow connecting to an external docker engine, which I think is what you need

pale cipher
magic mango
#

how does it work when buildkit is hosted on a remote dockerd?

unix socket is forwarded to/from the client host machine, using the buildkit streaming protocol. So this will work with remote workers as well. As long as there is a unix socket on the client's host filesystem of course

how to access container spawned by host docker from dagger container?

Use the Dagger API to execute a container with 1) a docker client installed (for example the docker CLI but could be anything), and 2) a valid docker socket mounted at /var/run/docker.sock

#

Let me know if that's not clear (can be confusing when talking about multiple layers of container engines πŸ™‚

pale cipher
#

So if it's the local's docker.sock forwarded and mounted on remote's container, running docker run mysql inside a dagger container will actually spawn mysql container on local? Speaking of "access" actually I meant to connect to the mysql port, is it really possible without some sort of network setup? lol

#

The reason I care so much about the remote dockerd madness is that our corp CI platform is based on unprivileged container instead of vm like github actions, so we have to make a machine to be a shared dockerd in order to use docker commands on CI runs. Therefore there is no docker.sock on local but on remote.

magic mango
#

cc @rigid sinew @vocal shale πŸ‘†

#

Yeah access the mysql container itself is an additional problem... Mostly because the Docker API doesn't have an infrastructure-agnostic way to access a port (something we are fixing with Dagger πŸ™‚

#

@pale cipher how do you access the docker.sock from your CI contsiner currently?

magic mango
#

There is probably a short-term fix, and a longer-term solution.

  • Longer-term, assuming you like Dagger and want to use it in your CI: setup a shared Dagger runner running on top of your shared docker; have your unprivileged CI runners connect to that (no more remote docker.sock), and use the Dagger API to run mysql directly.
#
  • Short-term: I need to understand your setup a bit better to be sure πŸ™‚
rigid sinew
#

(mysql or any other long running service alongside your pipeline)

pale cipher
#

Is the goal to run a fresh mysql container for tests, only for the duration of tests?

Yes, but could be as complicated as kind create cluster.

#

assuming you like Dagger and want to use it in your CI

No I don't like dagger. I love dagger.cat_confused

a shared Dagger runner running on top of your shared docker

Is there a dagger runner with Go SDK? I didn't notice. How are my repo files transfered this way?

magic mango
#

It's complicated πŸ™‚ Remote engine is in the works and not yet fully complete / documented. But it's coming!

rigid sinew
pale cipher
magic mango
#

Huh.

#

Well Earthly runs on buildkit too, so if they can do it, I'm sure Dagger could? Had no idea this is something they did, or that it would be something people need πŸ™‚

rigid sinew
#

I see. Long term, we're going to have services as @tawny geyser pointed out. Basically it will allow you to run long running containers directly from the SDK (equivalent of docker run but in code)

With that, you could run a docker-in-docker with dagger

magic mango
#

@rigid sinew could it be done in userland now, within an exec?

pale cipher
#

I think it can be as easy as allowing Exec with privileged. Haven't dug into it yet.

rigid sinew
#

Basically a never ending .Exec() in a goroutine

magic mango
#

Could also be all wrapped in a shell script inside a "regular" exec? Not sure which is more hacky

pale cipher
rigid sinew
#

So it will break at some point, but when it'll break we'll have a better alternative

pale cipher
#

So what do you think about adding privileged exec support? Along with the never-ending-exec hack my problem seems to be solved in the short term.thinkies