Hyper Open Edge Cloud

How To Extend Sections In Buildout

How To Extend Sections In Buildout
  • Last Update:2021-04-14
  • Version:002
  • Language:en

Agenda

  • Extending Buildout Sections
  • Extend Download Sections in software.cfg
  • Verification

This howTo describe how to extend buildout section with macros in the context of SlapOS. The official buildout documentation is available here: Extending sections using macros

Here is the commit introducing this functionality to html5as Software release: 11d4867da8

Prerequisites

Access Theia

You can access the Theia using the url and logging in with username and password.

Observation

Sections doing the same things, share a lot of keys:

recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}
...
mode = 0644

Create macro: [download-base]

This code can be refactored using buildout macros.

[download-base]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}
mode = 0644

Have one shared section to define the default behaviour to download templates. Sections extending this one don't need to redefine shared parameters

Simplification

We can reuse [download-base]

[download-base]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}
mode = 0644

by extending it with  <= download-base line to replace:

recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}
...
mode = 0644

For instance, [instance_html5as] becomes: 

# Download instance_html5as.cfg.in
[instance_html5as]
# This section inherit from download-base
<= download-base
_update_hash_filename_ = instance_html5as.cfg.in
md5sum = e478a1ba048cd0b07553d82e7fc7a48d

Refactor all download sections in software.cfg

Refactor all download sections in software.cfg.

# Download instance_html5as.cfg.in
[instance_html5as]
# This section inherit from download-base
<= download-base
_update_hash_filename_ = instance_html5as.cfg.in
md5sum = 9c023bac9fb0db71213c5d31bd6a0b6b

[template_nginx_conf]
<= download-base
_update_hash_filename_ = templates/nginx_conf.in
md5sum = 61dc4c82bf48563228ce4dea6c5c6319

[template_launcher]
<= download-base
_update_hash_filename_ = templates/launcher.in
md5sum = 8d4d3152f5125f73d0c3f3ea1c3699dd

[template_mime_types]
<= download-base
_update_hash_filename_ = templates/mime_types.in
md5sum = 4ef94a7b458d885cd79ba0b930a5727e

[template_index_html]
<= download-base
_update_hash_filename_ = templates/index.html.in
md5sum = d57cb01df5941e139b02a2f7bdabcdc8

Validation

  • Check slapos node software logs: No error should appear in the last run

Validation

tail -f ~/srv/runner/var/log/slapos-node-software.log

You can retrieve the logs to inspect.
To retrieve the log of slapos node software, you are supposed to type in the terminal:

tail -f ~/srv/runner/var/log/slapos-node-software.log

As there is no error, the sections you extended should be fine.