2
0
mirror of https://github.com/cmehay/pyentrypoint synced 2024-10-30 15:21:11 +00:00

Merge pull request #24 from cmehay/envtobool

Add envtobool function in jinja templates
This commit is contained in:
Christophe Mehay 2020-05-24 18:24:50 +02:00 committed by GitHub
commit c53175a360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 10 deletions

View File

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

View File

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

View File

@ -14,6 +14,9 @@ This tool avoids writing shell scripts to:
## Changelog ## Changelog
###### v0.7.1 (2020-05-24)
- add envtobool function in configuration template
###### v0.7.0 (2020-05-17) ###### v0.7.0 (2020-05-17)
- Add command matching setup - Add command matching setup
@ -88,7 +91,7 @@ This is an example of `entrypoint-config.yml` file.
```yaml ```yaml
# Entrypoint configuration example # 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, # If you run the container with a command not in this list,
# pyentrypoint will run the command directly without any action # pyentrypoint will run the command directly without any action
# If this setting and `command` are not set, all commands will be handled. # If this setting and `command` are not set, all commands will be handled.
@ -97,17 +100,17 @@ commands:
- git - git
- sl* - sl*
# DEPRECATED: This option is remplaced by `commands` # DEPRECATED: This setup is remplaced by `commands`
# This entry should reflect CMD in Dockerfile # This entry should reflect CMD in Dockerfile
# If `commands` is present, this option will be ignored. # If `commands` is present, this setup will be ignored.
# DEPRECATED: This option is remplaced by `commands` # DEPRECATED: This setup is remplaced by `commands`
command: git command: git
# DEPRECATED: This option will be dropped # DEPRECATED: This setup will be dropped
# This is a list with some subcommands to handle # This is a list with some subcommands to handle
# when CMD is not `git` here. # when CMD is not `git` here.
# By default, all args started with hyphen are handled. # By default, all args started with hyphen are handled.
# DEPRECATED: This option will be dropped # DEPRECATED: This setup will be dropped
subcommands: subcommands:
- "-*" - "-*"
- clone - clone
@ -335,6 +338,22 @@ You have 4 available objects in your templates.
`env` is an alias to `environ`. `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
`yaml` and `json` objects are respectively an import of [`PyYAML`](http://pyyaml.org/) and [`json`](https://docs.python.org/2/library/json.html) modules. `yaml` and `json` objects are respectively an import of [`PyYAML`](http://pyyaml.org/) and [`json`](https://docs.python.org/2/library/json.html) modules.

View File

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

View File

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

View File

@ -1,7 +1,7 @@
[tool] [tool]
[tool.poetry] [tool.poetry]
name = "pyentrypoint" name = "pyentrypoint"
version = "0.7.0" version = "0.7.1"
description = "pyentrypoint manages entrypoints in Docker containers." description = "pyentrypoint manages entrypoints in Docker containers."
license = "WTFPL" 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"] 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"]

View File

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

View File

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