diff --git a/.travis.yml b/.travis.yml index 4fb3803..3ba11b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/CHANGELOG b/CHANGELOG index 09c13d3..3459394 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/README.md b/README.md index 43c9260..6352f75 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/common.yml b/common.yml index 3a25767..05a3ea9 100644 --- a/common.yml +++ b/common.yml @@ -5,3 +5,5 @@ environ: {"json": "ok"} YAML: | yaml: ok + OK: 'true' + KO: '0' diff --git a/pyentrypoint/entrypoint.py b/pyentrypoint/entrypoint.py index be2ff4b..2e07b6a 100644 --- a/pyentrypoint/entrypoint.py +++ b/pyentrypoint/entrypoint.py @@ -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): diff --git a/pyproject.toml b/pyproject.toml index 43e01f5..bdaeec6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] diff --git a/tests/pyentrypoint_test.py b/tests/pyentrypoint_test.py index 5d9426d..646caa1 100644 --- a/tests/pyentrypoint_test.py +++ b/tests/pyentrypoint_test.py @@ -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(): diff --git a/tests/test_template.yml.tpl b/tests/test_template.yml.tpl index 76c5e43..bbf1465 100644 --- a/tests/test_template.yml.tpl +++ b/tests/test_template.yml.tpl @@ -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) }}