Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22462

Giampaolo Rodola: Virtualize OSX on Linux

$
0
0

Preamble

I've been a Linux user for something like 10 years now. In order to develop and maintain psutil on different platforms I've been using the excellent VirtualBox. With it, during the years, I've been able to virtualize different versions of Windows, FreeBSD, OpenBSD, NetBSD and Solaris and implement and protract support for such platforms inside psutil. Without VirtualBox there really wouldn't exist psutil as it stands nowadays.
At some point I also managed to virtualize OSX by using an hacked version of OSX called iDeneb which is based on OSX 10.5 / Leopard (note: 9 years old), and that is what I've been using up until today. Of course such an old hacked version of OSX isn't nice to deal with. It ships Python 2.5, it kernel panicks, I had to reinstall it from scratch quite often and people (rightfully) make fun of you.  Thank you iDeneb: I loved and hated you at the same time. =)

Vagrant

I'm really not sure how I could  have been missing this for all this time, but it turns out emulating OSX on Linux really is as easy as executing a one-liner:
vagrant init AndrewDryga/vagrant-box-osx; vagrant up
And that really is it! I mean... you're literally good to go and start developing! That will create a Vagrant file, download a pre-configured OSX image via internet (10GB or something) and finally run it in VirtualBox. The whole package includes:
  • OSX 10.10.4 / Yosemite
  • XCode 6.4 + gcc
  • brew
  • Python 2.7
In a couple of hours I modified the original Vagrantfile a little and managed to mount a directory which is shared between the VM and the host (my laptop) and ended up with this Vagrantfile.

Development workflow

This is the second best part, and it represents why Vagrant is such a great tool. So far in order to virtualize a platform and develop on it I had to:
  • download the platform ISO (BSD, SunOS or whatever)
  • manually install it in VirtualBox
  • install deps, configure the platform, setup SSHd
In order to automatize the system configuration I came up with a bunch of automation scripts but that really is another story.  With that done, every time I wanted to work on psutil I had to:
  • open VirtualBox (GUI)
  • "get into it" (by clicking with the mouse), open a terminal, get the IP address
  • get out of VirtualBox, open a local terminal, SSH into the VM
  • open the GUI file manager, SFTP into the VM, open the source files with my editor (Sublime), finally start working
With Vagrant the workflow becomes much more easier as no GUI is involved. Everything happens in the terminal (2 actually):
  • I install and run the VM with "vagrant up"
  • I SSH into it with "vagrant ssh" in one terminal (without knowing any IP)
  • I edit files locally in another terminal 
That's it. The best part is that Vagrant (or VirtualBox?) does the necessary magic so that a local directory (the one where you have your source files) will be mapped and visible inside the VM. With that you can edit the source files locally without ever connecting to the VM via an IP address, SFTP or whatever.
I will likely get rid of my other VMs installed "manually" and do the same: rely on Vagrant. Actually I already did for OpenBSD and NetBSD but I'm still not happy with what i have. In summary, I think this is a great improvement in terms of productivity, and I wish I had discovered this sooner.

Viewing all articles
Browse latest Browse all 22462

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>