Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: YungSang/boot2docker-vagrant-box
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: yungsang/v0.6.0
Choose a base ref
...
head repository: YungSang/boot2docker-vagrant-box
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: classic
Choose a head ref
Loading
Showing with 423 additions and 53 deletions.
  1. +0 −1 .gitignore
  2. +75 −6 Makefile
  3. +16 −6 README.md
  4. +118 −0 contrib/resize4docker
  5. +4 −9 files/bootlocal.sh
  6. +26 −0 files/bootsync.sh
  7. +6 −0 files/oem-release
  8. +57 −9 template.json
  9. +43 −0 test/Dockerfile
  10. +32 −0 test/Vagrantfile
  11. +46 −0 vagrantfile.tpl
  12. +0 −22 vagrantfile_virtualbox.tpl
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -2,5 +2,4 @@
packer_cache/
*.box
*.iso
Vagrantfile
.vagrant
81 changes: 75 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,81 @@
boot2docker.box: boot2docker.iso template.json vagrantfile_virtualbox.tpl files/*
packer build template.json
all: boot2docker-virtualbox.box boot2docker-parallels.box

boot2docker.iso:
curl -LO https://github.com/steeve/boot2docker/releases/download/v0.6.0/boot2docker.iso
virtualbox: boot2docker-virtualbox.box

parallels: boot2docker-parallels.box

boot2docker-virtualbox.box: boot2docker.iso template.json vagrantfile.tpl \
files/bootlocal.sh files/bootsync.sh files/docker-enter files/oem-release
packer build -only virtualbox template.json

boot2docker-parallels.box: boot2docker.iso template.json vagrantfile.tpl \
files/bootlocal.sh files/bootsync.sh files/docker-enter files/oem-release
packer build -only parallels template.json

#boot2docker.iso:
# curl -LO https://github.com/YungSang/boot2docker/releases/download/yungsang%2Fv1.4.1/boot2docker.iso

files/docker-enter:
curl -L https://raw.githubusercontent.com/YungSang/docker-attach/master/docker-nsenter -o files/docker-enter

test: test/Vagrantfile boot2docker-virtualbox.box
@vagrant box add -f boot2docker boot2docker-virtualbox.box
@cd test; \
vagrant destroy -f; \
vagrant up; \
echo "-----> /etc/os-release"; \
vagrant ssh -c "cat /etc/os-release"; \
echo "-----> /etc/oem-release"; \
vagrant ssh -c "cat /etc/oem-release"; \
echo "-----> docker version"; \
DOCKER_HOST="tcp://localhost:2375"; \
docker version; \
echo "-----> docker images -t"; \
docker images -t; \
echo "-----> docker ps -a"; \
docker ps -a; \
echo "-----> nc localhost 8080"; \
nc localhost 8080; \
echo '-----> docker-enter `docker ps -l -q` ls -l'; \
vagrant ssh -c 'docker-enter `docker ps -l -q` ls -l'; \
echo '-----> docker exec `docker ps -l -q` ls -l'; \
docker exec `docker ps -l -q` ls -l; \
vagrant suspend

ptest: DOCKER_HOST_IP=$(shell cd test; vagrant ssh-config | sed -n "s/[ ]*HostName[ ]*//gp")
ptest: ptestup
@cd test; \
echo "-----> /etc/os-release"; \
vagrant ssh -c "cat /etc/os-release"; \
echo "-----> /etc/oem-release"; \
vagrant ssh -c "cat /etc/oem-release"; \
DOCKER_HOST="tcp://${DOCKER_HOST_IP}:2375"; \
echo "-----> docker version"; \
docker version; \
echo "-----> docker images -t"; \
docker images -t; \
echo "-----> docker ps -a"; \
docker ps -a; \
echo "-----> nc ${DOCKER_HOST_IP} 8080"; \
nc ${DOCKER_HOST_IP} 8080; \
echo '-----> docker-enter `docker ps -l -q` ls -l'; \
vagrant ssh -c 'docker-enter `docker ps -l -q` ls -l'; \
echo '-----> docker exec `docker ps -l -q` ls -l'; \
docker exec `docker ps -l -q` ls -l; \
vagrant suspend

ptestup: test/Vagrantfile boot2docker-parallels.box
@vagrant box add -f boot2docker boot2docker-parallels.box
@cd test; \
vagrant destroy -f; \
vagrant up --provider parallels

clean:
cd test; vagrant destroy -f
rm -f boot2docker.iso
rm -f *.box
rm -f files/docker-enter
rm -f boot2docker-virtualbox.box
rm -f boot2docker-parallels.box
rm -rf output-*/

.PHONY: clean
.PHONY: test clean
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# boot2docker Vagrant Box

This repository contains the scripts necessary to create a Vagrant-compatible
[boot2docker](https://github.com/steeve/boot2docker) box. If you work solely
[boot2docker](https://github.com/boot2docker/boot2docker) box. If you work solely
with Docker, this box lets you keep your Vagrant workflow and work in the
most minimal Docker environment possible.

## Usage

If you just want to use the box, then download the latest box from
the [releases page](https://github.com/mitchellh/boot2docker-vagrant-box/releases)
the [releases page](https://github.com/YungSang/boot2docker-vagrant-box/releases)
and `vagrant up` as usual! Or, if you don't want to leave your terminal:

$ vagrant init boot2docker https://github.com/mitchellh/boot2docker-vagrant-box/releases/download/v0.3.0/boot2docker.box
$ vagrant init yungsang/boot2docker
$ vagrant up
$ export DOCKER_HOST=tcp://localhost:2375
$ docker version

![Vagrant Up Boot2Docker](https://raw.github.com/mitchellh/boot2docker-vagrant-box/master/readme_image.gif)
![Vagrant Up Boot2Docker](https://raw.github.com/YungSang/boot2docker-vagrant-box/master/readme_image.gif)

## Building the Box

@@ -24,8 +26,16 @@ do it in seconds.

To build the box, first install the following prerequisites:

* [Packer](http://www.packer.io) (at least version 0.5.1)
* [Packer](http://www.packer.io) (at least version 0.5.2, 0.6.1 for Parallels)
* [VirtualBox](http://www.virtualbox.org)

Then, just run `make`. The resulting box will be named "boot2docker.box".
Then, just run `make`. The resulting box will be named `boot2docker-virtualbox.box` and `boot2docker-parallels.box`.
The entire process to make the box takes about 20 seconds.

## License

[![CC0](http://i.creativecommons.org/p/zero/1.0/88x31.png)](http://creativecommons.org/publicdomain/zero/1.0/)
To the extent possible under law, the person who associated CC0 with this work has waived all copyright and related or neighboring rights to this work.

- [boot2docker](http://boot2docker.io/) is under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0).
- [Vagrant](http://www.vagrantup.com/): Copyright (c) 2010-2014 Mitchell Hashimoto, under the [MIT License](https://github.com/mitchellh/vagrant/blob/master/LICENSE)
118 changes: 118 additions & 0 deletions contrib/resize4docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash

GREEN=""
RED=""
CLEAR=""

print_usage() {
echo "Usage: $(basename $0) [Vagrant Machine Name] [Size in MB]"
if [ -n "$1" ] ; then
echo
echo -e "${RED}$1${CLEAR}"
fi
}

# Check parameters
NAME="default"
SIZE=""
if [ -n "$1" ] ; then
if expr "$1" : '[0-9]*' > /dev/null ; then
NAME="default"
SIZE="$1"
else
NAME="$1"
fi
fi
if [ -n "$2" ] ; then
if expr "$2" : '[0-9]*' > /dev/null ; then
SIZE="$2"
else
print_usage "The Size parameter must be a numeric value in MB." >&2
exit 1
fi
fi

# Get UUID of VM
ID_FILE="./.vagrant/machines/${NAME}/virtualbox/id"
if [ ! -f "${ID_FILE}" ] ; then
print_usage "Please execute in the folder alongside Vagrantfile with \"${NAME}\"." >&2
exit 1
fi
UUID=$(cat ${ID_FILE})

# Get VMDK
VMDK_DISK_PATH=""
output=$(VBoxManage showvminfo ${UUID} --machinereadable | grep "SATA Controller-0-0")
pattern='^"SATA Controller-0-0"="(.+)"'
if [[ "${output}" =~ ${pattern} ]] ; then
VMDK_DISK_PATH=${BASH_REMATCH[1]}
fi
if [ -z "${VMDK_DISK_PATH}" -o "${VMDK_DISK_PATH}" == "none" ] ; then
print_usage "No HDD in the machine \"${NAME}\"." >&2
exit 1
fi

# Set VDI
VDI_DISK_PATH="${VMDK_DISK_PATH%.*}.vdi"

DONE=false

if [ "${VMDK_DISK_PATH}" != "${VDI_DISK_PATH}" ] ; then
echo -e "${GREEN}Stopping the VM...${CLEAR}"
# Resume VM if it's suspended. Otherwise, the pertition may be broken.
vagrant resume "${NAME}" > /dev/null 2>&1
vagrant halt "${NAME}"
# Must wait to shutdown completely
sleep 5

echo -e "${GREEN}Replacing VMDK with VDI...${CLEAR}"
# Convert VMDK to VDI
VBoxManage clonehd "${VMDK_DISK_PATH}" "${VDI_DISK_PATH}" --format VDI --variant Standard

# Detach VMDK
VBoxManage storageattach "${UUID}" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium none

# Delete VMDK
VBoxManage closemedium disk "${VMDK_DISK_PATH}" --delete

# Attach VDI
VBoxManage storageattach "${UUID}" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "${VDI_DISK_PATH}"

DONE=true
fi

if [ -n "${SIZE}" ] ; then
if ! $DONE ; then
echo -e "${GREEN}Stopping the VM...${CLEAR}"
# Resume VM if it's suspended. Otherwise, the pertition may be broken.
vagrant resume "${NAME}" > /dev/null 2>&1
vagrant halt "${NAME}"
# Must wait to shutdown completely
sleep 5
fi

echo -e "${GREEN}Resizing the disk...${CLEAR}"
VBoxManage modifyhd "${VDI_DISK_PATH}" --resize "${SIZE}"
if [ $? -ne 0 ] ; then
print_usage "You may set a wrong number as the Size parameter. It can't shrink a disk." >&2
exit 1
fi

echo -e "${GREEN}Boot and Re-partitioning...${CLEAR}"
vagrant up "${NAME}" > /dev/null
vagrant ssh -c "sudo umount -l /mnt/sda1; (echo d; echo 1; echo w) | sudo fdisk /dev/sda; (echo n; echo p; echo 1; echo; echo; echo w) | sudo fdisk /dev/sda" "${NAME}" > /dev/null 2>&1

echo -e "${GREEN}Reboot and Resizing the partition...${CLEAR}"
vagrant reload "${NAME}" > /dev/null
vagrant ssh -c "tce-load -w -i e2fsprogs && sudo resize2fs /dev/sda1" > /dev/null 2>&1

DONE=true
fi

if $DONE ; then
vagrant up "${NAME}" > /dev/null
echo -e "${GREEN}Complete successfully${CLEAR}"
else
echo -e "${RED}Nothing to do${CLEAR}" >&2
exit 1
fi
13 changes: 4 additions & 9 deletions files/bootlocal.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#!/bin/sh

mkdir -p /home/docker/.ssh
chmod 0700 /home/docker/.ssh

cat <<KEY >/home/docker/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
KEY
chmod 0600 /home/docker/.ssh/authorized_keys

chown -R docker:staff /home/docker/.ssh
if [ -e /var/lib/boot2docker/bin/docker-enter ] ; then
ln -s /var/lib/boot2docker/bin/docker-enter /usr/local/bin/docker-enter
ln -s /var/lib/boot2docker/bin/docker-enter /usr/local/bin/docker-attach
fi
26 changes: 26 additions & 0 deletions files/bootsync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

# Place oem-release in /etc
ln -s /var/lib/boot2docker/oem-release /etc/oem-release

mkdir -p /home/docker/.ssh
chmod 0700 /home/docker/.ssh

cat <<KEY >/home/docker/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
KEY
chmod 0600 /home/docker/.ssh/authorized_keys

chown -R docker:staff /home/docker/.ssh

# Start NFS client for NFS synced folder
if [ -x /usr/local/etc/init.d/nfs-client ]; then
/usr/local/etc/init.d/nfs-client start
fi

# Place docker in /usr/bin for guest capability check
ln -s /usr/local/bin/docker /usr/bin/docker

# Load the vboxsf module
modprobe vboxguest
modprobe vboxsf
6 changes: 6 additions & 0 deletions files/oem-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ID=boot2docker
NAME="Boot2Docker.box for Vagrant"
VERSION_ID=1.4.1
HOME_URL="https://vagrantcloud.com/yungsang/boot2docker"
SUPPORT_URL="https://github.com/YungSang/boot2docker-vagrant-box"
BUG_REPORT_URL="https://github.com/YungSang/boot2docker-vagrant-box/issues"
Loading