mgmt
mgmt copied to clipboard
[LOVE] Build self-contained static binaries with DSL code contained
Welcome:
This is a difficult patch for someone who has experience in golang, and some experience in mgmt. It is meant to encourage an mgmt hacker to get more deeply involved with mgmt. It will probably take you at least a few days or so to complete.
Intro:
Mgmt is written in golang and as a result can be compiled into a nice, self-contained package. It can accept and run some code (eg: the mgmt DSL) at startup or via a "deploy". It would be especially convenient if we could compile in the code base and have that run automatically at startup so that we could more easily build standalone "applications" and start them on boot with systemd. To implement this, you'll need to either recommend an alternate design, or use the one provided below.
Design:
You'll need to come up with a concrete design and user experience which is functional, and elegant. It will probably involve storing the code base in a compiled binary with go-bindata. It would probably be excellent if we supported a new sub-command in mgmt which would build such a binary. This would have the advantage that we could compile and type-check the code before building the binary. It would also provide a more consistent user interface and is better than requiring the user to run "make". If there is a way that we can avoid having to have the whole source dir present to build such a binary, then that is preferable. Some research is needed here to see if we can "tack" on some user data and build a new binary, or if we'd need to compile in the entire source code dir, and spit it out into a temporary directory for running a compile, or perhaps just requiring a few system dependencies.
Read the contributing tips: https://github.com/purpleidea/mgmt/blob/master/.github/PULL_REQUEST_TEMPLATE.md
Happy hacking, and ping me for questions!
Bonus/Future work:
- Write a few tests.
- Add an option to ignore future deploys to prevent someone changing the "code".
Just came across this. Looks like it could be useful for adding mgmt code to an existing binary. https://github.com/zhuangsirui/binpacker
@jonathangold Interesting-- This appends code to an existing binary? Which would still run normally and be able to "unpack" from itself? I didn't find that information in the docs, is it in a blog post somewhere? Cool find! If so, it could work better than go-bindata.
Haven't looked into it enough to answer those questions, but on second look, it may not turn out to be that helpful. ¯\(ツ)/¯ There's some other potentially tools at https://github.com/avelino/awesome-go#resource-embedding
@jonathangold Cool! It would be most helpful to be able to add data to a binary after it already exists, since if we're building a new one at compile time go-bindata can do that already.
In any case, this isn't the highest priority issue for now, since it's probably more important to have more useful code, modules, and library functions first :)
This is basically done. Some additional feature ideas exist in the issue, but we're close enough that I think I will close this for now. Woo!