You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
6.6 KiB

  1. # include-in-agenda
  2. #+PROPERTY: Effort_ALL 0 0:30 1:00 2:00 0.5d 1d 1.5d 2d 3d 4d 5d
  3. #+PROPERTY: Max_effort_ALL 0 0:30 1:00 2:00 0.5d 1d 1.5d 2d 3d 4d 5d
  4. #+PROPERTY: header-args:python :var filename=(buffer-file-name)
  5. #+PROPERTY: header-args:sh :var filename=(buffer-file-name)
  6. #+TODO: TODO WIP BLOCKED | DONE CANCELED
  7. #+LATEX_HEADER: \usepackage[margin=0.5in]{geometry}
  8. #+LaTeX_CLASS: article
  9. #+OPTIONS: H:8 ^:nil prop:("Effort" "Max_effort") tags:not-in-toc
  10. #+COLUMNS: %50ITEM %Effort(Min Effort) %Max_effort(Max Effort)
  11. #+begin_LaTeX
  12. \hypersetup{
  13. linkcolor=blue,
  14. pdfborder={0 0 0 0}
  15. }
  16. #+end_LaTeX
  17. #+TITLE: 0k-compose
  18. #+LATEX: \pagebreak
  19. 0k-compose defines and run multi-container setups with Docker.
  20. It is a wrapper around =docker-compose= that aims at offering:
  21. - very simple (short) service description
  22. - completely orchestrate deployment of a solution
  23. - deployed solution is reproducible and identical
  24. #+LATEX: \pagebreak
  25. #+LATEX: \pagebreak
  26. * Installation
  27. ** Requirement
  28. You'll need:
  29. - =bash= >= 4.3
  30. - =docker= >= 17.06
  31. Expect to use command line and edit some files with your favorite
  32. editor.
  33. On MacOSX, you'll need to install homebrew
  34. https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/
  35. ** Installation
  36. *** Compose binary
  37. You can download this bash script and set it executable:
  38. https://git.0k.io/0k-compose.git/plain/bin/compose
  39. **** Linux/MacOSX
  40. For instance, you could
  41. #+BEGIN_SRC shell
  42. cd /tmp &&
  43. wget https://git.0k.io/0k-compose.git/plain/bin/compose -O compose &&
  44. chmod +x compose &&
  45. mv compose /usr/local/bin/
  46. #+END_SRC
  47. **** Windows WSL
  48. We need the real compose to be out of the WSL root and in the
  49. Docker available path, so this should work:
  50. You'll need administrative permission, for that just right click on
  51. the installed Linux environment such as Ubuntu and select “Run as
  52. Administrator”.
  53. #+BEGIN_SRC shell
  54. ## We make sure we have access to ``cmd.exe``
  55. CMD=$(type -p cmd.exe >/dev/null) || {
  56. for p in {/mnt,}/c/WINDOWS/SYSTEM32; do
  57. if [ -x "$p"/cmd.exe ]; then
  58. CMD="$p"/cmd.exe
  59. fi
  60. done
  61. if [ -z "$CMD" ]; then
  62. echo "cmd.exe is not found in \$PATH." \
  63. "And could not find it in standard directories." >&2
  64. return 1
  65. fi
  66. }
  67. win_env() { "$CMD" /c "<nul set /p=%${1}%" 2>/dev/null; }
  68. wsl_path_env() { wslpath "$(win_env "${1}")"; }
  69. ## Actual installation code:
  70. PROGRAM_PATH="$(wsl_path_env ProgramFiles)"/Compose &&
  71. mkdir -p "$PROGRAM_PATH/bin" &&
  72. cd /tmp &&
  73. wget "https://git.0k.io/0k-compose.git/plain/bin/compose?h=dev" -O compose &&
  74. chmod +x compose &&
  75. mv compose "$PROGRAM_PATH"/bin/compose &&
  76. mkdir -p ~/.local/bin &&
  77. ln -sf "$PROGRAM_PATH"/bin/compose ~/.local/bin/
  78. cd "$OLDPWD"
  79. #+END_SRC
  80. *** Test
  81. You should be able to run:
  82. #+BEGIN_SRC shell
  83. compose --version
  84. #+END_SRC
  85. *** Charms
  86. You should get some charms to mode forward. Charms are sort of
  87. packages that know how to setup services.
  88. **** Linux/MacOSX
  89. If you are installing this for you user account in Linux or MacOSX:
  90. #+BEGIN_SRC shell
  91. cd ~ &&
  92. git clone https://git.0k.io/0k-charms.git .charm-store
  93. #+END_SRC
  94. If you want to install them for general usage and intend
  95. to run =compose= with root access:
  96. #+BEGIN_SRC shell
  97. cd /srv &&
  98. git clone https://git.0k.io/0k-charms.git charm-store
  99. #+END_SRC
  100. **** Windows WSL
  101. #+BEGIN_SRC shell
  102. win_env() { cmd.exe /c "<nul set /p=%${1}%" 2>/dev/null; }
  103. wsl_path_env() { wslpath "$(win_env "${1}")"; }
  104. PROGRAM_PATH="$(wsl_path_env ProgramFiles)"/Compose &&
  105. cd "$PROGRAM_PATH" &&
  106. git clone https://git.0k.io/0k-charms.git charm-store
  107. #+END_SRC
  108. ** Usage
  109. Create a basic =compose.yml=, for instance:
  110. #+BEGIN_SRC yaml
  111. odoo:
  112. #+END_SRC
  113. And then run:
  114. #+BEGIN_SRC sh
  115. compose up
  116. #+END_SRC
  117. ** Configuration
  118. =compose= needs to store various things on your host:
  119. - the =datastore= is the data of all services that will be run by
  120. =compose= . This datastore can be saved and restored or moved around
  121. between hosts to revive the exact same services at the same point
  122. in time. It contains any data the service will produce : it can be
  123. work data, logs, parameters if the service allows for some configuration.
  124. On linux servers, when you are installing this with =root=
  125. permissions, it is traditionally stored in =/srv/datastore=. On
  126. local user installs you could tuck it in ``~/.compose/datastore``.
  127. - a state information directory for =compose= to store various
  128. internal running information: compose is not a daemon running in the
  129. back so it is storing state information in this directory. It is
  130. basically configuration values for services (for instance: user and
  131. password access between services, internal URL so that services
  132. can talk to each others... and any configuration that can be generated
  133. automatically, like configurations files in the service's format...)
  134. - a cache directory for =compose=, which is just a place to store
  135. intermediate values of computationaly expensive code. The content of
  136. this directory can be entirely wiped out and is cleaned by compose
  137. regularly to avoid growing too much.
  138. It'll need to get a read access also to:
  139. - a =charms-store=, a directory tree filled with charms. A charm is a directory conforming
  140. to charm rules (most importantly, it should hold a file named =metadata.yml=). A charm
  141. describe how to spawn a service. We have charms for =postgres=, =rocketchat=, =apache=, ...
  142. When launching =compose=, it takes also a =compose.yml= to manage
  143. services to deploy that can be specified with the =-f MYCOMPOSEFILE=
  144. optional argument, or will be found automatially in current directory
  145. or parents of it.
  146. * Feature
  147. compose run
  148. - much smaller and functional ``compose.yml`` file
  149. - all boiler-plate code is considered technical details
  150. and are moved in ``charms``
  151. - common compose-level API for same intents
  152. - launching a 'frontend', whether it is 'ngnix' or 'apache'
  153. is just one word to change in ``compose.yml``.
  154. - explicitely describe the relations between services and
  155. manage their dependencies.
  156. - be a good mannered command-line layer that don't remove any
  157. feature from ``docker-compose``.
  158. - allow complex setups and behavior out of ``docker-compose`` reach
  159. through:
  160. - =init= hooks that are run on the host before launching
  161. - relation hooks that triggers only when connecting 2 services
  162. - it enforce a clear separation of responsabilities
  163. ** Good mannered command line layer
  164. We want =compose= to be used as a drop-in replacement where ``docker-compose``
  165. can be used. With the following exception:
  166. - its own service file is named =compose.yml=.
  167. - some =compose='s service are subordinates
  168. *** Keeping command-line intact
  169. compose run