multipass-compose

This post is about “real” virtual machines, not container-based virtualization. So the “you can just stuff it into Docker” reflex doesn’t quite apply here.

Building cloud services means we constantly use virtual machines. In production, type-1 hypervisors — the kind that, simply put, run on bare metal; on our local machines, type-2, the familiar ones — VirtualBox, qemu, and possibly Parallels Desktop.

When a lot of developers moved to the new M1 chips from a certain fruit company, we found ourselves needing a replacement for VirtualBox and our indispensable vagrant tool. The reason is simple: there’s currently no way to run an x86_64 VM inside vagrant on an aarch64 machine.

It matters to us that we can verify the manifests we write for deploying new cloud services locally — before we push them to source control and wait for the CI pipeline.

The simple solution turned out to be multipass, a project from Canonical — the company behind Ubuntu. It runs on familiar Intel CPUs and on the new M1s alike. Under the hood it can use whichever hypervisor fits: VirtualBox, qemu, or hyperkit. That solves the architecture compatibility problem.

But our installations more often than not use multiple machines, not just one. We needed a way to start and stop several VMs at the same time to mimic a real system on a work laptop.

That’s how the idea for multipass-compose came about — a sort of docker-compose analogue that orchestrates multiple machines in a local environment. The project is still at a very early stage, but we’re already using it during development.

Links to all the projects and a separate repository with usage examples for multipass-compose are at the end of the post.

Here’s a short usage guide for the tool.

It all starts with a multipass-compose.yaml manifest that describes the virtual machines you need. For brevity I’ll skip the optional cpu, mem, disk parameters, as well as cloud-init which lets you pass in a user-data section:

services:
  web-server:
    image: focal
  database:
    image: focal
  backend:
    image: focal

All machines are started with a single command:

multipass-compose up

Stopping and fully removing the VMs is done with down:

multipass-compose down

The ip command lets you look up the IP address assigned to a VM, which comes in handy when generating dynamic inventory for ansible:

multipass-compose ip <name>

Thanks to this tool, we can now verify our manifests and the services that manage them in the local development environment.

multipass-compose is in an early stage of development and adoption — stay tuned for further updates.

References