Creating computing and development environments will be an essential skill for software engineering. Unfortunately, consistently getting software installed on a your computer and correctly setting up the environments can take away weeks of your productive time.
Virtual machines/containers can provide a useful solution for automating the creation and management of your computing environment and development workflow. Unfortunately, when developers think about virtual machines, a common idea that comes to mind is a dedicated heavy-weight virtualized system with a full graphics Desktop. Alternatively, you may think of dual-booted systems. While these types of systems can be useful, the goal of this workshop is to introduce you to a different concept for software development.
A philosophy: Be able to throw away your machine and still code
Code that only runs on your machine is useful to no one else
With computing environments, we are able to automate the specification of our environment for running our code, which makes it easier for us to recreate and share our computing environments with others on a new machine.
To use a computing environment, you can use your host operating system to write code, interact with the running program, and visualize its executions. But you avoid execution code on your own machine itself—that all happens inside the computing environment.
Computing environments are for running code, not writing code.
To accomplish this, we use a set of tools to enable you to map files and program between your host environment and computing environment.
Setting up Virtualization
VirtualBox is a lightweight virtualization provider. It is very effective for creating headless virtual machines that run without any GUI/Desktop interface.
virtualboxrequires a kernel extension to work. If the installation fails, retry after you enable it in: System Preferences → Security & Privacy → General
Ensure virtualization is enabled
To be able to run virtual machines, your machine needs to support virtualization. Ensure virtualization (Intel VT-x or AMD-V) is enabled on your system using the instructions for your operating system:
Windows: open Task Manager and go to Performance tab, and you should see virtualization is enabled.
Mac: run the command below to see the list of supported CPU flags. If you see VMX, your machine supports hardware virtualization:[command:]
Linux: run the command below to see the list of supported CPU flags. If you see VMX or SVM flag, youre machine supports hardware virtualization:
grep -E "vmx|svm" /proc/cpuinfo
Debugging virtualization issues
Windows: If you’re running Hyper-V and VirtualBox, and you’re experiencing crashes when you try to start a VM, you may need to turn off Hyper-V (which exclusively locks use of CPU for virtualization).
Linux: If you run
vboxmanage list vmscommand and you get
WARNING: The vboxdrv kernel module is not loaded...error, see the dicussion here for how to fix it.
Creating a Virtual Machine
While it is possible to use the VirtualBox GUI to manually install a virtual machine (and run through the OS installation script); this is not an effective automation approach!
bakerx is a simple tool for creating and managing virtual machines.
First, you need to pull an existing virtual machine image from a registry. Registries are basically the assets in a GitHub repository releases. Then you can pull an image by running the following commands:
See slim for instructions on how to create and publish an image.
After pulling images, you can create VMs that run those images. Simply run the command below:
--memory | -mflag is optional, and can be used to set the amount of shared memory with your virtual machine.
Connecting to VMs
Finally, bakerx will give you an
ssh command similar to what is shown below, which you can use to connect to the VM.
When you’re done, you can stop and delete the VM.