[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

  ../../stack/nodejs.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
  npm-modules
  proxy-by-url
  http-proxy
  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 = 67bd60ea1bfb4fc6aafdfe4fa204f725731f20cf

[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 = ${trafficserver7:location}
sha256sum = ${coreutils:location}/bin/sha256sum
kedifa = ${:bin_directory}/kedifa
kedifa-getter = ${:bin_directory}/kedifa-getter
kedifa-csr = ${:bin_directory}/kedifa-csr

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_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_nging_configuration = ${template-nginx-configuration:output}
template_nginx_eventsource_slave_virtualhost = ${template-nginx-eventsource-slave-virtualhost:target}
template_nginx_notebook_slave_virtualhost = ${template-nginx-notebook-slave-virtualhost: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
  key caddy_custom_http_validator caddy-custom-http-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

[caddy-custom-http-validator]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/${:filename}
filename = caddy-custom-http-validator.in
output = ${buildout:directory}/caddy-custom-http-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

# NGINX Configuration
[template-nginx-configuration]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/nginx.cfg.in
output = ${buildout:directory}/template-nginx.cfg.in
mode = 0644

[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-nginx-eventsource-slave-virtualhost]
<=download-template
filename = nginx-eventsource-slave.conf.in

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

# Migrated from KVM recipe
[http-proxy]
# https://github.com/nodejitsu/node-http-proxy
recipe = slapos.recipe.build:download-unpacked
# use upstream when merged
url = https://lab.nexedi.com/nexedi/node-http-proxy/repository/archive.zip?ref=a5d3aff428ee8d840068b439f6ce121077f1144f
md5sum = 65602466066444c718215de41f546585

[proxy-by-url]
# https://github.com/dominictarr/proxy-by-url
recipe = slapos.recipe.build:download-unpacked
# use upstream when merged
url = https://lab.nexedi.com/nexedi/proxy-by-url/repository/archive.zip?ref=59fcb11a3e00c45b4b0362e76f29653abb313072
md5sum = c383e0c5ff31b56f7987466e8304c941

[npm-modules]
recipe = plone.recipe.command
destination = ${buildout:parts-directory}/${:_buildout_section_name_}
location = ${buildout:parts-directory}/${:_buildout_section_name_}
command =
  export HOME=${:location};
  rm -fr ${:destination} &&
  mkdir -p ${:destination} &&
  cd ${:destination} &&
  ${nodejs:location}/bin/node ${nodejs:location}/bin/npm install colors@0.6.0-1 &&
  ${nodejs:location}/bin/node ${nodejs:location}/bin/npm install socket.io@0.8.7 &&
  ${nodejs:location}/bin/node ${nodejs:location}/bin/npm install socket.io-client@0.8.7 &&
  ${nodejs:location}/bin/node ${nodejs:location}/bin/npm install optimist@0.3.1 &&
  ${nodejs:location}/bin/node ${nodejs:location}/bin/npm install pkginfo@0.2.3
