This started out as an experiment in running Linux containers on Windows, and it was coming along quite nicely until I got stuck trying to launch the build container. I decided to hold off on debugging it and switched up my game plan so I could put together this post for you all.
Build the Virtual Machine
Technically, you could use any physical or virtual Linux system as long as it supports the prerequisites. I chose to build a new Hyper-V virtual machine running CentOS 7 (1810) and scripted everything out.
You don’t need anything special; just a minimal installation. If you’re using Hyper-V, the following (or something very close to it) will get you started.
$VMName = "CentOS-01" New-VM -Name $VMName -Path "D:\Hyper-V\Virtual Machines" -Generation 2 -MemoryStartupBytes 8GB -SwitchName "Contoso-LAN" -NewVHDPath "D:\Hyper-V\Virtual Hard Disks\$VMName-system.vhdx" -NewVHDSizeBytes 127GB Add-VMDvdDrive -VMName $VMName -Path "E:\Disc Images\CentOS-7-x86_64-Minimal-1810.iso" Set-VMFirmware -VMName $VMName -FirstBootDevice (Get-VMDvdDrive -VMName $VMName) -EnableSecureBoot Off Set-VMMemory -VMName $VMName -DynamicMemoryEnabled $false Start-VM -Name $VMName vmconnect $env:COMPUTERNAME $VMName
Installing Docker couldn’t be much simpler. You’ll use curl to download and execute the installation script. Then you’ll set the Docker service to start on boot. Finally, you’ll start the Docker service.
curl -fsSL https://get.docker.com/ | sh systemctl enable docker systemctl start docker
Download the VyOS Build Repository
All you’re really doing here is pulling down the build scripts from the crux branch, but you’ll need to install the unzip package before unzipping the archive. Then you’ll change into the build directory so we can continue.
curl -O -L https://github.com/vyos/vyos-build/archive/crux.zip yum install unzip unzip crux.zip cd vyos-build-crux
Build the VyOS Build Container
The Dockerfile is in the docker subfolder, so we use the following command to instruct Docker to build the image and tag it vyos-builder. Easy peasy… it just takes a while. Go have a coffee!
docker build -t vyos-builder docker
Run the VyOS Build Container
Now that we have the build container, let’s run it. The –rm parameter instructs Docker to remove the container when we exit. The -it parameter instructs Docker to run the container interactively. The –privileged parameter instructs Docker to run the container with (almost) all the capabilities of the host machine. The -v $(pwd):/vyos parameter instructs Docker to mount the current working directory on the host as /vyos within the container. The -w /vyos parameter instructs Docker to set /vyos as the current working directory within the container. The vyos-builder parameter just tells Docker to run the container image tagged with that value. And finally, the bash parameter instructs Docker to execute the bash command so you’ll have a shell to work with.
docker run --rm -it --privileged -v $(pwd):/vyos -w /vyos vyos-builder bash
Configure the Build
Now that the container is running, you should be at a prompt that looks something like this:
You should already be in the right directory, so configuring the build is as easy as executing the following command.
./configure --architecture amd64 --build-by "email@example.com" --build-type release --version 1.2.0
Build the ISO Image
Now, for the payoff! The following command will build the ISO image. This will also take a while, so top off that coffee and take another break.
You should have a brand spanking new ISO image in the build directory.
[root@centos-01 vyos-build-crux]# ls -l build/vyos-1.2.0-amd64.iso build/live-image-amd64.hybrid.iso -rw-r--r--. 1 root root 378535936 Feb 10 23:32 build/live-image-amd64.hybrid.iso lrwxrwxrwx. 1 root root 27 Feb 10 23:32 build/vyos-1.2.0-amd64.iso -> live-image-amd64.hybrid.iso
Great work! Now fire it up and do your thing!