index.tex 4.9 KB

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