diff --git a/software/slaprunner/README.txt b/software/slaprunner/README.txt index d15dc98b14d34c345f0aa0bf8c19c12bdc8fb742..bed1f3536f7746dd9d907ecb63e590aa9959321f 100644 --- a/software/slaprunner/README.txt +++ b/software/slaprunner/README.txt @@ -53,6 +53,16 @@ The parameter "auto-deploy-instance" can be explicitly set to allow or prevent t There also exists the parameter "autorun", which will build&run your software if set to true. For this, you need "auto_deploy" to true, and set the parameter "slapos-software" to the software you want to deploy. Do not hesitate to clone a different repo than "slapos", or to change the tag/branch to use your custom Software Release. (see "slapos-repository" and "slapos-reference" in previous section). +To deploy the instance with some parameters, just give to the runner parameters starting with "parameter-", they will be correctly forwarded to the instance, which will use them for its configuration. For example, if you want to send to the sofware helloworld the parameter "name" with the value "nicolas", here is how to configure the parameter.xml of the webrunner for auto-depolyment : + +<?xml version='1.0' encoding='utf-8'?> +<instance> +<parameter id="slapos-software">software/helloworld</parameter> +<parameter id="auto_deploy">true</parameter> +<parameter id="autorun">true</parameter> +<parameter id="parameter-name">nicolas</parameter> +</instance> + Resilience : ------------ diff --git a/software/slaprunner/common.cfg b/software/slaprunner/common.cfg index a75b791c8528021553b3fc524c8ed2a5a91a7e3d..879fe8d95f1980e90871838cad20e759da8ba57a 100644 --- a/software/slaprunner/common.cfg +++ b/software/slaprunner/common.cfg @@ -111,6 +111,15 @@ filename = slapos.cfg.in download-only = true mode = 0644 +[parameters-template] +recipe = hexagonit.recipe.download +url = ${:_profile_base_location_}/${:filename} +#md5sum = 8207e74c7b97a4a3f3be390ea4f97ae1 +location = ${buildout:parts-directory}/${:_buildout_section_name_} +filename = parameters.xml.in +download-only = true +mode = 0644 + [eggs] recipe = z3c.recipe.scripts eggs = diff --git a/software/slaprunner/instance-runner-export.cfg.in b/software/slaprunner/instance-runner-export.cfg.in index 27b0c789591f4089e37b9a60f0391bf4ee5a8598..8b2b79501d177091758a4a2ad401d77b7930f5c7 100644 --- a/software/slaprunner/instance-runner-export.cfg.in +++ b/software/slaprunner/instance-runner-export.cfg.in @@ -26,6 +26,7 @@ parts += slapos-repo-config cron-entry-backup cron-entry-prepare-software + deploy-instance-parameters ###Parts to add for monitoring slap-parameters certificate-authority diff --git a/software/slaprunner/instance-runner-import.cfg.in b/software/slaprunner/instance-runner-import.cfg.in index c668e79b0e33fdcdd42f8153313d640c44cc07b5..ff5fa48b683abddc1dbf5432b70d3de2c43aa9c3 100644 --- a/software/slaprunner/instance-runner-import.cfg.in +++ b/software/slaprunner/instance-runner-import.cfg.in @@ -23,6 +23,7 @@ parts += slapos-cfg slapos-repo-config cron-entry-prepare-software + deploy-instance-parameters # have to repeat the next one, as it's not inherited from pbsready-import import-on-notification ###Parts to add for monitoring diff --git a/software/slaprunner/instance-runner.cfg b/software/slaprunner/instance-runner.cfg index 9010ae9831987a7fdb198701263210ba490a222a..96c408d34a8024f804fb8fc1071481397af7c534 100644 --- a/software/slaprunner/instance-runner.cfg +++ b/software/slaprunner/instance-runner.cfg @@ -22,6 +22,7 @@ parts = slapos-cfg slapos-repo-config cron-entry-prepare-software + deploy-instance-parameters {% if slapparameter_dict.get('custom-frontend-backend-url') %} custom-frontend-promise {% endif %} @@ -541,6 +542,29 @@ name = prepare-software frequency = */2 * * * * command = $${prepare-software:wrapper-path} +[instance-parameters] +recipe = slapos.recipe.template:jinja2 +extensions = jinja2.ext.do +template = ${parameters-template:location}/${parameters-template:filename} +rendered = $${directory:etc}/.parameter.xml.default +mode = 0644 +context = + key slapparameter_dict slap-configuration:configuration + +[deploy-instance-parameters] +recipe = plone.recipe.command +stop-on-error = true +parameter-xml = $${directory:etc}/.parameter.xml +command = if [ ! -f $${:parameter-xml} ]; then cp $${instance-parameters:rendered} $${:parameter-xml}; fi + +[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} + [public] shell-password = $${shellinabox-code:passwd} diff --git a/software/slaprunner/parameters.xml.in b/software/slaprunner/parameters.xml.in new file mode 100644 index 0000000000000000000000000000000000000000..c09e71ee84781f142704404b9c0fb27dbd2822ff --- /dev/null +++ b/software/slaprunner/parameters.xml.in @@ -0,0 +1,18 @@ +{% set inst_parameter_dict = {} -%} +{% if slapparameter_dict is defined -%} +{% for key in slapparameter_dict.keys() -%} +{% if key.startswith('parameter-') -%} +{% do inst_parameter_dict.__setitem__(key[10:], slapparameter_dict.pop(key)) -%} +{% endif -%} +{% endfor -%} +{% endif -%} + +<?xml version='1.0' encoding='utf-8'?> +<instance> +{% if slapparameter_dict is defined %} + {% for parameter_name in inst_parameter_dict.keys() %} + <parameter id="{{ parameter_name }}">{{ inst_parameter_dict[parameter_name] }}</parameter> + {% endfor %} +{% endif %} +</instance> +