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.

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