bundles.tex 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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) -> mad_repl:sh(Params).
  26. \end{lstlisting}
  27. \vspace{1\baselineskip}
  28. \subsection{BEAM ERTS Releases}
  29. As you may know you can create OTP releases with
  30. reltool (rebar generate) or systools (relx). mad creates releases boot
  31. script with systools and pack tra by itself.
  32. \vspace{1\baselineskip}
  33. \begin{lstlisting}
  34. # mad release beam sample
  35. \end{lstlisting}
  36. \vspace{1\baselineskip}
  37. \subsection{LING Unikernels}
  38. Sample rebar.config for your application you want to go unikernel:
  39. \vspace{1\baselineskip}
  40. \begin{lstlisting}
  41. {deps_dir,"deps"}.
  42. {deps, [{ling,"master"},{sh,"1.9"}]}.
  43. \end{lstlisting}
  44. \vspace{1\baselineskip}
  45. Now you should build LING/posix:
  46. \vspace{1\baselineskip}
  47. \begin{lstlisting}
  48. $ mad dep
  49. $ cd deps/ling
  50. $ ARCH=posix make
  51. \end{lstlisting}
  52. \vspace{1\baselineskip}
  53. Now pack vmling.o, your OTP apps and rest static to single-file LING bundle with VM inside.
  54. \vspace{1\baselineskip}
  55. \begin{lstlisting}
  56. $ mad release ling mad
  57. Ling Params: []
  58. ARCH: posix_x86
  59. Bundle Name: mad
  60. System: [compiler,syntax_tools,sasl,tools,mnesia,reltool,xmerl,crypto,kernel,
  61. stdlib,wx,webtool,ssl,runtime_tools,public_key,observer,inets,asn1,
  62. et,eunit,hipe,os_mon]
  63. Apps: [kernel,stdlib,sh,mad]
  64. Overlay: ["crypto.beam","9p.beam","9p_auth.beam","9p_info.beam",
  65. "9p_mounter.beam","9p_server.beam","9p_tcp.beam","9p_zero.beam",
  66. "disk.beam","disk_server.beam","embedded_export.beam",
  67. "goo_export.beam","goofs.beam","hipe_unified_loader.beam",
  68. "inet_config.beam","kernel.beam","ling_bifs.beam","ling_code.beam",
  69. "ling_disasm.beam","ling_iops.beam","ling_iopvars.beam",
  70. "ling_lib.beam","net_vif.beam","os.beam","prim_file.beam",
  71. "user_drv.beam","os_mon.beam","dets.beam","filename.beam",
  72. "maps.beam","unicode.beam","zlib.beam"]
  73. Bucks: [{boot,"/boot",2},
  74. {os_mon,"/erlang/lib/os_mon/ebin",1},
  75. {crypto,"/erlang/lib/crypto/ebin",1},
  76. {kernel,"/erlang/lib/kernel/ebin",90},
  77. {stdlib,"/erlang/lib/stdlib/ebin",85},
  78. {sh,"/erlang/lib/sh/ebin",6},
  79. {mad,"/erlang/lib/mad/ebin",43}]
  80. Initializing EMBED.FS:
  81. Mount View:
  82. /boot /boot
  83. /erlang/lib/os_mon/ebin /os_mon
  84. /erlang/lib/crypto/ebin /crypto
  85. /erlang/lib/kernel/ebin /kernel
  86. /erlang/lib/stdlib/ebin /stdlib
  87. /erlang/lib/sh/ebin /sh
  88. /erlang/lib/mad/ebin /mad
  89. Creating EMBED.FS C file: ...ok
  90. Compilation of Filesystem object: ...ok
  91. Linking Image: ok
  92. \end{lstlisting}
  93. \vspace{1\baselineskip}
  94. Run it:
  95. \vspace{1\baselineskip}
  96. \begin{lstlisting}
  97. $ rlwrap ./image.img
  98. Erlang [ling-0.5]
  99. Eshell V6.3 (abort with ^G)
  100. 1> application:which_applications().
  101. [{mad,"MAD VXZ Build Tool","2.2"},
  102. {sh,"VXZ SH Executor","0.9"},
  103. {stdlib,"ERTS CXC 138 10","2.2"},
  104. {kernel,"ERTS CXC 138 10","3.0.3"}]
  105. \end{lstlisting}
  106. \vspace{1\baselineskip}
  107. \subsection{Docker-compatible RUNC Containers}
  108. Creating runc-complatible container is simple:
  109. \vspace{1\baselineskip}
  110. \begin{lstlisting}
  111. # mad release runc sample
  112. \end{lstlisting}
  113. \vspace{1\baselineskip}
  114. \subsection{Makefiles with OTP.MK}
  115. OTP.MK is a tiny 50 lines Makefile that allows to start your set
  116. of application using run\_erl and to\_erl tools from OTP distribution.
  117. We use that way in poduction. This is the best option also in
  118. development mode because all directory structure is open and mutable,
  119. so you can reload modified files and perform recompilation on the fly.
  120. It uses the original code to fast resolve dependencies into the right
  121. boot sequence to start. If you want more powerful Makefile-based erlang
  122. package management you may take a look onto ERLANG.MK by Nine Nines.
  123. \vspace{1\baselineskip}
  124. \begin{lstlisting}
  125. # make console
  126. \end{lstlisting}
  127. \vspace{1\baselineskip}