[buildout]
extends =
  buildout.hash.cfg
  ../../stack/slapos.cfg
  ../../component/dash/buildout.cfg
  ../../component/caddy/buildout.cfg
  ../../component/gzip/buildout.cfg
  ../../component/logrotate/buildout.cfg
  ../../component/rdiff-backup/buildout.cfg
  ../../component/trafficserver/buildout.cfg
  ../../component/6tunnel/buildout.cfg
  ../../component/xz-utils/buildout.cfg

  ../../stack/caucase/buildout.cfg
# Monitoring stack (keep on bottom)
  ../../stack/monitor/buildout.cfg

parts +=
  template
  template-caddy-frontend
  template-caddy-replicate
  caddy

  logrotate
  rdiff-backup
  caddyprofiledeps

  kedifa-develop
  kedifa

[kedifa-repository]
recipe = slapos.recipe.build:gitclone
repository = https://lab.nexedi.com/nexedi/kedifa.git
git-executable = ${git:location}/bin/git
revision = d6bbd7db215e12871c1536f22a8fbf994227270c

[kedifa-develop]
recipe = zc.recipe.egg:develop
setup = ${kedifa-repository:location}

[kedifa]
recipe = zc.recipe.egg
eggs =
  ${python-cryptography:egg}
  kedifa

[caddyprofiledeps-setup]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/setup.py

[caddyprofiledeps-dummy]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/caddyprofiledummy.py

[caddyprofiledeps-prepare]
recipe = plone.recipe.command
stop-on-error = True
location = ${buildout:parts-directory}/${:_buildout_section_name_}
update-command = ${:command}
command =
  rm -fr ${:location} &&
  mkdir -p ${:location} &&
  cp ${caddyprofiledeps-setup:target} ${:location}/ &&
  cp ${caddyprofiledeps-dummy:target} ${:location}/

[caddyprofiledeps-develop]
recipe = zc.recipe.egg:develop
setup = ${caddyprofiledeps-prepare:location}

[caddyprofiledeps]
depends = ${caddyprofiledeps-develop:recipe}
recipe = zc.recipe.egg
eggs =
  caddyprofiledeps

# Extent extra-eggs.
[extra-eggs]
eggs +=
  websockify
  erp5.util
  ${caucase-eggs:eggs}
  collective.recipe.shelloutput

[template-common]
recipe = slapos.recipe.template:jinja2
template = ${:_profile_base_location_}/instance-common.cfg.in
rendered = ${buildout:directory}/instance-common.cfg
mode = 0644
context =
  key develop_eggs_directory buildout:develop-eggs-directory
  key eggs_directory buildout:eggs-directory

[template-frontend-parameter-section]
common_profile = ${template-common:rendered}
logrotate_base_instance = ${template-logrotate-base:rendered}

bin_directory = ${buildout:bin-directory}

sixtunnel = ${6tunnel:location}
caddy = ${caddy:output}
caddy_location = ${caddy:location}
curl = ${curl:location}
dash = ${dash:location}
gzip = ${gzip:location}
logrotate = ${logrotate:location}
openssl = ${openssl:location}/bin/openssl
openssl_cnf = ${openssl:location}/etc/ssl/openssl.cnf
trafficserver = ${trafficserver:location}
sha256sum = ${coreutils:location}/bin/sha256sum
kedifa = ${:bin_directory}/kedifa
kedifa-updater = ${:bin_directory}/kedifa-updater
kedifa-csr = ${:bin_directory}/kedifa-csr
xz_location = ${xz-utils:location}

monitor_template = ${monitor-template:output}
template_cached_slave_virtualhost = ${template-cached-slave-virtualhost:target}
template_caddy_frontend_configuration = ${template-caddy-frontend-configuration:target}
template_graceful_script = ${template-graceful-script:target}
template_validate_script = ${template-validate-script:target}
template_rotate_script = ${template-rotate-script:target}
template_configuration_state_script = ${template-configuration-state-script:target}
template_caddy_lazy_script_call = ${template-caddy-lazy-script-call:target}
template_default_slave_virtualhost = ${template-default-slave-virtualhost:target}
template_empty = ${template-empty:target}
template_log_access = ${template-log-access:target}
template_not_found_html = ${template-not-found-html:target}
template_slave_configuration = ${template-slave-configuration:target}
template_slave_list = ${template-slave-list:target}
template_trafficserver_records_config = ${template-trafficserver-records-config:location}
template_trafficserver_records_config_filename = ${template-trafficserver-records-config:filename}
template_trafficserver_records_config_location = ${template-trafficserver-records-config:location}
template_trafficserver_storage_config_filename = ${template-trafficserver-storage-config:filename}
template_trafficserver_storage_config_location = ${template-trafficserver-storage-config:location}
template_trafficserver_logging_config_filename = ${template-trafficserver-logging-config:filename}
template_trafficserver_logging_config_location = ${template-trafficserver-logging-config:location}
template_wrapper = ${template-wrapper:output}

[template]
recipe = slapos.recipe.template:jinja2
template = ${:_profile_base_location_}/instance.cfg.in
rendered = ${buildout:directory}/template.cfg
mode = 0644
context =
  key common_profile template-common:rendered

  key monitor2_template monitor2-template:rendered
  key template_caddy_frontend template-caddy-frontend:target
  key template_caddy_replicate template-caddy-replicate:target
  key template_kedifa template-kedifa:target
  key template_replicate_publish_slave_information template-replicate-publish-slave-information:target
  key caddy_backend_url_validator caddy-backend-url-validator:output

  section template_frontend_parameter_dict template-frontend-parameter-section
  key caucase_jinja2_library caucase-jinja2-library:target

[template-caddy-frontend]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/instance-apache-frontend.cfg.in
mode = 0644

[caddy-backend-url-validator]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/${:filename}
filename = caddy-backend-url-validator.in
output = ${buildout:directory}/caddy-backend-url-validator
mode = 0750

[template-caddy-replicate]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/instance-apache-replicate.cfg.in
mode = 0644

[template-kedifa]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/instance-kedifa.cfg.in
mode = 0644

[download-template]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/templates/${:filename}
mode = 640

[template-slave-list]
<=download-template
filename = apache-custom-slave-list.cfg.in

[template-slave-configuration]
<=download-template
filename = custom-virtualhost.conf.in

[template-replicate-publish-slave-information]
<=download-template
filename = replicate-publish-slave-information.cfg.in

[template-caddy-frontend-configuration]
<=download-template
filename = Caddyfile.in

[template-not-found-html]
<=download-template
filename = notfound.html

[template-default-slave-virtualhost]
<=download-template
filename = default-virtualhost.conf.in

[template-cached-slave-virtualhost]
<=download-template
filename = cached-virtualhost.conf.in

[template-log-access]
<=download-template
filename = template-log-access.conf.in

[template-empty]
<=download-template
filename = empty.in

[template-wrapper]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/wrapper.in
output = ${buildout:directory}/template-wrapper.cfg
mode = 0644

[template-trafficserver-records-config]
<=download-template
url = ${:_profile_base_location_}/templates/trafficserver/${:filename}
filename = records.config.jinja2

[template-trafficserver-storage-config]
<=download-template
url = ${:_profile_base_location_}/templates/trafficserver/${:filename}
filename = storage.config.jinja2

[template-trafficserver-logging-config]
<=download-template
url = ${:_profile_base_location_}/templates/trafficserver/${:filename}
filename = logging.config.jinja2

[template-rotate-script]
<=download-template
filename = rotate-script.sh.in

[template-caddy-lazy-script-call]
<=download-template
filename = apache-lazy-script-call.sh.in

[template-graceful-script]
<=download-template
filename = graceful-script.sh.in

[template-validate-script]
<=download-template
filename = validate-script.sh.in

[template-configuration-state-script]
<=download-template
filename = configuration-state-script.sh.in