browserify / wzrd.in

browserify as a service.
http://wzrd.in
MIT License
637 stars 96 forks source link

Mad refactor -- use docker for build isolation, clean up everything in the process #133

Closed jfhbrook closed 7 years ago

jfhbrook commented 7 years ago

THIS IS READY FOR REVIEW!!

Closes #18 Closes #117 Closes #72

This started out as work to improve isolation/sandboxing of build processes by leveraging docker. This also has the bonus of creating a code seam between the builder (options go in, built bundle comes out) and the bundler (the name of the thing that used to deal with building but now will only deal with caching and options munging).

While docker gets us some nice advantages in terms of build isolation a la chroots, it doesn't give us true sandboxing. Some resources to get us there include https://www.stgraber.org/2014/01/17/lxc-1-0-unprivileged-containers/ and https://github.com/thestinger/playpen . However, while docker currently Just Works on osx, both of these solutions require linux (and a lot more glue code!). Investigation is coming. I'm tempted to ship this to make things better, and then do a phase 2 where I support an alternate sandboxed backend testable on linux/systemd.

While writing the builder I decided to migrate towards promises. This is probably a controversial move. https://www.youtube.com/watch?v=WBupia9oidU That said, it's created some really nice gains around the "don't do 2 of the same build at the same time" problem (look in the build method of the builder), and nodebacks and promises are like oil and water, so here we are! At the very least, I'm doing my best to not write bad promise code. So far so good I think. (Note I don't plan on going apeshit with the promises in the route/controller code, that should remain express-friendly.)

I'm also using es6 classes. Most of the libraries were already implementing class-like patterns, this just makes it more official.

Tests are also happening! This refactor is big enough that I needed to be able to pin some stuff down. This has been particularly nice for dealing with the problem the current codebase has where there's a "pkg" "module" and "version" flying around that may or may not have who knows what properties. The builder enforces specific keys for a number of properties, and these conventions are largely being propagated through the codebase. Tests help ensure the behavior is consistent, and we don't pass a semver into something expecting a version, or vice versa.

Things that are done:

Cut scope:

May this not die in a ditch!

jfhbrook commented 7 years ago

@maxogden This is ready for review. From you, I think I just need some assurances that deploying this won't break requirebin. We should also talk deploy strategy.

jfhbrook commented 7 years ago

Note to self: With https://github.com/thestinger/playpen I should be able to do docker export browserify-builder | tar -x -C sandbox or similar.