travis-ci / travis-cookbooks

Chef cookbook monolithic repo :book: :bomb:
MIT License
662 stars 234 forks source link

[Discussion] Use Dockerfiles to build Xenial images #925

Open bogdanap opened 7 years ago

bogdanap commented 7 years ago

@soulshake came up with this idea a while ago and I thought it's worth discussing it, especially since we've just started work on Xenial - trying this out now would mean less duplicated work should we decide to move to Dockerfiles in the future.

Here are the bullet points we came up with:

Pros:

Cons:

Risks:

bogdanap commented 7 years ago

We've discussed this further as part of the weekly team sync and decided to spend some time on a proof of concept. For this purpose, I've created https://github.com/travis-ci/build-env-linux to keep the new Dockerfiles.

bogdanap commented 7 years ago

After giving this a bit more thought, I've realized that there is at least one case where we do need to keep running fully virtualized: builds that require service: docker. We could change our approach and use Dockerfiles for sudo: false builds, but I think that increases the chance of introducing differences between the two infras by mistake, so I'm afraid this might be it for this particular idea 💀

soulshake commented 7 years ago

@bogdanap I see a couple of possible paths forward here.

Bind-mount the Docker socket

Bind-mounting /var/run/docker.sock lets you control Docker from within Docker, which is a great solution for most cases IMO. There's not a lot you can't do from within a container with full privileges.

But there might be some edge cases where running in a container (fully privileged, with root) just isn't enough. I haven't found any yet, but they're probably out there.

There is one possible drawback when bind-mounting the docker socket: a script that runs e.g. docker ps -q | xargs docker kill would cause the environment to kill itself (and perhaps other components that you would run next to it in containers)

That being said, this could be:

Docker image -> VM image

The idea here would be to make a Docker image bootable, docker export, then import it as a VM image into GCE.

Since docker images share the kernel with the host, you need to load a bunch of kernel modules, etc. I have initrd and initramfs in my notes from a convo about this at DockerCon, but I haven't tried it myself yet.

chroot tricks

"Another approach would be, instead of turning a container image into a VM image, to inject the container image into a pre-existing (minimal) VM image and use some chroot trick to hand off control to the container image.

I believe that Debian even has some decent tools to manage chroots (i.e. mount the right pseudofs in the right place etc)."

Sources

Thanks @jpetazzo and @ewindisch for input!