index.tex 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. \section{MAD: Erlang Build and Deploy Tool}
  2. \subsection{History}
  3. We came to conclusion that no matter how perfect your libraries are,
  4. the comfort and ease come mostly from developing tools.
  5. Everything got started when \footahref{https://github.com/proger}{Vladimir~Kirillov} decided to
  6. replace Rusty's sync beam reloader. As you know sync uses
  7. filesystem polling which is neither energy-efficient nor elegant. Also
  8. sync is only able to recompile separate modules while
  9. common use-case in N2O is to recompile DTL templates
  10. and LESS/SCSS stylesheets. That is why we need to recompile
  11. the whole project. That's the story how \footahref{https://github.com/synrc/active}{active} emerged.
  12. Under the hood active is a client subscriber
  13. of \footahref{https://github.com/synrc/fs}{fs} library, native filesystem listener for Linux, Windows and Mac.
  14. De-facto standard in Erlang world is rebar.
  15. We love rebar interface despite its implementation.
  16. First we plugged rebar into active and then decided to drop its support,
  17. it was slow, especially in cold recompilation.
  18. It was designed to be a stand-alone tool, so it has some
  19. glitches while using as embedded library.
  20. Later we switched to Makefile-based build tool \footahref{https://github.com/synrc/otp.mk}{otp.mk}.
  21. The idea to build rebar replacement was up in the air for a long time.
  22. The best minimal approach was picked up by \footahref{https://github.com/s1n4}{Sina~Samavati},
  23. who implemented the first prototype called 'mad'. Initially mad
  24. was able to compile DTL templated, YECC files, escript (like
  25. bundled in gproc), also it had support for caching with side-effects.
  26. In a month I forked mad and took over the development under the same name.
  27. \vspace{1\baselineskip}
  28. \begin{lstlisting}[caption=Example of building N2O sample]
  29. Cold Hot
  30. rebar get-deps compile 53.156s 4.714s
  31. mad deps compile 54.097s 0.899s
  32. \end{lstlisting}
  33. \vspace{1\baselineskip}
  34. \vspace{1\baselineskip}
  35. \begin{lstlisting}[caption=Example of building Cowboy]
  36. Hot
  37. make (erlang.mk) 2.588s
  38. mad compile 2.521s
  39. \end{lstlisting}
  40. \vspace{1\baselineskip}
  41. \subsection{Introduction}
  42. We were trying to make something minimalistic that fits out \footahref{https://github.com/synrc}{Web Stack}.
  43. Besides we wanted to use our knowledge of other build tools like lein, sbt etc.
  44. Also for sure we tried sinan, ebt, Makefile-based scripts.
  45. Synrc mad has a simple interface as follows:
  46. \vspace{1\baselineskip}
  47. \begin{lstlisting}
  48. BNF:
  49. invoke := mad params
  50. params := [] | run params
  51. run := command [ options ]
  52. command := app | lib | deps | compile | bundle
  53. start | stop | repl
  54. \end{lstlisting}
  55. \vspace{1\baselineskip}
  56. It seems to us more natural, you can specify random
  57. commands set with different specifiers (options).
  58. \subsection{Several Types of Packaging}
  59. The key feature of mad is ability to create single-file bundled web sites.
  60. Thus making dream to boot simpler than node.js come true.
  61. This target escript is ready to run on Windows, Linux and Mac.
  62. \subsection{Deployment Options}
  63. mad is also supposed to be a deploy tool with ability to
  64. deploy not only to our resources like Erlang on Xen, Voxoz (LXC/Xen) but
  65. also to Heroku and others.
  66. \subsection{OTP Compliant}
  67. mad supports rebar umbrella project structure.
  68. Specifically two kinds of directory layouts:
  69. \subsection{Fast Apps Ordering}
  70. As you may know you can create OTP releases with
  71. reltool (rebar generate) or systools (relx). mad currently
  72. creates releases with relx but is going to do it independently soon.
  73. Now it can only order applications.
  74. \subsection{Tiny Size}
  75. And the good part:
  76. \vspace{1\baselineskip}
  77. \begin{lstlisting}
  78. Sources Binary
  79. mad 567 LOC 39 KB
  80. rebar 7717 LOC 181 KB
  81. \end{lstlisting}
  82. \vspace{1\baselineskip}