Add envtobool function in jinja templates

envtobool
Christophe Mehay 4 years ago
parent 5389f36478
commit 82180f18f9

@ -13,9 +13,8 @@ deploy:
before_deploy:
- poetry config http-basic.pypi $PYPI_USER $PYPI_PASSWORD
- poetry build
deploy:
provider: script
script: poetry publish
provider: script
script: poetry publish
on:
tags: true
env:

@ -1,3 +1,6 @@
v0.7.1
- add envtobool function in configuration template
v0.7.0
- Add mapping of config commands and conf files to root commands

@ -14,6 +14,9 @@ This tool avoids writing shell scripts to:
## Changelog
###### v0.7.1 (2020-05-24)
- add envtobool function in configuration template
###### v0.7.0 (2020-05-17)
- Add command matching setup
@ -88,7 +91,7 @@ This is an example of `entrypoint-config.yml` file.
```yaml
# Entrypoint configuration example
# This entry list commands handled by entrypoint.
# This setup lists commands handled by entrypoint.
# If you run the container with a command not in this list,
# pyentrypoint will run the command directly without any action
# If this setting and `command` are not set, all commands will be handled.
@ -97,17 +100,17 @@ commands:
- git
- sl*
# DEPRECATED: This option is remplaced by `commands`
# DEPRECATED: This setup is remplaced by `commands`
# This entry should reflect CMD in Dockerfile
# If `commands` is present, this option will be ignored.
# DEPRECATED: This option is remplaced by `commands`
# If `commands` is present, this setup will be ignored.
# DEPRECATED: This setup is remplaced by `commands`
command: git
# DEPRECATED: This option will be dropped
# DEPRECATED: This setup will be dropped
# This is a list with some subcommands to handle
# when CMD is not `git` here.
# By default, all args started with hyphen are handled.
# DEPRECATED: This option will be dropped
# DEPRECATED: This setup will be dropped
subcommands:
- "-*"
- clone
@ -335,6 +338,22 @@ You have 4 available objects in your templates.
`env` is an alias to `environ`.
##### envtobool
`envtobool` function is a useful to parse boolean string input in environnement to enable or disable features.
The function accepts a default value as second parameter.
```jinja
{% if envtobool('SOME_ENV_VARIABLE', False) %}
do stuff
{% endif %}
# Will write True or False here
{envtobool('SOME_OTHER_ENV_VARIABLE', True)}
```
See https://docs.python.org/3/distutils/apiref.html#distutils.util.strtobool for information on input.
#### yaml and json
`yaml` and `json` objects are respectively an import of [`PyYAML`](http://pyyaml.org/) and [`json`](https://docs.python.org/2/library/json.html) modules.

@ -5,3 +5,5 @@ environ:
{"json": "ok"}
YAML: |
yaml: ok
OK: 'true'
KO: '0'

@ -12,6 +12,7 @@ from jinja2 import Environment
from jinja2 import FileSystemLoader
from .config import Config
from .config import envtobool
from .constants import ENTRYPOINT_FILE
from .docker_links import DockerLinks
from .logs import Logs
@ -87,6 +88,7 @@ class Entrypoint(object):
environ=os.environ,
json=json,
yaml=yaml,
envtobool=envtobool,
containers=DockerLinks().to_containers()))
def run_pre_conf_cmds(self):

@ -1,7 +1,7 @@
[tool]
[tool.poetry]
name = "pyentrypoint"
version = "0.7.0"
version = "0.7.1"
description = "pyentrypoint manages entrypoints in Docker containers."
license = "WTFPL"
classifiers = ["Programming Language :: Python", "Development Status :: 1 - Planning", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.6", "Topic :: System :: Installation/Setup"]

@ -153,6 +153,10 @@ def test_templates():
# test json
assert test['JSON']['json'] == 'ok'
# test envtobool
assert test['ENVTOBOOL']['ok']
assert not test['ENVTOBOOL']['ko']
def test_conf_commands():

@ -62,3 +62,7 @@ YAML:
{% for key, val in yaml.load(env['YAML']).items() %}
'{{key}}': '{{val}}'
{% endfor %}
ENVTOBOOL:
ok: {{ envtobool('OK', False) }}
ko: {{ envtobool('KO', True) }}

Loading…
Cancel
Save