GitXplorerGitXplorer
r

docker-vagrant_libvirt_virtualbox

public
5 stars
3 forks
0 issues

Commits

List of commits on branch master.
Unverified
77f9a088328ee0f41c6027770d113eb2eaf33b9e

Add comment to .markdownlint.yml

rruzickap committed 5 years ago
Unverified
698e6d96face8b696068a84bf8253b86cc843fa7

Add comments to .hadolint.yaml

rruzickap committed 5 years ago
Unverified
bb12d21020cc3b2e47449b2dc9ad51bd3a8afd9b

Add .pre-commit-config.yaml to .gitignore

rruzickap committed 5 years ago
Unverified
0ad5065ce87a2173f43fcf627f3271289c1e8113

Remove entrypoint.sh from docker-image.yml, add shellcheck

rruzickap committed 5 years ago
Unverified
405c4d2e5b40b15f034100f77645869c4959ab5a

Add GitHub Actions

rruzickap committed 5 years ago
Unverified
b795e442d480725dafb7ee7a291c48727e53b242

Fix README to pass the markdownlint

rruzickap committed 5 years ago

README

The README file for this repository.

Dockerfile with Vagrant QEMU and VirtualBox

Docker Hub; peru/vagrant_libvirt_virtualbox Docker pulls Docker Build

This repository provides Dockerfile which can run Vagrant (including vagrant-libvirt and vagrant-winrm plugins) to start / manipulate VM images.

The docker image is primary created for testing Vagrant images built from Packer Templates located in this repository https://github.com/ruzickap/packer-templates.

Installation steps

To use this Docker image you need to install VirtualBox and Docker to your OS (Fedora / Ubuntu). This may work on other operating systems too, but I didn't have a chance to test it.

Ubuntu installation steps (Docker + VirtualBox)

sudo apt update
sudo apt install -y --no-install-recommends docker.io jq libvirt-bin virtualbox wget
sudo gpasswd -a ${USER} docker
# This is mandatory for Ubuntu otherwise docker container will not have access to /dev/kvm - this is default in Fedora (https://bugzilla.redhat.com/show_bug.cgi?id=993491)
sudo bash -c "echo 'KERNEL==\"kvm\", GROUP=\"kvm\", MODE=\"0666\"' > /etc/udev/rules.d/60-qemu-system-common.rules"
sudo sed -i 's/^unix_sock_/#&/' /etc/libvirt/libvirtd.conf
sudo reboot

Fedora installation steps (Docker + VirtualBox)

sudo sed -i 's@^SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config
sudo dnf upgrade -y
# Reboot if necessary (especially if you upgrade the kernel or related packages)

sudo dnf install -y http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install -y akmod-VirtualBox curl docker git jq kernel-devel-$(uname -r) libvirt-daemon-kvm wget
sudo akmods

sudo bash -c 'echo "vboxdrv" > /etc/modules-load.d/vboxdrv.conf'
sudo usermod -a -G libvirt ${USER}
sudo groupadd docker && sudo gpasswd -a ${USER} docker
sudo systemctl enable docker

sudo reboot

Test box image created from Packer templates

Real example how to use the Docker image to test box image produced by Packer for libvirt/qemu.

BOXES="windows-10-enterprise-x64-eval ubuntu-18.04-server-amd64"

mkdir vagrant_box
cd vagrant_box

for BOX in $BOXES; do
  CURRENT_VERSION=$(curl -s https://app.vagrantup.com/api/v1/box/peru/$BOX | jq -r ".current_version.version")
  wget -c https://app.vagrantup.com/peru/boxes/$BOX/versions/$CURRENT_VERSION/providers/libvirt.box -O ${BOX}-libvirt.box
  wget -c https://app.vagrantup.com/peru/boxes/$BOX/versions/$CURRENT_VERSION/providers/virtualbox.box -O ${BOX}-virtualbox.box
done

docker pull peru/vagrant_libvirt_virtualbox

docker run --rm -t -u $(id -u):$(id -g) --privileged --net=host \
-e HOME=/home/docker \
-v /dev/vboxdrv:/dev/vboxdrv \
-v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock \
-v $PWD:/home/docker/vagrant \
peru/vagrant_libvirt_virtualbox "set -x \
&& vagrant box add windows-10-enterprise-x64-eval-libvirt.box --name=windows-10-enterprise-x64-eval-libvirt --force \
&& vagrant init windows-10-enterprise-x64-eval-libvirt \
&& vagrant up --provider libvirt \
&& vagrant winrm --shell cmd --command 'systeminfo | findstr /B /C:\"OS Name\" /C:\"OS Version\"' \
&& vagrant destroy --force \
&& vagrant box remove windows-10-enterprise-x64-eval-libvirt \
&& virsh --connect=qemu:///system vol-delete --pool default --vol windows-10-enterprise-x64-eval-libvirt_vagrant_box_image_0.img \
&& rm -rvf Vagrantfile .vagrant"

docker run --rm -t -u $(id -u):$(id -g) --privileged --net=host \
-e HOME=/home/docker \
-v /dev/vboxdrv:/dev/vboxdrv \
-v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock \
-v $PWD:/home/docker/vagrant \
peru/vagrant_libvirt_virtualbox "set -x \
&& vagrant box add windows-10-enterprise-x64-eval-virtualbox.box --name=windows-10-enterprise-x64-eval-virtualbox --force \
&& vagrant init windows-10-enterprise-x64-eval-virtualbox \
&& sed -i '/config.vm.box =/a \ \ config.vm.provider \"virtualbox\" do |v|\n \ \ \ v.gui = false\n\ \ end' Vagrantfile \
&& vagrant up --provider virtualbox \
&& vagrant winrm --shell cmd --command 'systeminfo | findstr /B /C:\"OS Name\" /C:\"OS Version\"' \
&& vagrant destroy --force \
&& vagrant box remove windows-10-enterprise-x64-eval-virtualbox \
&& rm -rvf Vagrantfile .vagrant"

docker run --rm -t -u $(id -u):$(id -g) --privileged --net=host \
-e HOME=/home/docker \
-v /dev/vboxdrv:/dev/vboxdrv \
-v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock \
-v $PWD:/home/docker/vagrant \
peru/vagrant_libvirt_virtualbox "set -x \
&& vagrant box add ubuntu-18.04-server-amd64-libvirt.box --name=ubuntu-18.04-server-amd64-libvirt --force \
&& vagrant init ubuntu-18.04-server-amd64-libvirt \
&& vagrant up --provider libvirt \
&& vagrant ssh --command 'grep PRETTY_NAME /etc/os-release; id' \
&& vagrant destroy --force \
&& vagrant box remove ubuntu-18.04-server-amd64-libvirt \
&& virsh --connect=qemu:///system vol-delete --pool default --vol ubuntu-18.04-server-amd64-libvirt_vagrant_box_image_0.img \
&& rm -rf Vagrantfile .vagrant"

docker run --rm -t -u $(id -u):$(id -g) --privileged --net=host \
-e HOME=/home/docker \
-v /dev/vboxdrv:/dev/vboxdrv \
-v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock \
-v $PWD:/home/docker/vagrant \
peru/vagrant_libvirt_virtualbox "set -x \
&& vagrant box add ubuntu-18.04-server-amd64-virtualbox.box --name=ubuntu-18.04-server-amd64-virtualbox --force \
&& vagrant init ubuntu-18.04-server-amd64-virtualbox \
&& sed -i '/config.vm.box =/a \ \ config.vm.provider \"virtualbox\" do |v|\n \ \ \ v.gui = false\n\ \ end' Vagrantfile \
&& vagrant up --provider virtualbox \
&& vagrant ssh --command 'grep PRETTY_NAME /etc/os-release; id' \
&& vagrant destroy --force \
&& vagrant box remove ubuntu-18.04-server-amd64-virtualbox \
&& ls -la && pwd \
&& rm -rvf Vagrantfile .vagrant"