Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ base*
sigs
target-bin/bootstrap-fixup
.vagrant
docker
*.Dockerfile
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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`.
Expand Down
32 changes: 32 additions & 0 deletions bin/make-base-vm
Original file line number Diff line number Diff line change
Expand Up @@ -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]..."
Expand All @@ -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
Expand Down Expand Up @@ -70,6 +72,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

shift 1
;;
--*)
echo "unrecognized option $1"
exit 1
Expand Down Expand Up @@ -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

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.


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
Expand Down
4 changes: 3 additions & 1 deletion libexec/copy-from-target
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion libexec/copy-to-target
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions libexec/make-clean-vm
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 changes: 3 additions & 1 deletion libexec/on-target
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions libexec/start-target
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 changes: 6 additions & 0 deletions libexec/stop-target
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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