[buildout]
parts =
  qjs-launcher
  publish-connection-information

eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true

[slap-configuration]
recipe = slapos.cookbook:slapconfiguration.serialised
computer = $${slap_connection:computer_id}
partition = $${slap_connection:partition_id}
url = $${slap_connection:server_url}
key = $${slap_connection:key_file}
cert = $${slap_connection:cert_file}

[directory]
recipe = slapos.cookbook:mkdirectory

home = $${buildout:directory}
bin = $${:home}/bin
etc = $${:home}/etc
srv = $${:home}/srv
var = $${:home}/var

log = $${:var}/log
public = $${:srv}/public
service = $${:etc}/service

[peer-configuration]
recipe = slapos.recipe.template:jinja2
output = $${directory:etc}/configuration.json
extensions = jinja2.ext.do
extra-context =
context =
  import json_module json
  key parameter_dict slap-configuration:configuration
  $${:extra-context}
inline =
  {{ json_module.dumps(parameter_dict) }}

[js-dynamic-template]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:etc}/$${:_buildout_section_name_}.js
extra-context =
context =
  key configuration peer-configuration:output
  key isADrone slap-configuration:configuration.isADrone
  raw qjs_wrapper ${qjs-wrapper:location}/lib/libqjswrapper.so
  $${:extra-context}

[main]
<= js-dynamic-template
template = ${main:target}
extra-context =
  key log_dir directory:log
  key pubsub_script pubsub:rendered
  key worker_script worker:rendered

[pubsub]
<= js-dynamic-template
template = ${pubsub:target}

[worker]
<= js-dynamic-template
template = ${worker:target}
gwsocket_bin =
extra-context =
  key gwsocket_bin :gwsocket_bin

[user]
recipe = slapos.recipe.build:download
url = $${slap-configuration:configuration.flightScript}
destination = $${directory:etc}/user.js
offline = false

[qjs-launcher]
recipe = slapos.cookbook:wrapper
wrapper-path = $${directory:service}/qjs-launcher
command-line = ${quickjs:location}/bin/qjs $${main:rendered} $${user:target}

[publish-connection-information]
recipe = slapos.cookbook:publish.serialised
instance-path = $${directory:home}
