Testing software targeting Ubuntu with multipass


If you a regular reader of my blog, you're probably across the fact that my primary system is Ubuntu (Linux). When developing, we test our software to make sure everything is working as expected - especially if we want other users to install it, you may have some software installed on your system that other users don't have. So it's a good idea to test in a "clean" environment.


One strategy is with Docker - you can just boot up a docker container and run your scripts:

docker run -it ubuntu:latest


This will put you in a new shell where you can begin trying out your software, or install instructions to make sure there's nothing missing.


Docker however is not the purpose of this article - so on to multipass. Mutlipass is a tool to fire up instances of Ubuntu - it's the technology that snapcraft uses when building snaps. The GitHub repo for the projects describes it best:

Multipass is a lightweight VM manager for Linux, Windows and macOS. It's designed for developers who want a fresh Ubuntu environment with a single command. It uses KVM on Linux, Hyper-V on Windows and HyperKit on macOS to run the VM with minimal overhead. It can also use VirtualBox on Windows and macOS. Multipass will fetch images for you and keep them up to date.

So, first we need to install it. This is done with:

sudo snap install multipass --beta --classic


If you are on another system such as Windows or Mac, you can download the installer directly from the products' website.

So, first thing you will want to do is decide on which version of Ubuntu you would like to run. You can get a list of available versions with the command

multipass find




Once you settle on a version you'd like to target, you would run

mutlipass launch <imagename> 


If you notice the help output for launch, you will see that you can restrict the resources allocated to the VM - disk, CPU, memory.

If you reference "ubuntu" for imagename, it would be the current LTS. Similarly, if you omit the imagename, it would be the current LTS.

Assuming you haven't previously pulled the image, this could take some time (at least in my experience - it took over 30 minutes to pull the current LTS).

Once that is complete, you will have a running instance in the background. When you launch an instance, it is allocated a name. In my first case, it was allocated beaming-gnatcatcher. This is so that I can control it by an easy idenitifiable name. You could have also allocated your own name with the argument
-n|--name
.


So now, to actually run commands on the system you can either connect to the machines console, or pass commands in one by one.

You connect in with the
shell
command. You will notice that the user is
multipass

and thus
 
$HOME=/home/multipass




Or if you want to build a script that just runs commands one by one, you would use the
 
exec image -- command




One other scenario you will probably want to do is copy files across to the image. This is easily done with the transfer command. Depending on the direction you are transferring the file, you would prefix the file path with the name of the image, like so:

multipass transfer daemon.json beaming-gnatcatcher:/home/multipass/daemon.json


And of course, the other option is just to mount a path from your host into the VM. Here we use the mount command.

multipass mount /home/trent beaming-gnatcatcher:/home/trent


Finally, to wrap up - you would want to delete, at least stop your images to save resources. Do this by the delete and purge commands.


Popular posts from this blog

Report row buttons firing a dynamic action

Accessing the last request value from a page submission

Installing Oracle Instant Client on Ubuntu