Commit 2b6c1e47 authored by Kirill Smelkov's avatar Kirill Smelkov

helloworld & helloweb: Prepare to show different kinds of helloweb to the world

Prepare to have several helloweb programs each written in its own
language, and installed into bin/ as helloworld-<language> and exposed
as separate service to the web on its own port.

For component/helloweb we just rename installed script and section.

For software/helloworld we split helloweb & helloweb-promise section
into base and generate requested helloweb-<kinds> & friends via jinja2
programming; the same for exposing url for each kind.

So far it is only preparatory changes for new kinds - i.e. instance code
now supports it, but the only kind so far is still python.

/cc @jerome
parent eb270605
...@@ -4,7 +4,7 @@ extends = ...@@ -4,7 +4,7 @@ extends =
../git/buildout.cfg ../git/buildout.cfg
parts = parts =
helloweb helloweb-python
# repository with examples # repository with examples
...@@ -12,16 +12,17 @@ parts = ...@@ -12,16 +12,17 @@ parts =
recipe = slapos.recipe.build:gitclone recipe = slapos.recipe.build:gitclone
git-executable = ${git:location}/bin/git git-executable = ${git:location}/bin/git
repository = https://lab.nexedi.com/nexedi/helloweb.git repository = https://lab.nexedi.com/nexedi/helloweb.git
revision = 88d517131e75929f79a4d36de4124dab4521614a revision = 686dd5dd623728750ec30514173a7be36fab3a06
location = ${buildout:parts-directory}/helloweb location = ${buildout:parts-directory}/helloweb
# -*- python -*-
[helloweb-egg] [helloweb-egg]
recipe = zc.recipe.egg:develop recipe = zc.recipe.egg:develop
egg = helloweb egg = helloweb
setup = ${helloweb-repository:location}/python/ setup = ${helloweb-repository:location}/python/
[helloweb] [helloweb-python]
recipe = zc.recipe.egg:scripts recipe = zc.recipe.egg:scripts
eggs = ${helloweb-egg:egg} eggs = ${helloweb-egg:egg}
scripts = helloweb scripts = helloweb=helloweb-python
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
[buildout] [buildout]
parts = parts =
directory directory
helloweb
helloweb-promise
publish-connection-parameter publish-connection-parameter
# Define egg directories to be the one from Software Release # Define egg directories to be the one from Software Release
...@@ -70,31 +68,56 @@ log = ${:var}/log ...@@ -70,31 +68,56 @@ log = ${:var}/log
# 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
# 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-${:kind}.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-${:kind} --logfile ${: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-${:kind}
# 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-${:kind}
hostname= ${helloweb:ipv6}
port = ${helloweb:port} {# macro to instantiate service of `kind` to listen on `port` #}
{% set service_list = [] %}
{% macro hellowebsrv(kind, port) %}
{% do service_list.append(kind) %}
[helloweb-{{ kind }}]
<= helloweb
kind = {{ kind }}
port = {{ port }}
[helloweb-{{ kind }}-promise]
<= helloweb-promise
kind = {{ kind }}
hostname= ${helloweb-{{ kind }}:ipv6}
port = {{ port }}
{% endmacro %}
# services instantiation
{{ hellowebsrv('python', 7777) }}
# register all services/promises to buildout parts
[buildout]
parts +=
{%- for kind in service_list %}
helloweb-{{ kind }}
helloweb-{{ kind }}-promise
{%- endfor %}
# 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.
...@@ -103,4 +126,6 @@ port = ${helloweb:port} ...@@ -103,4 +126,6 @@ port = ${helloweb:port}
[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} {%- for kind in service_list %}
url.{{ kind }} = ${helloweb-{{ kind }}:url}
{%- endfor %}
...@@ -19,8 +19,8 @@ parts = ...@@ -19,8 +19,8 @@ parts =
# instance # instance
instance-profile instance-profile
# build helloweb program # build helloweb programs
helloweb helloweb-python
# Download instance.cfg.in (buildout profile used to deployment of instance), # Download instance.cfg.in (buildout profile used to deployment of instance),
...@@ -31,7 +31,8 @@ recipe = slapos.recipe.template:jinja2 ...@@ -31,7 +31,8 @@ recipe = slapos.recipe.template:jinja2
template = ${:_profile_base_location_}/instance.cfg.in template = ${:_profile_base_location_}/instance.cfg.in
rendered = ${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 = f282976950be0377dcb08c4f3513b4a1 md5sum = dc11d4d87edda76189ddd88a35265f05
mode = 0644 mode = 0644
extensions = jinja2.ext.do
context = context =
section buildout buildout 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