Mirage Unikernel build via Docker
As part of due diligence before introducing OCaml to our company, Iāve been building this site and exploring what OCaml has to offer on a lot of fronts. Now that I have a basic (sometimes terribly painful) flow in place, Iāve wanted to move on to slimming it down quite a bit. Especially the Mirage build + deploy process. Right now it looks like this:
- Dev on OSX (for minutes, hours, days, weeks) until happy with the changes
- Git push everything to master
- Start up VirtualBox, ssh in
- Type
historyto find the previous incantation - Build Xen artifacts
scpartifacts to an EC2 build machine- ssh into build machine.
- Run a deploy script to turn the Xen artifacts into a running server
- Clean up left over EC2 resources
As nice as the idea is that I can ājust developā Mirage apps on OSX, itās actually not quite true. Particularly as a beginner, itās easy to add a package as a dependency, and get stuck in a loop between steps 1 (which could be a long time depending on what Iām hacking on) and 3, as you find out that - aha! - the package isnāt compatible with the Mirage stack (usually because of the dreaded unix transitive dependency).
Not only that, but I have quite a few pinned packages at this point, and I build everything in step 3 in a carefully hand-crafted virtualbox machine. The idea of manually keeping my own dev envs in sync (much less coworkers!) sounded tedious in the extreme.
At a friendās insistence Iāve tried out Docker for OSX. Iām very dubious about this idea, but so far it seems like it could help a bit for providing a stable dev environment for a team.
To that end, I updated to Version 1.10.3-beta5 (build: 5049), and went to work trying random commands. It didnāt take too long thanks to a great overview by Amir Chaudry that saved a ton of guesswork (thanks Amir!). I started with a Mirage Docker image, unikernel / mirage, exported the opam switch config from my virtualbox side, imported it in the docker image, installed some system dependencies (openssl, dbm, etc.), and then committed the image. Seems to work a charm, and Iām relatively happy with sharing the file system across Docker/OSX (eliminates step 2 the dev iteration process). I may consider just running the server on the docker instance at this point, though thatās sadly losing some of the appeal of the Mirage workflow.
Another problem with this workflow is that mirage configure --xen screws up the same makefile I use for OSX-side dev (due to the shared filesystem). So flipping back and forth isnāt as seamless as I want.
So now the process is a bit shorter:
- Dev on OSX/Docker until happy with the changes
- Build Xen artifacts
scpartifacts to an EC2 build machine- ssh into build machine.
- Run a deploy script to turn the Xen artifacts into a running server
- Clean up left over EC2 resources
Already slimmed down! Iām in the process of converting the EC2 deploy script from bash to OCaml (via the previous Install OCaml AWS and dbm on OSX), so soon Iād like it to look like:
- Dev on OSX/Docker until happy with the changes
git commitcode, push- CI system picks up the new code + artifact commit, tests that it boots and binds to a port, then runs the EC2 deploy script.
Iāll be pretty close to happy once thatās the loop, and the last step can happen within ~20 seconds.