bundles.tex 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. \section{Bundles}
  2. \subsection{Apps Ordering}
  3. Before starting an application which could be
  4. packed within three forms: Single-File Bundle, Release or OTP.MK Folder.
  5. \vspace{1\baselineskip}
  6. \begin{lstlisting}
  7. # mad plan
  8. Ordered: [kernel,stdlib,mnesia,kvs,crypto,cowlib,ranch,
  9. cowboy,compiler,syntax_tools,erlydtl,gproc,
  10. xmerl,n2o,n2o_sample,fs,active,mad,rest,sh]
  11. \end{lstlisting}
  12. \vspace{1\baselineskip}
  13. \subsection{Single-File Bundles with MAD}
  14. The key feature of mad is ability to create single-file bundled web sites.
  15. Thus making dream to boot simpler than node.js come true.
  16. This target escript is ready to run on Windows, Linux and Mac.
  17. To make this possible we implemented a zip filesytem inside escript.
  18. mad packages priv directories along with ebin and configs.
  19. You can redefine each file in zip fs inside target
  20. escript by creation the copy with same path locally near escript.
  21. After launch all files are copied to ETS.
  22. N2O also comes with custom cowboy static handler that is able to
  23. read static files from this cached ETS filesystem.
  24. Also bundle are compatible with active online realoading and recompilation.
  25. E.g. you main create a single file site with:
  26. \vspace{1\baselineskip}
  27. \begin{lstlisting}
  28. # mad bundle app_name
  29. \end{lstlisting}
  30. \vspace{1\baselineskip}
  31. app\_name shoul be the same as a valid Erlang module, with app\_module:main/1
  32. function defined, which will boot up the bundle. This function could be like that:
  33. \vspace{1\baselineskip}
  34. \begin{lstlisting}
  35. -module(app_name).
  36. main(Params) ->
  37. RebarConfig = [],
  38. mad_repl:main(Params,RebarConfig).
  39. \end{lstlisting}
  40. \vspace{1\baselineskip}
  41. \subsection{Releases with RELX}
  42. As you may know you can create OTP releases with
  43. reltool (rebar generate) or systools (relx). mad currently
  44. creates releases with relx but is going to do it independently soon.
  45. Now it can only order applications.
  46. \vspace{1\baselineskip}
  47. \begin{lstlisting}
  48. # mad release
  49. \end{lstlisting}
  50. \vspace{1\baselineskip}
  51. \subsection{Folders with OTP.MK}
  52. OTP.MK is a tiny 50 lines Makefile that allows to start your set
  53. of application using run\_erl and to\_erl tools from OTP distribution.
  54. We use that way in poduction. This is the best option also in
  55. development mode because all directory structure is open and mutable,
  56. so you can reload modified files and perform recompilation on the fly.
  57. It uses the original code to fast resolve dependencies into the right
  58. boot sequence to start.
  59. \vspace{1\baselineskip}
  60. \begin{lstlisting}
  61. # make console
  62. \end{lstlisting}
  63. \vspace{1\baselineskip}