Commit eb270605 authored by Kirill Smelkov's avatar Kirill Smelkov

helloworld: Convert instance.cfg.in to jinja2

Jinja2 is currently the preferred way to do instance templating, because
it has control structures.

We'll need control structures in the following patches, but even without
it, it is better to show "how to" do instances the preferred way.

/cc @jerome
parent e3a11eaa
...@@ -13,8 +13,8 @@ parts = ...@@ -13,8 +13,8 @@ parts =
# Define egg directories to be the one from Software Release # Define egg directories to be the one from Software Release
# (/opt/slapgrid/...) # (/opt/slapgrid/...)
# Always the same. # Always the same.
eggs-directory = ${buildout:eggs-directory} eggs-directory = {{ buildout['eggs-directory'] }}
develop-eggs-directory = ${buildout:develop-eggs-directory} develop-eggs-directory = {{ buildout['develop-eggs-directory'] }}
offline = true offline = true
...@@ -23,15 +23,15 @@ offline = true ...@@ -23,15 +23,15 @@ offline = true
# We use the slapconfiguration recipe with a few parameters (partition id, # We use the slapconfiguration recipe with a few parameters (partition id,
# computer id, certificate, etc). # computer id, certificate, etc).
# It will then authenticate to SlapOS Master and fetch the instance parameters. # It will then authenticate to SlapOS Master and fetch the instance parameters.
# The parameters are accessible from $${instance-parameter:configuration.name-of-parameter} # The parameters are accessible from ${instance-parameter:configuration.name-of-parameter}
# Always the same. Just copy/paste. # Always the same. Just copy/paste.
# See docstring of slapos.cookbook:slapconfiguration for more information. # See docstring of slapos.cookbook:slapconfiguration for more information.
recipe = slapos.cookbook:slapconfiguration recipe = slapos.cookbook:slapconfiguration
computer = $${slap_connection:computer_id} computer = ${slap_connection:computer_id}
partition = $${slap_connection:partition_id} partition = ${slap_connection:partition_id}
url = $${slap_connection:server_url} url = ${slap_connection:server_url}
key = $${slap_connection:key_file} key = ${slap_connection:key_file}
cert = $${slap_connection:cert_file} cert = ${slap_connection:cert_file}
# Define default parameter(s) that will be used later, in case user didn't # Define default parameter(s) that will be used later, in case user didn't
# specify it. # specify it.
...@@ -46,18 +46,18 @@ configuration.name = John Doe ...@@ -46,18 +46,18 @@ configuration.name = John Doe
# Create all needed directories, depending on your needs # Create all needed directories, depending on your needs
[directory] [directory]
recipe = slapos.cookbook:mkdirectory recipe = slapos.cookbook:mkdirectory
home = $${buildout:directory} home = ${buildout:directory}
etc = $${:home}/etc etc = ${:home}/etc
var = $${:home}/var var = ${:home}/var
# Executables put here will be started but not monitored (for startup scripts) # Executables put here will be started but not monitored (for startup scripts)
script = $${:etc}/run/ script = ${:etc}/run/
# Executables put here will be started and monitored (for daemons) # Executables put here will be started and monitored (for daemons)
service = $${:etc}/service service = ${:etc}/service
# Executables put here will be launched after buildout has completed to see # Executables put here will be launched after buildout has completed to see
# if instance is running # if instance is running
promise = $${:etc}/promise/ promise = ${:etc}/promise/
# Path of the log directory used by our service (see [helloweb]) # Path of the log directory used by our service (see [helloweb])
log = $${:var}/log log = ${:var}/log
# Create a simple web server that says "hello <configuration.name>" to the web. # Create a simple web server that says "hello <configuration.name>" to the web.
...@@ -69,32 +69,32 @@ log = $${:var}/log ...@@ -69,32 +69,32 @@ log = $${:var}/log
# NOTE because every computer partition is allocated its own global IPv6 # NOTE because every computer partition is allocated its own global IPv6
# address, it is ok to fix the port - different hello-world instances will have # address, it is ok to fix the port - different hello-world instances will have
# different IPv6 addresses and they all will be accessible at the same time. # different IPv6 addresses and they all will be accessible at the same time.
ipv6 = $${instance-parameter:ipv6-random} ipv6 = ${instance-parameter:ipv6-random}
port = 7777 port = 7777
# full URL - for convenience # full URL - for convenience
url = http://[$${:ipv6}]:$${:port} url = http://[${:ipv6}]:${:port}
# the service will log here # the service will log here
logfile = $${directory:log}/helloweb.log logfile = ${directory:log}/helloweb.log
# Actual script that starts the service: # Actual script that starts the service:
# This recipe will try to "exec" the command-line after separating parameters. # This recipe will try to "exec" the command-line after separating parameters.
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
command-line = command-line =
${buildout:bin-directory}/helloweb --logfile $${helloweb:logfile} {{ buildout['bin-directory'] }}/helloweb --logfile ${helloweb:logfile}
$${:ipv6} $${:port} $${instance-parameter:configuration.name} ${:ipv6} ${:port} ${instance-parameter:configuration.name}
# Put this shell script in the "etc/service" directory. Each executable of this # Put this shell script in the "etc/service" directory. Each executable of this
# repository will be started and monitored by supervisord. If a service # repository will be started and monitored by supervisord. If a service
# exits/crashes, it will trigger a "bang" and cause a re-run of the instance. # exits/crashes, it will trigger a "bang" and cause a re-run of the instance.
wrapper-path = $${directory:service}/helloweb wrapper-path = ${directory:service}/helloweb
# promise, that checks that helloweb service is alive # promise, that checks that helloweb service is alive
[helloweb-promise] [helloweb-promise]
recipe = slapos.cookbook:check_port_listening recipe = slapos.cookbook:check_port_listening
path = $${directory:promise}/helloweb path = ${directory:promise}/helloweb
hostname= $${helloweb:ipv6} hostname= ${helloweb:ipv6}
port = $${helloweb:port} port = ${helloweb:port}
# Publish all the parameters needed for the user to connect to the instance. # Publish all the parameters needed for the user to connect to the instance.
...@@ -102,5 +102,5 @@ port = $${helloweb:port} ...@@ -102,5 +102,5 @@ port = $${helloweb:port}
# Here we'll just echo back the entered name as instance parameter # Here we'll just echo back the entered name as instance parameter
[publish-connection-parameter] [publish-connection-parameter]
recipe = slapos.cookbook:publish recipe = slapos.cookbook:publish
name = Hello $${instance-parameter:configuration.name}! name = Hello ${instance-parameter:configuration.name}!
url = $${helloweb:url} url = ${helloweb:url}
...@@ -27,9 +27,11 @@ parts = ...@@ -27,9 +27,11 @@ parts =
# replace all ${foo:bar} parameters by real values, and change $${foo:bar} to # replace all ${foo:bar} parameters by real values, and change $${foo:bar} to
# ${foo:bar} # ${foo:bar}
[instance-profile] [instance-profile]
recipe = slapos.recipe.template recipe = slapos.recipe.template:jinja2
url = ${:_profile_base_location_}/instance.cfg.in template = ${:_profile_base_location_}/instance.cfg.in
output = ${buildout:directory}/instance.cfg rendered = ${buildout:directory}/instance.cfg
# MD5 checksum can be skipped for development (easier to develop), but must be filled for production # MD5 checksum can be skipped for development (easier to develop), but must be filled for production
md5sum = 38243467b23a9abfa728bd4d30ab51ad md5sum = f282976950be0377dcb08c4f3513b4a1
mode = 0644 mode = 0644
context =
section buildout buildout
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment