Browse Source

Merge #181: Add the option to use docker containers

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)
pull/185/head
Devrandom 4 years ago
parent
commit
4703d74479
No known key found for this signature in database
GPG Key ID: E3AAB28B27F5CF4A
  1. 2
      .gitignore
  2. 13
      README.md
  3. 32
      bin/make-base-vm
  4. 4
      libexec/copy-from-target
  5. 5
      libexec/copy-to-target
  6. 5
      libexec/make-clean-vm
  7. 4
      libexec/on-target
  8. 5
      libexec/start-target
  9. 6
      libexec/stop-target

2
.gitignore vendored

@ -11,3 +11,5 @@ base* @@ -11,3 +11,5 @@ base*
sigs
target-bin/bootstrap-fixup
.vagrant
docker
*.Dockerfile

13
README.md

@ -48,6 +48,10 @@ If you'd like to use LXC mode instead, install it as follows: @@ -48,6 +48,10 @@ If you'd like to use LXC mode instead, install it as follows:
sudo apt-get install lxc
If you'd like to use docker mode instead, install it as follows:
sudo apt-get install docker-ce
### Debian:
See Ubuntu, and also run the following on Debian Jessie or newer:
@ -101,6 +105,15 @@ Set the `USE_LXC` environment variable to use `LXC` instead of `KVM`: @@ -101,6 +105,15 @@ Set the `USE_LXC` environment variable to use `LXC` instead of `KVM`:
export USE_LXC=1
### Docker
bin/make-base-vm --docker
bin/make-base-vm --docker --arch i386
Set the `USE_DOCKER` environment variable to use `DOCKER` instead of `KVM`:
export USE_DOCKER=1
### VirtualBox
Command-line `VBoxManage` must be in your `$PATH`.

32
bin/make-base-vm

@ -7,6 +7,7 @@ ARCH=amd64 @@ -7,6 +7,7 @@ ARCH=amd64
MIRROR_BASE=http://${MIRROR_HOST:-127.0.0.1}:3142
LXC=0
VBOX=0
DOCKER=0
usage() {
echo "Usage: ${0##*/} [OPTION]..."
@ -19,6 +20,7 @@ usage() { @@ -19,6 +20,7 @@ usage() {
--arch A build architecture A (e.g. i386) instead of amd64
--lxc use lxc instead of kvm
--vbox use VirtualBox instead of kvm
--docker use docker instead of kvm
The MIRROR_HOST environment variable can be used to change the
apt-cacher host. It should be something that both the host and the
@ -70,6 +72,10 @@ if [ $# != 0 ] ; then @@ -70,6 +72,10 @@ if [ $# != 0 ] ; then
VBOX=1
shift 1
;;
--docker)
DOCKER=1
shift 1
;;
--*)
echo "unrecognized option $1"
exit 1
@ -153,6 +159,32 @@ fi @@ -153,6 +159,32 @@ fi
# Remove cron to work around vmbuilder issue when umounting /dev on target
removepkg=cron
if [ $DOCKER = "1" ]; then
addpkg=`echo $addpkg | tr ',' ' '`
mkdir -p docker
cd docker
# Generate the dockerfile
cat << EOF > $OUT.Dockerfile
FROM $DISTRO:$SUITE
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get --no-install-recommends -y install $addpkg
RUN useradd -ms /bin/bash -U $DISTRO
USER $DISTRO:$DISTRO
WORKDIR /home/$DISTRO
CMD ["sleep", "infinity"]
EOF
docker build --pull -f $OUT.Dockerfile -t $OUT .
exit 0
fi
if [ $VBOX = "1" ]; then
NAME="$SUITE-$ARCH"
if ! vagrant status | grep "$NAME" | grep "not created" > /dev/null; then

4
libexec/copy-from-target

@ -46,7 +46,9 @@ if [ $# = 0 ] ; then @@ -46,7 +46,9 @@ if [ $# = 0 ] ; then
exit 1
fi
if [ -z "$USE_LXC" ]; then
if [ -n "$USE_DOCKER" ]; then
docker cp gitian-target:"/home/$TUSER/$1" $2
elif [ -z "$USE_LXC" ]; then
src="${1%/}" # remove trailing / which triggers special rsync behaviour
rsync --checksum -a $QUIET_FLAG -e "ssh -oConnectTimeout=30 -oNoHostAuthenticationForLocalhost=yes -i ${GITIAN_BASE:-.}/var/id_rsa -p $VM_SSH_PORT" "$TUSER@localhost:${src}" "$2"
else

5
libexec/copy-to-target

@ -46,7 +46,10 @@ if [ $# = 0 ] ; then @@ -46,7 +46,10 @@ if [ $# = 0 ] ; then
exit 1
fi
if [ -z "$USE_LXC" ]; then
if [ -n "$USE_DOCKER" ]; then
docker exec -u $TUSER gitian-target mkdir -p "/home/$TUSER/$2"
docker cp "$1" gitian-target:"/home/$TUSER/$2"
elif [ -z "$USE_LXC" ]; then
src="${1%/}" # remove trailing / which triggers special rsync behaviour
rsync --checksum -a $QUIET_FLAG -e "ssh -oConnectTimeout=30 -oNoHostAuthenticationForLocalhost=yes -i ${GITIAN_BASE:-.}/var/id_rsa -p $VM_SSH_PORT" "${src}" "$TUSER@localhost:$2"
else

5
libexec/make-clean-vm

@ -9,6 +9,8 @@ if [ -n "$USE_LXC" ]; then @@ -9,6 +9,8 @@ if [ -n "$USE_LXC" ]; then
VMSW=LXC
elif [ -n "$USE_VBOX" ]; then
VMSW=VBOX
elif [ -n "$USE_DOCKER" ]; then
VMSW=DOCKER
fi
usage() {
@ -66,4 +68,7 @@ case $VMSW in @@ -66,4 +68,7 @@ case $VMSW in
VBOX)
VBoxManage snapshot "Gitian-${SUITE}-${ARCH}" restore "Gitian-Clean"
;;
DOCKER)
true #Docker doesn't need to do anything
;;
esac

4
libexec/on-target

@ -46,7 +46,9 @@ fi @@ -46,7 +46,9 @@ fi
# exit 1
#fi
if [ -z "$USE_LXC" ]; then
if [ -n "$USE_DOCKER" ]; then
docker exec -u $TUSER -i gitian-target $*
elif [ -z "$USE_LXC" ]; then
ssh -oConnectTimeout=30 -oNoHostAuthenticationForLocalhost=yes -i ${GITIAN_BASE:-.}/var/id_rsa -p $VM_SSH_PORT $TUSER@localhost $*
else
config-lxc

5
libexec/start-target

@ -10,6 +10,8 @@ if [ -n "$USE_LXC" ]; then @@ -10,6 +10,8 @@ if [ -n "$USE_LXC" ]; then
VMSW=LXC
elif [ -n "$USE_VBOX" ]; then
VMSW=VBOX
elif [ -n "$USE_DOCKER" ]; then
VMSW=DOCKER
fi
case $VMSW in
@ -34,4 +36,7 @@ case $VMSW in @@ -34,4 +36,7 @@ case $VMSW in
VBoxManage startvm "Gitian-${2}" --type headless
echo "Gitian-${2}" > var/target.vmname
;;
DOCKER)
docker run -d --name gitian-target base-$SUFFIX:latest > /dev/null
;;
esac

6
libexec/stop-target

@ -5,6 +5,8 @@ if [ -n "$USE_LXC" ]; then @@ -5,6 +5,8 @@ if [ -n "$USE_LXC" ]; then
VMSW=LXC
elif [ -n "$USE_VBOX" ]; then
VMSW=VBOX
elif [ -n "$USE_DOCKER" ]; then
VMSW=DOCKER
fi
case $VMSW in
@ -30,4 +32,8 @@ case $VMSW in @@ -30,4 +32,8 @@ case $VMSW in
VBoxManage controlvm `cat var/target.vmname` savestate
rm var/target.vmname
;;
DOCKER)
docker container stop gitian-target > /dev/null
docker container rm gitian-target > /dev/null
;;
esac

Loading…
Cancel
Save