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.

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