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.

234 lines
5.1 KiB

  1. #!/bin/bash
  2. exname=$(basename $0)
  3. prefix_cmd="
  4. . /etc/shlib
  5. include common
  6. include parse
  7. . ../lib/common
  8. "
  9. ##
  10. ## Mocks
  11. ##
  12. relation-get() {
  13. local key="$1"
  14. echo "$CFG" | shyaml get-value "$key" 2>/dev/null
  15. }
  16. export -f relation-get
  17. get_service_relations() {
  18. printf "%s\0" "${RELATIONS[@]}"
  19. }
  20. export -f get_service_relations
  21. file_put() {
  22. echo "file_put $1"
  23. cat - | prefix " | "
  24. }
  25. export -f file_put
  26. docker() {
  27. echo "docker" "$@"
  28. echo stdin:
  29. cat - | prefix " | "
  30. }
  31. export -f docker
  32. config-add() {
  33. echo "config-add"
  34. echo "$1" | prefix " | "
  35. }
  36. export -f config-add
  37. mkdir() {
  38. echo "called: $FUNCNAME $@" >&2
  39. }
  40. export -f mkdir
  41. setfacl() {
  42. echo "called: $FUNCNAME $@" >&2
  43. }
  44. export -f setfacl
  45. chgrp() {
  46. echo "called: $FUNCNAME $@" >&2
  47. }
  48. export -f chgrp
  49. chmod() {
  50. echo "called: $FUNCNAME $@" >&2
  51. }
  52. export -f chmod
  53. cached_cmd_on_base_image() {
  54. echo "called: $FUNCNAME $@" >&2
  55. echo "stdout:" >&2
  56. echo "<GID>" | prefix " | " >&2
  57. echo "<GID>"
  58. }
  59. export -f cached_cmd_on_base_image
  60. ##
  61. ## apache_vhost_create
  62. ##
  63. try "
  64. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  65. DOMAIN=www.example.com
  66. DOCKER_SITE_PATH=/var/www/\$DOMAIN
  67. apache_vhost_create"
  68. noerror
  69. is out reg '^file_put \$SERVICE_CONFIGSTORE/.*/www.example.com.conf'
  70. try "
  71. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  72. DOMAIN=www.example.com
  73. DOCKER_SITE_PATH=/var/www/\$DOMAIN
  74. CFG='
  75. ssl: true
  76. '
  77. apache_vhost_create"
  78. noerror
  79. is out reg '^file_put \$SERVICE_CONFIGSTORE/.*/www.example.com.conf'
  80. is err ''
  81. try "
  82. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  83. export CONFIGSTORE='\$CONFIGSTORE'
  84. export BASE_SERVICE_NAME='\$BASE_SERVICE_NAME'
  85. export MASTER_TARGET_SERVICE_NAME='\$MASTER_TARGET_SERVICE_NAME'
  86. DOMAIN=www.example.com
  87. DOCKER_SITE_PATH=/var/www/\$DOMAIN
  88. CFG='
  89. ssl:
  90. key: |
  91. a
  92. b
  93. cert: c
  94. '
  95. apache_vhost_create"
  96. noerror
  97. is out part 'file_put $CONFIGSTORE/$BASE_SERVICE_NAME/etc/ssl/certs/www.example.com.pem
  98. | c'
  99. is out part 'file_put $CONFIGSTORE/$BASE_SERVICE_NAME/etc/ssl/private/www.example.com.key
  100. | a
  101. | b'
  102. is out reg 'config-add'
  103. is out reg ' - \$CONFIGSTORE/\$BASE_SERVICE_NAME/etc/ssl/certs/www.example.com.pem:/etc/ssl/certs/www.example.com.pem:ro'
  104. is out reg ' - \$CONFIGSTORE/\$BASE_SERVICE_NAME/etc/ssl/private/www.example.com.key:/etc/ssl/private/www.example.com.key:ro'
  105. try "
  106. export DOCKER_BASE_IMAGE=docker/apache
  107. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  108. export CONFIGSTORE='\$CONFIGSTORE'
  109. export BASE_SERVICE_NAME='\$BASE_SERVICE_NAME'
  110. export MASTER_TARGET_SERVICE_NAME='\$MASTER_TARGET_SERVICE_NAME'
  111. DOMAIN=www.example.com
  112. DOCKER_SITE_PATH=/var/www/\$DOMAIN
  113. export CFG='
  114. creds:
  115. toto: xxx
  116. '
  117. apache_vhost_create"
  118. noerror
  119. is out reg "htpasswd -bc '/etc/apache2/sites-enabled/www.example.com.passwd' 'toto' 'xxx'"
  120. is out reg 'docker run -i --entrypoint /bin/bash .* docker/apache'
  121. ##
  122. ## apache_proxy_dir
  123. ##
  124. try "
  125. export DOCKER_BASE_IMAGE=docker/apache
  126. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  127. export CONFIGSTORE='\$CONFIGSTORE'
  128. export BASE_SERVICE_NAME='\$BASE_SERVICE_NAME'
  129. export MASTER_TARGET_SERVICE_NAME='\$MASTER_TARGET_SERVICE_NAME'
  130. export CFG='
  131. creds:
  132. toto: xxx
  133. '
  134. apache_publish_dir"
  135. is errlvl 1 ## no domain
  136. try "
  137. export DATASTORE='\$DATASTORE'
  138. export DOCKER_BASE_IMAGE=docker/apache
  139. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  140. export CONFIGSTORE='\$CONFIGSTORE'
  141. export BASE_SERVICE_NAME='\$BASE_SERVICE_NAME'
  142. export MASTER_TARGET_SERVICE_NAME='\$MASTER_TARGET_SERVICE_NAME'
  143. export CFG='
  144. domain: www.example.com
  145. creds:
  146. toto: xxx
  147. '
  148. apache_publish_dir"
  149. is errlvl 0
  150. is err reg 'setfacl -R -m g:<GID>:rx \$DATASTORE/\$BASE_SERVICE_NAME/var/www/www.example.com'
  151. is err reg 'cached_cmd_on_base_image apache id -g www-data'
  152. try "
  153. export DATASTORE='\$DATASTORE'
  154. export DOCKER_BASE_IMAGE=docker/apache
  155. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  156. export CONFIGSTORE='\$CONFIGSTORE'
  157. export BASE_SERVICE_NAME='\$BASE_SERVICE_NAME'
  158. export MASTER_TARGET_SERVICE_NAME='\$MASTER_TARGET_SERVICE_NAME'
  159. export CFG='
  160. domain: www.example.com
  161. creds:
  162. toto: xxx
  163. data-dirs:
  164. - a
  165. - b
  166. - c
  167. '
  168. apache_publish_dir"
  169. is errlvl 0
  170. is err reg 'setfacl -R -m g:<GID>:rwx \$DATASTORE/\$BASE_SERVICE_NAME/var/www/www.example.com/a \$DATASTORE/\$BASE_SERVICE_NAME/var/www/www.example.com/b \$DATASTORE/\$BASE_SERVICE_NAME/var/www/www.example.com/c'
  171. is err reg 'setfacl -R -d -m g:<GID>:rwx \$DATASTORE/\$BASE_SERVICE_NAME/var/www/www.example.com/a \$DATASTORE/\$BASE_SERVICE_NAME/var/www/www.example.com/b \$DATASTORE/\$BASE_SERVICE_NAME/var/www/www.example.com/c'
  172. try "
  173. export DATASTORE='\$DATASTORE'
  174. export DOCKER_BASE_IMAGE=docker/apache
  175. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  176. export CONFIGSTORE='\$CONFIGSTORE'
  177. export BASE_SERVICE_NAME='\$BASE_SERVICE_NAME'
  178. export MASTER_BASE_SERVICE_NAME='\$MASTER_BASE_SERVICE_NAME'
  179. export MASTER_TARGET_SERVICE_NAME='\$MASTER_TARGET_SERVICE_NAME'
  180. export CFG='
  181. domain: www.example.com
  182. location: /opt/apps/newlocation
  183. creds:
  184. toto: xxx
  185. data-dirs:
  186. - a
  187. - b
  188. - c
  189. '
  190. apache_publish_dir"
  191. is errlvl 0
  192. is err reg 'mkdir -p /opt/apps/newlocation'
  193. is err reg 'setfacl -R -m g:<GID>:rx /opt/apps/newlocation'
  194. is out part ' | $MASTER_BASE_SERVICE_NAME:
  195. | volumes:
  196. | - /opt/apps/newlocation:/var/www/www.example.com'