docker-compose.yaml 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. {% from "webdav_macros/httpd.conf" import httpd_conf %}
  2. {% from "webdav_macros/webdav_http.conf" import webdav_http %}
  3. {% from "webdav_macros/webdav_https.conf" import webdav_https %}
  4. {% set tpl = ix_lib.base.render.Render(values) %}
  5. {% if not values.network.http_port.bind_mode and not values.network.https_port.bind_mode %}
  6. {% do tpl.funcs.fail("Must enable at least one of http or https ports") %}
  7. {% endif %}
  8. {% if values.network.https_port.bind_mode and not values.network.certificate_id %}
  9. {% do tpl.funcs.fail("Must provide a certificate id if enabling https") %}
  10. {% endif %}
  11. {% set c1 = tpl.add_container(values.consts.webdav_container_name, "image") %}
  12. {% set perm_container = tpl.deps.perms(values.consts.perms_container_name) %}
  13. {% set perms_config = {"uid": values.run_as.user, "gid": values.run_as.group, "mode": "check"} %}
  14. {% do c1.set_user(values.run_as.user, values.run_as.group) %}
  15. {% do c1.healthcheck.set_test("tcp", {"port": values.network.http_port.port_number if values.network.http_port.bind_mode else values.network.https_port.port_number}) %}
  16. {% do c1.environment.add_user_envs(values.webdav.additional_envs) %}
  17. {% do c1.configs.add("httpd-conf", httpd_conf(values), values.consts.httpd_conf_path) %}
  18. {% if values.network.certificate_id %}
  19. {% set cert = values.ix_certificates[values.network.certificate_id] %}
  20. {% do c1.configs.add("public", cert.certificate, values.consts.ssl_cert_path) %}
  21. {% do c1.configs.add("private", cert.privatekey, values.consts.ssl_key_path) %}
  22. {% endif %}
  23. {% if values.webdav.auth_type != "none" %}
  24. {% do c1.configs.add("htauth", tpl.funcs.htpasswd(values.webdav.username, values.webdav.password), "%s%s"|format(values.consts.auth_file_base, values.webdav.auth_type)) %}
  25. {% endif %}
  26. {% if values.network.http_port.bind_mode %}
  27. {% do c1.add_port(values.network.http_port) %}
  28. {% do c1.configs.add("webdav-http-config", webdav_http(values), values.consts.webdav_http_config_path) %}
  29. {% endif %}
  30. {% if values.network.https_port.bind_mode %}
  31. {% do c1.add_port(values.network.https_port) %}
  32. {% do c1.configs.add("webdav-https-config", webdav_https(values), values.consts.webdav_https_config_path) %}
  33. {% endif %}
  34. {% set tmp_config = {"type": "temporary", "volume_config": {"volume_name": "webdav-tmp"}} %}
  35. {% do c1.add_storage("/tmp", tmp_config) %}
  36. {% do perm_container.add_or_skip_action("webdav-tmp", tmp_config, perms_config) %}
  37. {# Stores PID file and DavLockDB file #}
  38. {% do c1.add_storage(values.consts.pid_base_path, {"type": "tmpfs", "tmpfs_config": {"mode": "0777", "size": 100}}) %}
  39. {% set share_names = namespace(x=[]) %}
  40. {% for share in values.storage.shares %}
  41. {% if not tpl.funcs.match_regex(share.name, "^[a-zA-Z0-9_-]+$") %}
  42. {% do tpl.funcs.fail("Share name must consist only of [Letters(a-z, A-Z), Numbers(0-9), Underscores(_), Dashes(-)], but got [%s]"|format(share.name)) %}
  43. {% endif %}
  44. {% do share_names.x.append(share.name) %}
  45. {% set store_config = {
  46. "type": "host_path",
  47. "read_only": share.read_only,
  48. "mount_path": "/%s/%s"|format(values.consts.shares_prefix, share.name),
  49. "host_path_config": {
  50. "auto_permissions": share.fix_permissions,
  51. "create_host_path": share.get("create_host_path", False),
  52. "path": share.host_path,
  53. }
  54. } %}
  55. {% do c1.add_storage(store_config.mount_path, store_config) %}
  56. {% do perm_container.add_or_skip_action(share.name, dict(store_config, **{"read_only": False}), perms_config) %}
  57. {% endfor %}
  58. {% if share_names.x | length != share_names.x | unique | list | length %}
  59. {% do tpl.funcs.fail("Share names must be unique, but got [%s]"|format(share_names.x | join(", "))) %}
  60. {% endif %}
  61. {% if perm_container.has_actions() %}
  62. {% do perm_container.activate() %}
  63. {% do c1.depends.add_dependency(values.consts.perms_container_name, "service_completed_successfully") %}
  64. {% endif %}
  65. {{ tpl.render() | tojson }}