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

Add the option to use docker containers #181

Merged
merged 4 commits into from
May 31, 2018
Merged

Conversation

achow101
Copy link
Contributor

@achow101 achow101 commented May 29, 2018

This PR adds another VM type: docker containers.

Since vmbuilder appears to be borked in recent versions (at least for how we are using it) and people have had issues with lxc in the past (including myself), I have added the option of using docker containers instead of LXC, KVM, or vbox. Setting up and using the docker containers is just as easy and seamless as the setup for lxc and kvm, except it should actually work since the docker people know what they are doing and have made it easy to actually setup and interact with docker containers.

make-base-vm now has a --docker switch to enable docker containers. Like with lxc, a USE_DOCKER environment variable needs to be set for the other scripts to use docker.

I have tested this with a build of Bitcoin Core 0.16.1rc1. The host is Ubuntu 18.04 while the container uses Ubuntu 14.04 as specified by the Bitcoin Core gitian descriptors. The binaries built matched those built by others using lxc or kvm (I am currently unable to compare with my own lxc and kvm builds because neither work for me).

While this PR supports using debian instead of ubuntu, I have no idea whether it actually works and I don't have anything to test that with.

@achow101 achow101 requested a review from devrandom as a code owner May 29, 2018 04:19
codablock added a commit to codablock/dash that referenced this pull request May 29, 2018
Copy link

@codablock codablock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Your timing couldn't be better :) I was already thinking about implementing the same. Found one error so far (see inline comments).

I'm still testing this and can later report if I was able to create deterministic builds.

@@ -70,6 +71,10 @@ if [ $# != 0 ] ; then
VBOX=1
shift 1
;;
--docker)
DOCKER=1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have a default value set on top of this script (like LXC and KVM). This later makes $DOCKER = "1" fail when not using docker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

bin/make-base-vm Outdated

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get --no-install-recommends -y install $addpkg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be combined with the previous statement to avoid rare caching issues that would cause the install to fail.

C.f. https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@devrandom
Copy link
Owner

I like this in concept, but I have some concerns about trust.

I worry that there is no way to validate that the pulled docker image (e.g. Debian) hasn't been tampered with. If everybody builds using docker, that will become a single point of potential compromise.

Any thoughts on this?

@devrandom
Copy link
Owner

devrandom commented May 29, 2018

To clarify, I contrast this with distribution supplied CD/DVD images, which (I believe) have more eyes on them.

@achow101
Copy link
Contributor Author

achow101 commented May 29, 2018

I worry that there is no way to validate that the pulled docker image (e.g. Debian) hasn't been tampered with. If everybody builds using docker, that will become a single point of potential compromise.

The main information page for the Ubuntu docker images is at https://hub.docker.com/r/_/ubuntu/. This page has links to the repo which contains the stuff for building the ubuntu docker images, including the Ubuntu images from Canonical. So you can clone that repo, build the docker image yourself, and use docker image inspect to verify that the built image matches the one downloaded from the docker image repos.

The only problem with this is that the docker image used is from https://partner-images.canonical.com/core/ which is not where the normal official Ubuntu images are downloaded from.

For debian, the main information page has a section that describes how the images are made deterministically so you can do the same process and then check that the build docker image matches the downloaded one.

To clarify, I contrast this with distribution supplied CD/DVD images, which (I believe) have more eyes on them.

That is certainly the case. I don't think these docker images have as many eyes on them as the normal distributions.


You can also specify a specific image by its SHA256 hash, so you can verify that a particular image is legit, and then just use that one only by specifying its hash.

@devrandom
Copy link
Owner

That's very good to know, thank you.

@@ -34,4 +36,7 @@ case $VMSW in
VBoxManage startvm "Gitian-${2}" --type headless
echo "Gitian-${2}" > var/target.vmname
;;
DOCKER)
docker run -t -d -P --name gitian-target base-$SUFFIX:latest > /dev/null
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why -t - is the pty used somehow?

Why -P - we're not exposing any ports?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-t is necessary for the container to stay up.

-P is not necessary, I have removed it.

bin/make-base-vm Outdated

RUN useradd -ms /bin/bash -U ubuntu
USER ubuntu:ubuntu
WORKDIR /home/ubuntu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that right, or should it be $DISTRO on these three lines instead of ubuntu?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be $DISTRO, fixed.

@achow101 achow101 force-pushed the docker branch 2 times, most recently from f081e69 to 0b44462 Compare May 30, 2018 01:24
FROM $DISTRO:$SUITE

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get --no-install-recommends -y install $addpkg

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to run a dist-upgrade here as well? This seems to be done later by gitian-builder nevertheless, but doing it here as well would speed up the later upgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the base vm image as close to what lxc and kvm modes would generate. AFAICT, they don't do dist-upgrade either.

bin/make-base-vm Outdated
CMD ["/bin/bash"]
EOF

docker build -f $OUT.Dockerfile -t $OUT .

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding --pull here would also speed up later dist-upgrades.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

codablock added a commit to codablock/dash that referenced this pull request May 30, 2018
Requires a gitian-builder version with
devrandom/gitian-builder#181

This will also switch to use Docker by default.
UdjinM6 pushed a commit to dashpay/dash that referenced this pull request May 30, 2018
* gitian-build.sh: fix signProg being recognized as two parameters

* Support docker based Gitian builds

Requires a gitian-builder version with
devrandom/gitian-builder#181

This will also switch to use Docker by default.

* Switch back to using lxc as default until upstream gitian-builder is ready
bin/make-base-vm Outdated
USER $DISTRO:$DISTRO
WORKDIR /home/$DISTRO

CMD ["/bin/bash"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is why there is the -t flag. If you want it to just stay up, why not explicitly have a wait+sleep loop here? It seems cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can do that. The line is supposed to be of the form CMD [“executable”, “param1”, “param2”…]. I don't know how such a loop would be written in that form.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMD ["bash", "-c", "while true; do sleep 1; done"] should work

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you can do CMD ["sleep", "infinity"]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

achow101 added 4 commits May 30, 2018 20:17
make-base-vm can be run with --docker to create a dockerfile and
docker image for the specified arch and suite.
start-target creates and starts a docker container from the image created
by make-base-vm

stop-target stops and removes the docker container from start-target

copy-from-target, copy-to-target, and on-target can execute commands
and copy files to and from the docker container started by start-target.

make-clean-vm does nothing because nothing needs to be done to make a
clean docker container.
Copy link
Owner

@devrandom devrandom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will merge in the next couple of days.

@devrandom
Copy link
Owner

After reading
https://docs.docker.com/engine/security/trust/content_trust/#image-tags-and-content-trust it seems we should provide a way to specify the digest that will go into FROM $DISTRO:$SUITE@$DIGEST.

I'll go ahead and merge this, but would be great if a PR could be submitted for that, and Bitcoin and other Gitian descriptors are updated to specify the digest.

@devrandom devrandom merged commit 27d0130 into devrandom:master May 31, 2018
devrandom added a commit that referenced this pull request May 31, 2018
27d0130 update gitignore for docker (Andrew Chow)
8847ca1 update readme for docker (Andrew Chow)
3934150 Have libexec scripts be able to communicate with a docker container (Andrew Chow)
1ca59fd Option for make-base-vm to create docker image (Andrew Chow)
@achow101
Copy link
Contributor Author

it seems we should provide a way to specify the digest that will go into FROM $DISTRO:$SUITE@$DIGEST.

Well $SUITE could include the digest too, e.g. ubuntu@sha256:b8855dc848e2622653ab557d1ce2f4c34218a9380cceaa51ced85c5f3c8eb201

@devrandom
Copy link
Owner

That may confuse the user, since it will stop working if they switch to another virtualization. Seems like it's virtualization specific, so maybe it should be something like DOCKER_IMAGE_DIGEST.

@devrandom
Copy link
Owner

To be more precise, the Gitian descriptors were meant to be virtualization tech independent.

@achow101
Copy link
Contributor Author

Ah, good point. I will open a PR for that later today or tomorrow.

@devrandom
Copy link
Owner

Great.

andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
* gitian-build.sh: fix signProg being recognized as two parameters

* Support docker based Gitian builds

Requires a gitian-builder version with
devrandom/gitian-builder#181

This will also switch to use Docker by default.

* Switch back to using lxc as default until upstream gitian-builder is ready
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants