bundles.tex 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. \section{Container Bundles}
  2. \subsection{ESCRIPT Bundles}
  3. The key feature of mad is ability to create single-file bundled web sites.
  4. Thus making dream to boot simpler than node.js come true.
  5. This bundle target is ready to run on Windows, Linux and Mac.
  6. To make this possible we implemented a zip filesytem inside escript.
  7. mad packages priv directories along with ebin and configs.
  8. You can redefine each file in zip fs inside target
  9. escript by creation the copy with same path locally near escript.
  10. After launch all files are copied to ETS.
  11. N2O also comes with custom cowboy static handler that is able to
  12. read static files from this cached ETS filesystem.
  13. Also bundle are compatible with active online realoading and recompilation.
  14. E.g. you main create a single file site with:
  15. \vspace{1\baselineskip}
  16. \begin{lstlisting}
  17. # mad bundle app_name
  18. \end{lstlisting}
  19. \vspace{1\baselineskip}
  20. app\_name shoul be the same as a valid Erlang module, with app\_module:main/1
  21. function defined, which will boot up the bundle. This function could be like that:
  22. \vspace{1\baselineskip}
  23. \begin{lstlisting}
  24. -module(app_name).
  25. main(Params) ->
  26. RebarConfig = [],
  27. mad_repl:main(Params,RebarConfig).
  28. \end{lstlisting}
  29. \vspace{1\baselineskip}
  30. \subsection{BEAM ERTS Releases}
  31. As you may know you can create OTP releases with
  32. reltool (rebar generate) or systools (relx). mad creates releases boot
  33. script with systools and pack tra by itself.
  34. \vspace{1\baselineskip}
  35. \begin{lstlisting}
  36. # mad release beam sample
  37. \end{lstlisting}
  38. \vspace{1\baselineskip}
  39. \subsection{LING Unikernels}
  40. Sample rebar.config for your application you want to go unikernel:
  41. \vspace{1\baselineskip}
  42. \begin{lstlisting}
  43. {deps_dir,"deps"}.
  44. {deps, [{ling,"master"},{sh,"1.9"}]}.
  45. \end{lstlisting}
  46. \vspace{1\baselineskip}
  47. Now you should build LING/posix:
  48. \vspace{1\baselineskip}
  49. \begin{lstlisting}
  50. $ mad dep
  51. $ cd deps/ling
  52. $ ARCH=posix make
  53. \end{lstlisting}
  54. \vspace{1\baselineskip}
  55. Now pack vmling.o, your OTP apps and rest static to single-file LING bundle with VM inside.
  56. \vspace{1\baselineskip}
  57. \begin{lstlisting}
  58. $ mad release ling mad
  59. Ling Params: []
  60. ARCH: posix_x86
  61. Bundle Name: mad
  62. System: [compiler,syntax_tools,sasl,tools,mnesia,reltool,xmerl,crypto,kernel,
  63. stdlib,wx,webtool,ssl,runtime_tools,public_key,observer,inets,asn1,
  64. et,eunit,hipe,os_mon]
  65. Apps: [kernel,stdlib,sh,mad]
  66. Overlay: ["crypto.beam","9p.beam","9p_auth.beam","9p_info.beam",
  67. "9p_mounter.beam","9p_server.beam","9p_tcp.beam","9p_zero.beam",
  68. "disk.beam","disk_server.beam","embedded_export.beam",
  69. "goo_export.beam","goofs.beam","hipe_unified_loader.beam",
  70. "inet_config.beam","kernel.beam","ling_bifs.beam","ling_code.beam",
  71. "ling_disasm.beam","ling_iops.beam","ling_iopvars.beam",
  72. "ling_lib.beam","net_vif.beam","os.beam","prim_file.beam",
  73. "user_drv.beam","os_mon.beam","dets.beam","filename.beam",
  74. "maps.beam","unicode.beam","zlib.beam"]
  75. Bucks: [{boot,"/boot",2},
  76. {os_mon,"/erlang/lib/os_mon/ebin",1},
  77. {crypto,"/erlang/lib/crypto/ebin",1},
  78. {kernel,"/erlang/lib/kernel/ebin",90},
  79. {stdlib,"/erlang/lib/stdlib/ebin",85},
  80. {sh,"/erlang/lib/sh/ebin",6},
  81. {mad,"/erlang/lib/mad/ebin",43}]
  82. Initializing EMBED.FS:
  83. Mount View:
  84. /boot /boot
  85. /erlang/lib/os_mon/ebin /os_mon
  86. /erlang/lib/crypto/ebin /crypto
  87. /erlang/lib/kernel/ebin /kernel
  88. /erlang/lib/stdlib/ebin /stdlib
  89. /erlang/lib/sh/ebin /sh
  90. /erlang/lib/mad/ebin /mad
  91. Creating EMBED.FS C file: ...ok
  92. Compilation of Filesystem object: ...ok
  93. Linking Image: ok
  94. \end{lstlisting}
  95. \vspace{1\baselineskip}
  96. Run it:
  97. \vspace{1\baselineskip}
  98. \begin{lstlisting}
  99. $ rlwrap ./image.img
  100. Erlang [ling-0.5]
  101. Eshell V6.3 (abort with ^G)
  102. 1> application:which_applications().
  103. [{mad,"MAD VXZ Build Tool","2.2"},
  104. {sh,"VXZ SH Executor","0.9"},
  105. {stdlib,"ERTS CXC 138 10","2.2"},
  106. {kernel,"ERTS CXC 138 10","3.0.3"}]
  107. \end{lstlisting}
  108. \vspace{1\baselineskip}
  109. \subsection{Docker-compatible RUNC Containers}
  110. Creating runc-complatible container is simple:
  111. \vspace{1\baselineskip}
  112. \begin{lstlisting}
  113. # mad release runc sample
  114. \end{lstlisting}
  115. \vspace{1\baselineskip}
  116. \subsection{Makefiles with OTP.MK}
  117. OTP.MK is a tiny 50 lines Makefile that allows to start your set
  118. of application using run\_erl and to\_erl tools from OTP distribution.
  119. We use that way in poduction. This is the best option also in
  120. development mode because all directory structure is open and mutable,
  121. so you can reload modified files and perform recompilation on the fly.
  122. It uses the original code to fast resolve dependencies into the right
  123. boot sequence to start. If you want more powerful Makefile-based erlang
  124. package management you may take a look onto ERLANG.MK by Nine Nines.
  125. \vspace{1\baselineskip}
  126. \begin{lstlisting}
  127. # make console
  128. \end{lstlisting}
  129. \vspace{1\baselineskip}