index.tex 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. \section{MAD: Erlang Build and Deploy Tool}
  2. \subsection{History}
  3. We realized no matter how perfect your libraries are,
  4. the comfort and easy come mostly from developing tools.
  5. Everything got started when 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 active emerged.
  12. Under the hood active is a client subscriber
  13. of 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. Later switched to Makefile-based build tool otp.mk.
  18. And of course it is slow, especially in cold recompilation.
  19. It was designed to be a stand-alone tool, so it has some
  20. glitches while using as embedded library.
  21. Our idea to build rebar replacement was picked up by Sina Samavati,
  22. he implemented the first prototype called mad. Initially mad
  23. was able to compile DTL templated, YECC files, escript (like
  24. bundled in gproc), also it was support caching with side-effects.
  25. After a month I forked mad and took over the development under the same name.
  26. \vspace{1\baselineskip}
  27. \begin{lstlisting}[caption=Example of building N2O sample]
  28. Cold Hot
  29. rebar get-deps compile 53.156s 4.714s
  30. mad deps compile 54.097s 0.899s
  31. \end{lstlisting}
  32. \vspace{1\baselineskip}
  33. \vspace{1\baselineskip}
  34. \begin{lstlisting}[caption=Example of building Cowboy]
  35. Hot
  36. make (erlang.mk) 2.588s
  37. mad compile 2.521s
  38. \end{lstlisting}
  39. \vspace{1\baselineskip}
  40. \subsection{Introduction}
  41. We were trying to make something minimalistic that fits out Web Stack.
  42. Besides we wanted to use our knowledge of other build tools like lein, sbt etc.
  43. Also for sure we tried sinan, ebt, Makefile-based scripts.
  44. Synrc mad has a simple interface as follows:
  45. \vspace{1\baselineskip}
  46. \begin{lstlisting}
  47. BNF:
  48. invoke := mad params
  49. params := [] | run params
  50. run := command [ options ]
  51. cmd := app | lib | deps | compile | bundle
  52. run | stop | attach | repl
  53. \end{lstlisting}
  54. \vspace{1\baselineskip}
  55. It seems to us more natural, you can specify random
  56. commands set with different specifiers (options).
  57. \subsection{Single-File Bundling}
  58. The key feature of mad is ability to create single-file bundled web sites.
  59. Thus making Joe's dream to boot like node.js come true.
  60. This target escript is ready to run on Windows, Linux and Mac.
  61. To make this possible we implemented a zip filesytem inside escript.
  62. mad packages priv directories along with ebin and configs.
  63. You can redefine each file in zip fs inside target
  64. escript by creation the copy with same path locally near escript.
  65. After launch all files are copied to ETS.
  66. N2O also comes with custom cowboy static handler that is able to
  67. read static files from this cached ETS filesystem.
  68. Also bundle are compatible with active online realoading and recompilation.
  69. \subsection{Templates}
  70. mad also comes with N2O templates. So you can bootstrap a N2O-based site
  71. just having a single copy of mad.
  72. \vspace{1\baselineskip}
  73. \begin{lstlisting}
  74. # mad app sample
  75. # cd sample
  76. # mad deps compile plan bundle web_app
  77. \end{lstlisting}
  78. \vspace{1\baselineskip}
  79. After that you can just run ./web_app under Windows, Linux and
  80. Mac and open \footahref{http://localhost:8000}{http://localhost:8000}.
  81. \vspace{1\baselineskip}
  82. \begin{lstlisting}
  83. C:\> escript web_app
  84. Applications: [kernel,stdlib,crypto,cowlib,ranch,cowboy,compiler,syntax_tools,
  85. erlydtl,gproc,xmerl,n2o,n2o_sample,fs,active,mad,sh]
  86. Configuration: [{n2o,[{port,8000},{route,routes}]},
  87. {kvs,[{dba,store_mnesia},
  88. {schema,[kvs_user,kvs_acl,kvs_feed,kvs_subscription]}]}]
  89. Erlang/OTP 17 [erts-6.0] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]
  90. Eshell V6.0 (abort with ^G)
  91. 1>
  92. \end{lstlisting}
  93. \vspace{1\baselineskip}
  94. \subsection{Deploy}
  95. mad is also supposed to be also a deploy tool with ability to
  96. deploy not only to our resources like Erlang on Xen, Voxoz (LXC/Xen) but
  97. also to Heroku and others.
  98. \subsection{OTP Compliant}
  99. mad supports rebar umbrella project structure.
  100. Specifically two kinds of directory layouts:
  101. \vspace{1\baselineskip}
  102. \begin{lstlisting}[caption=Solution]
  103. ├── apps
  104. ├── deps
  105. ├── rebar.config
  106. └── sys.config
  107. \end{lstlisting}
  108. \vspace{1\baselineskip}
  109. \vspace{1\baselineskip}
  110. \begin{lstlisting}[caption=OTP Application]
  111. ├── deps
  112. ├── ebin
  113. ├── include
  114. ├── priv
  115. ├── src
  116. └── rebar.config
  117. \end{lstlisting}
  118. \vspace{1\baselineskip}
  119. Also you can create OTP releases with reltool, rebar configure or relx.
  120. Internally mad uses reltool to order your dependencies.