fork 0k-charms
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.

326 lines
8.4 KiB

  1. #!/bin/bash
  2. set -eux
  3. ## 0k git remote path
  4. GIT_0K_BASE=${GIT_0K_BASE:-"0k-ro:/var/git"}
  5. ## 0k git remote options
  6. GIT_0K_CLONE_OPTIONS=${GIT_0K_CLONE_OPTIONS:-""}
  7. ##
  8. ## Install 0k-manage
  9. ##
  10. mkdir -p /opt/apps
  11. (
  12. if [ -d "/opt/apps/0k-manage" ]; then
  13. cd /opt/apps/0k-manage &&
  14. git pull -r
  15. else
  16. cd /opt/apps &&
  17. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-manage.git" &&
  18. cd /opt/apps/0k-manage &&
  19. git checkout 0k/prod/master
  20. fi
  21. pip install sact.epoch || exit 1
  22. if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "ImportError: No module named interface" ]; then
  23. echo "Error: conflicting installation of zope.interface detected. Trying workaround."
  24. (
  25. cd /usr/local/lib/python2.7/dist-packages
  26. mv zope zope-bad
  27. ) &&
  28. pip install zope.interface --upgrade &&
  29. pip install zope.component --upgrade
  30. if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "" ]; then
  31. echo "Workaround worked."
  32. else
  33. echo "Failed work around."
  34. exit 1
  35. fi
  36. fi
  37. # ln -sf /opt/apps/0k-manage/src/bin/* /usr/local/bin/
  38. )
  39. ##
  40. ## Install 0k-charm
  41. ##
  42. (
  43. apt-get install -y kal-shlib-charm kal-shlib-cache kal-shlib-cmdline </dev/null
  44. if [ -d "/opt/apps/0k-charm" ]; then
  45. cd /opt/apps/0k-charm &&
  46. git checkout master &&
  47. git pull -r
  48. else
  49. cd /opt/apps &&
  50. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charm.git"
  51. fi
  52. ln -sfn /opt/apps/0k-charm/bin/charm /usr/local/sbin/
  53. )
  54. ##
  55. ## Install 0k-charms
  56. ##
  57. (
  58. if [ -d "/opt/apps/0k-charms" ]; then
  59. cd /opt/apps/0k-charms &&
  60. git checkout master &&
  61. git pull -r
  62. else
  63. cd /opt/apps &&
  64. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charms.git"
  65. fi
  66. if ! [ -d "/srv/charm-store" ]; then
  67. mkdir -p /srv/charm-store
  68. fi
  69. ln -sfn /opt/apps/0k-charms /srv/charm-store/0k-charms
  70. )
  71. ##
  72. ## Install lxc-scripts
  73. ##
  74. (
  75. if ! [ -d "/opt/apps/lxc-scripts" ]; then
  76. cd /opt/apps &&
  77. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/lxc-scripts.git"
  78. fi
  79. cd /opt/apps/lxc-scripts &&
  80. git checkout master &&
  81. git pull -r &&
  82. ln -sfn /opt/apps/lxc-scripts/bin/lxc-* /usr/local/sbin/ &&
  83. if [ -f /etc/default/lxc ]; then
  84. if [ -f /etc/default/lxc.pre-install ]; then
  85. cp /etc/default/lxc.pre-install /etc/default/lxc
  86. else
  87. cp /etc/default/lxc /etc/default/lxc.pre-install
  88. fi
  89. [ -d /usr/lib/lxc/templates ] && {
  90. ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/lib/lxc/templates/
  91. echo TEMPLATE_PATH=/usr/lib/lxc/templates >> /etc/default/lxc
  92. }
  93. [ -d /usr/share/lxc/templates ] && {
  94. ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/share/lxc/templates
  95. echo TEMPLATE_PATH=/usr/share/lxc/templates >> /etc/default/lxc
  96. }
  97. fi
  98. )
  99. ##
  100. ## Install 0k-docker
  101. ##
  102. (
  103. if [ -d "/opt/apps/0k-docker" ]; then
  104. cd /opt/apps/0k-docker &&
  105. git checkout master &&
  106. git pull -r
  107. else
  108. cd /opt/apps &&
  109. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-docker"
  110. fi
  111. ln -sfn /opt/apps/0k-docker/bin/* /usr/local/sbin/
  112. ## in update, will remove broken links to binaries that were removed
  113. find -L /usr/local/sbin -maxdepth 1 -type l -delete
  114. )
  115. ##
  116. ## Install 0k.io certificate authority
  117. ##
  118. ## Note that docker should be installed after (or be restarted).
  119. apt-get install -y curl </dev/null
  120. ## This does not seem to work anymore (docker v1.12, ubutnu 14.04 on gani)
  121. echo "Fetching 0k.io CA certificate..."
  122. curl http://docker.0k.io/get/ca.0k.io.pem > /etc/ssl/ca.0k.io.pem
  123. cat /etc/ssl/ca.0k.io.pem >> /etc/ssl/certs/ca-certificates.crt
  124. ## This is the new way: https://docs.docker.com/engine/security/certificates/
  125. mkdir -p /etc/docker/certs.d/docker.0k.io
  126. ln -sfn /etc/ssl/ca.0k.io.pem /etc/docker/certs.d/docker.0k.io/ca.crt
  127. service docker restart
  128. echo "Login into our server."
  129. docker login -u vm -p iamavm https://docker.0k.io
  130. sed -ri 's/^#(net\.ipv4\.ip_forward=1)$/\1/g' /etc/sysctl.conf
  131. sysctl -w net.ipv4.ip_forward=1
  132. ##
  133. ## docker-compose
  134. ##
  135. if type -p docker-compose >/dev/null; then
  136. #echo "Found docker-compose..." >&2
  137. if ! CURRENT_VERSION_TEXT="$(docker-compose --version 2>/dev/null)"; then
  138. echo "'docker-compose' failed ! Please check your docker-compose binary."
  139. echo "Failed install."
  140. docker-compose --version
  141. exit 1
  142. fi
  143. VALID_VERSION_TEXT="docker-compose version 1.21.2, build "
  144. if ! [[ "$CURRENT_VERSION_TEXT" == "$VALID_VERSION_TEXT"* ]]; then
  145. echo "Invalid version of docker-compose: we need exactly:"
  146. echo "version text: $VALID_VERSION_TEXT"
  147. echo "current version: $CURRENT_VERSION_TEXT"
  148. echo "Failed install."
  149. exit 1
  150. fi
  151. else
  152. if ! [ -d /opt/apps/docker-compose ]; then
  153. (
  154. mkdir -p /opt/apps
  155. cd /opt/apps
  156. git clone https://github.com/docker/compose.git docker-compose &&
  157. cd docker-compose &&
  158. git checkout 0898c783ad2e0d01bd55b47fcb9eb7183edc1015 ## version pinning
  159. )
  160. fi
  161. mkdir -p /opt/venv
  162. if ! type -p virtualenv >/dev/null; then
  163. pip install virtualenv==13.1.2
  164. fi
  165. if ! [ -d /opt/venv/docker-compose ]; then
  166. virtualenv /opt/venv/docker-compose/
  167. fi
  168. set +eux
  169. . /opt/venv/docker-compose/bin/activate
  170. set -eux
  171. ## XXXvlab: docker version 3.5.0 is bugged on its requirement list:
  172. ## error: Setup script exited with error in docker setup command: 'tests_require' must be a string or list of strings containing valid project/version requirement specifiers; Expected ',' or end-of-list in pytest==2.9.1; python_version == '3.3' at ; python_version == '3.3'
  173. pip install $(cat <<EOF
  174. backports.ssl-match-hostname==3.5.0.1
  175. cached-property==1.4.3
  176. certifi==2018.4.16
  177. chardet==3.0.4
  178. docker==3.4.1
  179. docker-compose==1.21.2
  180. docker-pycreds==0.3.0
  181. dockerpty==0.4.1
  182. docopt==0.6.2
  183. enum34==1.1.6
  184. functools32==3.2.3.post2
  185. idna==2.5
  186. ipaddress==1.0.22
  187. jsonschema==2.6.0
  188. python-dateutil==2.7.3
  189. pytz==2018.5
  190. PyYAML==3.13
  191. requests==2.17.3
  192. sact.epoch==1.3.0
  193. shyaml==0.5.2
  194. six==1.11.0
  195. texttable==0.9.1
  196. urllib3==1.21.1
  197. websocket-client==0.48.0
  198. wheel==0.24.0
  199. zope.component==4.4.1
  200. zope.event==4.3.0
  201. zope.interface==4.5.0
  202. EOF
  203. )
  204. ( cd /opt/apps/docker-compose &&
  205. python setup.py install )
  206. if ! pip freeze | grep "^requests==2.17.3\$" >/dev/null 2>&1; then
  207. pip install requests==2.17.3 --upgrade
  208. fi
  209. deactivate
  210. mkdir -p /etc/compose
  211. if ! grep "^. /opt/venv/docker-compose/bin/activate$" /etc/compose/local.conf >/dev/null 2>&1; then
  212. cat <<EOF >> /etc/compose/local.conf
  213. . /opt/venv/docker-compose/bin/activate
  214. EOF
  215. fi
  216. fi
  217. ##
  218. ## Installation of compose
  219. ##
  220. apt-get install kal-shlib-common kal-shlib-pretty kal-shlib-charm kal-shlib-array -y --force-yes </dev/null
  221. if [ -d "/opt/apps/0k-compose" ]; then
  222. cd "/opt/apps/0k-compose" &&
  223. git pull -r
  224. else
  225. mkdir -p /opt/apps && cd /opt/apps
  226. git clone "$GIT_0K_BASE"/0k/0k-compose.git
  227. fi
  228. [ -e /usr/local/bin/compose ] || ln -sfv /opt/apps/0k-compose/bin/compose /usr/local/bin/
  229. rm -rf /var/cache/compose
  230. cat <<EOF > /etc/default/datastore
  231. DATASTORE=/srv/datastore
  232. SNAPSHOT_BACKUP=/var/backups/snapshot
  233. EOF
  234. cat <<EOF > /etc/default/compose
  235. ## if not provided, this will be the default service launched.
  236. export DEFAULT_SERVICES=""
  237. export DEFAULT_PROJECT_NAME=$(hostname | cut -f 2 -d . )
  238. export DOCKER_DATASTORE=\$([ -e /etc/default/datastore ] && . /etc/default/datastore && echo \$DATASTORE)
  239. export DATASTORE=\$DOCKER_DATASTORE/data
  240. export CONFIGSTORE=\$DOCKER_DATASTORE/config
  241. EOF
  242. if ! egrep "^DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then
  243. echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf
  244. fi
  245. ##
  246. ## Install pgm
  247. ##
  248. (
  249. if [ -d "/opt/apps/0k-pgm" ]; then
  250. cd /opt/apps/0k-pgm &&
  251. git pull -r
  252. else
  253. cd /opt/apps &&
  254. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-pgm.git" &&
  255. cd /opt/apps/0k-pgm &&
  256. git checkout master
  257. fi
  258. ln -sf /opt/apps/0k-pgm/bin/* /usr/local/bin/
  259. apt-get install -y --force-yes pv buffer < /dev/null
  260. apt-get install -y postgresql-client </dev/null
  261. )