Expends user and group in environment

environment
Christophe Mehay 8 years ago
parent ff9d53fd1b
commit dd17aadfae

@ -9,7 +9,6 @@
- id: flake8
args:
- --exclude=__init__.py,docs/conf.py
- id: name-tests-test
- id: autopep8-wrapper
- id: requirements-txt-fixer
- id: trailing-whitespace

@ -137,6 +137,8 @@ Affect only command handled.
**Note**: Dockerfile USER value by default.
Can be expended from environment in ``ENTRYPOINT_USER`` and ``ENTRYPOINT_GROUP``.
config_files
^^^^^^^^^^^^

@ -81,6 +81,24 @@ class ConfigMeta(object):
pass
self._config[key] = val
def set_to_env(self):
self.log.debug('Add conf to environment')
for attr in [a for a in dir(self) if not a.startswith('_')]:
setup = getattr(self, attr)
env = 'ENTRYPOINT_{attr}'.format(attr=attr.upper())
if type(setup) is bool and setup:
self.log.debug('set env {env} with "true"'.format(
env=env
))
os.environ[env] = 'true'
if type(setup) is int or type(setup) is str:
if env not in os.environ:
self.log.debug('set env {env} with "{val}"'.format(
env=env,
val=str(setup),
))
os.environ[env] = str(setup)
class Config(ConfigMeta):

@ -142,6 +142,7 @@ def main(argv):
if not entry.is_handled and not entry.should_config:
entry.log.warning("Running command without config")
entry.launch()
entry.config.set_to_env()
entry.log.debug("Starting config")
entry.run_pre_conf_cmds()
entry.apply_conf()

@ -5,7 +5,7 @@ from setuptools import setup
# Thanks Sam and Max
__version__ = '0.4.5'
__version__ = '0.4.6'
if __name__ == '__main__':
setup(

@ -0,0 +1,7 @@
import os
def clean_env():
for key in os.environ.copy().keys():
if key.startswith('ENTRYPOINT_'):
del os.environ[key]

@ -31,6 +31,9 @@ pre_conf_commands:
post_conf_commands:
- echo TEST2 > /tmp/OKOK
- echo TEST3 > /tmp/OKOKOK
- echo ${ENTRYPOINT_USER} > /tmp/user
- echo ${ENTRYPOINT_GROUP} > /tmp/group
- echo ${ENTRYPOINT_DEBUG} > /tmp/debug
- echo "INFO IS DISPLAYED\nON TWO LINES"
- echo "WARNING IS DISPLAYED" 1>&2

@ -5,9 +5,15 @@ from __future__ import unicode_literals
import os
from multiprocessing import Process
from commons import clean_env
from pyentrypoint.entrypoint import main
def teardown_function(function):
clean_env()
class ProxyMain(object):
def __init__(self, args, env):

@ -7,6 +7,7 @@ import os
from multiprocessing import Process
import pytest
from commons import clean_env
from yaml import load
from yaml import Loader
@ -21,6 +22,10 @@ LINKS = [
]
def teardown_function(function):
clean_env()
def test_all_links():
links = DockerLinks()
all_links = links.links()
@ -153,28 +158,32 @@ def test_templates():
def test_conf_commands():
entry = Entrypoint(conf='configs/base.yml')
checks = [
('/tmp/OK', 'TEST'),
('/tmp/OKOK', 'TEST2'),
('/tmp/OKOKOK', 'TEST3'),
('/tmp/OKOKOKOK', 'TEST4'),
('/tmp/OKOKOKOKOK', 'TEST5'),
('/tmp/user', '1000'),
('/tmp/group', '1000'),
('/tmp/debug', 'true'),
]
os.environ['ENTRYPOINT_PRECONF_COMMAND'] = 'echo TEST4 > /tmp/OKOKOKOK'
os.environ['ENTRYPOINT_POSTCONF_COMMAND'] = 'echo TEST5 > /tmp/OKOKOKOKOK'
entry.config.set_to_env()
entry.run_pre_conf_cmds()
entry.run_post_conf_cmds()
with open('/tmp/OK') as f:
assert f.readline().startswith('TEST')
with open('/tmp/OKOK') as f:
assert f.readline().startswith('TEST2')
with open('/tmp/OKOKOK') as f:
assert f.readline().startswith('TEST3')
with open('/tmp/OKOKOKOK') as f:
assert f.readline().startswith('TEST4')
with open('/tmp/OKOKOKOKOK') as f:
assert f.readline().startswith('TEST5')
for filename, value in checks:
with open(filename) as f:
line = f.readline()
print(line)
assert line.startswith(value)
def test_command():

@ -20,6 +20,12 @@ from signal import SIGHUP
from time import sleep
from commons import clean_env
def teardown_function(function):
clean_env()
def _reloader_check(conf, command):
entry = Entrypoint(conf=conf)

Loading…
Cancel
Save