298 points · by pickleMeTimbers · 4y ago · 128 comments
""" The goal of this project is to enable MacOS users to:
Easily spin up and manage lightweight Alpine Linux environments. Use tiny VMs to take advantage of containerisation technologies, including LXD and Docker. Build and test software on x86_64 and aarch64 systems """
The aarch64 -> x86_64 virtualization performance is pretty rough.
Like, to the point where compiling a small hobbyist Rust project that needs to be deployed on Linux x86_64 in the cloud (cheap VPS)... you might as well just build it in the cloud and not locally on Mac host because it takes 10 minutes instead of 10 seconds
I’d love to containerize all of my local development efforts (scripts and rails apps) but the slow ass filesystem always ruined it in the past.
I believe multipass uses SSHFS (https://discourse.ubuntu.com/t/how-to-improve-mounts-perform...) to mount filesystems between the host and the VM. Performance has been excellent.
Lately I’ve been trying https://devenv.sh/ and it works great!
I haven’t tried it for ruby, though I have used vanilla nix shell for ruby projects before and it worked quite well after I over-rode GEM_PATH and GEM_HOME to the correct values.
Can devenv environment put itself in a chroot / sandbox where it cannot access my files, and is firewalled by default?
nix file helps you build OCI image and then you run it not locally/somewhere else?
can that be compared apples to apples to docker where you can build with Dockerfile syntax, and then run locally the image?
(Aside: you can build oci images using nix, but that’s probably what you would use for building deployable artifacts for production, not for development).
I would not say it is comparable with a Dockerfile - a Dockerfile is closer to a shell script, with caching between each step. Credit to Dockerfile syntax for being very easy to grok, but it is inherently not reproducible.
The perceived reliability of docker for development probably comes from the fact that you can share a prebuilt image, but rebuilding might not always work.
Like Mitchell Hashimoto (Hashicorp), I no longer do any development on macOS directly; I have a Linux VM where all my projects live and have their environments managed with a shell.nix file. Highly highly recommend it.
shell.nix - this brings the packages I need to develop into the $PATH when I run `nix-shell` in the repo
{pkgs ? import <nixpkgs> {}}:
with pkgs;
mkShell {
buildInputs = [
meilisearch
openssl
overmind
pkg-config
postgresql
rustup
tmux
];
shellHook = ''
export OVERMIND_PROCFILE=Procfile.dev
export PGDATA="data.pg"
export MEILI_DB_PATH="data.ms"
'';
}
Procfile.dev - this is used to start the background services I need, the format is "name: command" postgres: postgres -K /tmp
meilisearch: meilisearch
Then I can run `nix-shell` to load all the dependencies and `overmind start` to bring up Postgres + Meilisearch with ignored data dirs relative to the project folder. If any of these packages need to be pinned to a specific version you can do that with this tool[1].That's pretty much it - with all the background services running you can load your monolith or microservices with cargo/npm/etc. It's all very nice and clean!
[1]: https://lazamar.co.uk/nix-versions/ - I actually just used this in a new shell.nix for my personal website to pin a version of Hugo from 2019 (when I last touched it) so that it would build again
I think the new virtualization framework just came out of beta though so now it’s just VirtuoFS that needs to be enabled.
Make sure that you're running a recent version of Lima, and use a 9p mount.
Edit: by editing one of these yamls: https://github.com/lima-vm/lima/tree/master/examples
If you use VS Code the remoting extensions pack includes SSH, for my personal laptop, I'm usually using code to my linux desktop, and editing remotely... it's pretty slick. Code will run a "code server" in the remote environment, and is effectively just displaying the text view to you, the actual work is happening in the remote envornment. You can do similar with containers, or in windows+wsl.
They all use the underlying OS hypervisor so I’m not sure you can get perceivable performance out of one solution over the other.
That said, there now seems to be a huge number of options for running various combinations of VMs and containers on Mac and Lenix now. I just use whatever seems popular and is easy to set up, but I have no sense of the pros and cons among them. I would love a coherent document on this topic.
So in other words, qemu runs at near-native speeds?
From there you can register Rosetta as a runtime and use it to run x86-64 Linux apps on ARM64 if you want. (https://developer.apple.com/documentation/virtualization/run...)
EDIT: This is from experience. When I started using a M1 mac, our docker builds on x86 images took up to 5x or 10x longer vs running on an arm64 image. Had slightly faster, but similar results running my own docker host on Lima, or podman, or building without docker inside a UTM host which also uses qemu.
https://developer.apple.com/documentation/virtualization/run...
My current setup is to have both data and workload run on a remote machine and I connect to it via SSH. I can either run neovim inside or use the remote development plugin from VSCode. But as mentioned, the input lag can be very annoying. I’m wondering if there’s another setup where I can still retain some of the upsides of running the workloads remotely and still having a decent user experience (reduced lag)
- Local and remote copy of files - Two way sync
I've been using this for years, editing locally with Sublime, while running everything on a remote Linux vm. Because it's two way sync, anything created/modified on the server is also sync'd back to your local filesystem. I end up syncing most of the remote $HOME so I can easily fire up a new VM, sync, and go. It really is fantastic.
https://docs.rackspace.com/blog/speeding-up-ssh-session-crea...
For reducing the latency of an interactive ssh session, there's mosh: https://mosh.org/
Or are you just talking about when using neovim?
If you've ever tried to spin up a whole bunch of Docker containers in WSL2 and watched `vmmem` memory and CPU usage explode, you know that 'near-native speed' in VMs comes with lots of asterisks.
Does macOS have usable native macOS containers yet?
I come from the development background and the number one use case of containers on macOS is development enviroments, as on Windows too. For this use case, file system IO has always been bottleneck, not CPU. I do not know if there is some silver bullet in the horizon that could make this faster.
I am personally slowly moving back to Docker after having used limactl for a long time. It's just a pain in the ass.
A Linux laptop is better for all intents and purposes, except the shitty battery life...
EDIT: Looks like this was indeed just added in the last couple of weeks https://github.com/lima-vm/lima/commit/c18ae239b69a47db77436...
Macpine: https://github.com/beringresearch/macpine/blob/71788e9c3c09c...
colima: https://github.com/abiosoft/colima/blob/7ebcf14a69158afa43b2...
So it seems that it has same performance as colima project as well.
As for IO performance, see this colima issue https://github.com/abiosoft/colima/issues/146#issuecomment-1...
E.g. here is page 2 of one tutorial: https://access.redhat.com/documentation/en-us/red_hat_enterp...
All these rules made no sense to me, and while I suppose they become clear at some point, I like my tutorials to be clear from the start.
https://access.redhat.com/documentation/en-us/red_hat_enterp...
That said I don't remember having to learn all that much about cgroups when I last looked at lxc...
Well, I started looking into it because there were all these mounted filesystems that I couldn't unmount, even as root. I guess I will have to look into namespaces also.
You'll be pleased that at least with cgroups v2 there's only a single /sys/fs/cgroup instead of half a dozen filesystems mounted underneath that path. :)
3 minutes search reveals an easy to follow tutorial.
Lxc is somewhat to lxd as jails are to ezjails...
I'm guessing bocker would be more useful for that: https://news.ycombinator.com/item?id=33218094
Wow, I'm dying to see how it works!
> brew install qemu
:|