[buildout]
parts =
  symlinks
  publish
  postgres-instance
  postgres-promise


# Define egg directories to be the one from Software Release
# (/opt/slapgrid/...)
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true


[directories]
recipe = slapos.cookbook:mkdirectory
bin = $${buildout:directory}/bin
etc = $${buildout:directory}/etc
services = $${directories:etc}/service
promises = $${directories:etc}/promise
var = $${buildout:directory}/var


[symlinks]
recipe = cns.recipe.symlink
symlink_target = $${directories:bin}
symlink_base = ${postgresql:location}/bin


#----------------
#--
#-- Creates a Postgres cluster, configuration files, and a database.

[postgres-instance]
recipe = slapos.cookbook:postgres

# Options
ipv6 = $${instance-parameters:ipv6}
ipv4 = $${instance-parameters:ipv4}
ipv6_random = $${instance-parameters:ipv6_random}
user = user
port = 5432
dbname = db
# pgdata_directory is created by initdb, and should not exist beforehand.
pgdata-directory = $${directories:var}/data
bin = $${directories:bin}
services = $${directories:services}


#----------------
#--
#-- Deploy promise scripts.

[postgres-promise]
recipe = slapos.cookbook:check_port_listening
path = $${directories:promises}/postgres
hostname = $${instance-parameters:ipv6_random}
port = $${postgres-instance:port}


#----------------
#--
#-- Publish instance parameters.

[publish]
recipe = slapos.cookbook:publish
url = $${postgres-instance:url}


#----------------
#--
#-- Fetches parameters defined in SlapOS Master for this instance

[instance-parameters]
# Fetches parameters defined in SlapOS Master for this instance
recipe = slapos.cookbook:slapconfiguration
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}