From 14f8cb649a415c26f9b1e46aa8d4a5c18e2a4d3f Mon Sep 17 00:00:00 2001 From: Christophe Mehay Date: Mon, 5 Dec 2016 23:30:52 +0100 Subject: [PATCH] Fix install dep and add Dockefiles --- .dockerignore | 5 +++++ Dockerfile-test.py2 | 17 +++++++++++++++++ Dockerfile-test.py3 | 17 +++++++++++++++++ Dockerfile.py2 | 19 +++++++------------ Dockerfile.py2-alpine | 12 ++++++++++++ Dockerfile.py3 | 19 +++++++------------ Dockerfile.py3-alpine | 12 ++++++++++++ README.md | 16 ++++++++++++++++ docker-compose.yml | 8 ++++---- pyentrypoint/command.py | 2 ++ setup.py | 3 +-- 11 files changed, 100 insertions(+), 30 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile-test.py2 create mode 100644 Dockerfile-test.py3 create mode 100644 Dockerfile.py2-alpine create mode 100644 Dockerfile.py3-alpine diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..bc34ac2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +* +!pyentrypoint +!setup.py +!README.md +!tests diff --git a/Dockerfile-test.py2 b/Dockerfile-test.py2 new file mode 100644 index 0000000..9245497 --- /dev/null +++ b/Dockerfile-test.py2 @@ -0,0 +1,17 @@ +# Testing with python 2 + +FROM python:2 + +RUN pip install pytest six pyyaml jinja2 colorlog watchdog pytest-mock + +RUN adduser --uid 1009 --system testuser +RUN addgroup --gid 1010 testgroup + +ENV PYTHONPATH /opt/ + +ADD tests/test_template.yml.tpl /tmp/test_template.yml +ADD tests/test_template.yml.tpl /tmp/test_template2.yml.tpl + +WORKDIR /opt/tests + +CMD ["py.test", "--verbose", "-rw", "."] diff --git a/Dockerfile-test.py3 b/Dockerfile-test.py3 new file mode 100644 index 0000000..129bb91 --- /dev/null +++ b/Dockerfile-test.py3 @@ -0,0 +1,17 @@ +# Testing with python 3 + +FROM python:3 + +RUN pip3 install pytest six pyyaml jinja2 colorlog watchdog pytest-mock + +RUN adduser --uid 1009 --system testuser +RUN addgroup --gid 1010 testgroup + +ENV PYTHONPATH /opt/ + +ADD tests/test_template.yml.tpl /tmp/test_template.yml +ADD tests/test_template.yml.tpl /tmp/test_template2.yml.tpl + +WORKDIR /opt/tests + +CMD ["py.test", "--verbose", "-rw", "."] diff --git a/Dockerfile.py2 b/Dockerfile.py2 index 9245497..c9d17df 100644 --- a/Dockerfile.py2 +++ b/Dockerfile.py2 @@ -1,17 +1,12 @@ -# Testing with python 2 - FROM python:2 -RUN pip install pytest six pyyaml jinja2 colorlog watchdog pytest-mock +ADD . /tmp/ -RUN adduser --uid 1009 --system testuser -RUN addgroup --gid 1010 testgroup +RUN cd /tmp && \ + pip install --upgrade pip && \ + python setup.py install && \ + rm -rf * -ENV PYTHONPATH /opt/ +ONBUILD ADD entrypoint-config.yml . -ADD tests/test_template.yml.tpl /tmp/test_template.yml -ADD tests/test_template.yml.tpl /tmp/test_template2.yml.tpl - -WORKDIR /opt/tests - -CMD ["py.test", "--verbose", "-rw", "."] +ENTRYPOINT ["pyentrypoint"] diff --git a/Dockerfile.py2-alpine b/Dockerfile.py2-alpine new file mode 100644 index 0000000..2aa0425 --- /dev/null +++ b/Dockerfile.py2-alpine @@ -0,0 +1,12 @@ +FROM python:2-alpine + +ADD . /tmp/ + +RUN cd /tmp && \ + pip install --upgrade pip && \ + python setup.py install && \ + rm -rf * + +ONBUILD ADD entrypoint-config.yml . + +ENTRYPOINT ["pyentrypoint"] diff --git a/Dockerfile.py3 b/Dockerfile.py3 index 129bb91..ceb19fa 100644 --- a/Dockerfile.py3 +++ b/Dockerfile.py3 @@ -1,17 +1,12 @@ -# Testing with python 3 - FROM python:3 -RUN pip3 install pytest six pyyaml jinja2 colorlog watchdog pytest-mock +ADD . /tmp/ -RUN adduser --uid 1009 --system testuser -RUN addgroup --gid 1010 testgroup +RUN cd /tmp && \ + pip install --upgrade pip && \ + python setup.py install && \ + rm -rf * -ENV PYTHONPATH /opt/ +ONBUILD ADD entrypoint-config.yml . -ADD tests/test_template.yml.tpl /tmp/test_template.yml -ADD tests/test_template.yml.tpl /tmp/test_template2.yml.tpl - -WORKDIR /opt/tests - -CMD ["py.test", "--verbose", "-rw", "."] +ENTRYPOINT ["pyentrypoint"] diff --git a/Dockerfile.py3-alpine b/Dockerfile.py3-alpine new file mode 100644 index 0000000..8ef41fa --- /dev/null +++ b/Dockerfile.py3-alpine @@ -0,0 +1,12 @@ +FROM python:3-alpine + +ADD . /tmp/ + +RUN cd /tmp && \ + pip install --upgrade pip && \ + python setup.py install && \ + rm -rf * + +ONBUILD ADD entrypoint-config.yml . + +ENTRYPOINT ["pyentrypoint"] diff --git a/README.md b/README.md index c1fd6ac..cce76af 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,22 @@ ENTRYPOINT ['pyentrypoint'] CMD ['git'] ``` +#### Using docker-image + +```dockerfile +FROM goldy/pyentrypoint:python3 + +# ONBUILD statement add entrypoint-config.yml in current directories + +``` + +Available with many flavours: + +- `goldy/pyentrypoint:python2` +- `goldy/pyentrypoint:python3` +- `goldy/pyentrypoint:python2-alpine` +- `goldy/pyentrypoint:python3-alpine` + ### Working examples - [Tor hidden service](https://github.com/cmehay/docker-tor-hidden-service) diff --git a/docker-compose.yml b/docker-compose.yml index 4ce1b0a..d3fcf13 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ testpython3: build: . - dockerfile: Dockerfile.py3 + dockerfile: Dockerfile-test.py3 volumes: - ./pyentrypoint:/opt/pyentrypoint:ro - ./tests:/opt/tests @@ -15,7 +15,7 @@ testpython3: testpython2: build: . - dockerfile: Dockerfile.py2 + dockerfile: Dockerfile-test.py2 volumes: - ./pyentrypoint:/opt/pyentrypoint:ro - ./tests:/opt/tests @@ -30,7 +30,7 @@ testpython2: testpython3_debug: build: . - dockerfile: Dockerfile.py3 + dockerfile: Dockerfile-test.py3 volumes: - ./pyentrypoint:/opt/pyentrypoint:ro - ./tests:/opt/tests @@ -46,7 +46,7 @@ testpython3_debug: testpython2_debug: build: . - dockerfile: Dockerfile.py2 + dockerfile: Dockerfile-test.py2 volumes: - ./pyentrypoint:/opt/pyentrypoint:ro - ./tests:/opt/tests diff --git a/pyentrypoint/command.py b/pyentrypoint/command.py index 146cdd6..1173d12 100644 --- a/pyentrypoint/command.py +++ b/pyentrypoint/command.py @@ -79,6 +79,8 @@ class Command(object): self.log.debug('Now running: "{args}"'.format( args='" "'.join(self.args) )) + if not self.args[0]: + raise Exception('Nothing to run') os.execvpe(self.args[0], self.args, self.env) def _run_reloader(self): diff --git a/setup.py b/setup.py index a8eb91e..ad6e360 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup # Thanks Sam and Max -__version__ = '0.4.6' +__version__ = '0.4.7' if __name__ == '__main__': setup( @@ -27,7 +27,6 @@ if __name__ == '__main__': install_requires=['Jinja2>=2.8', 'PyYAML>=3.11', 'colorlog>=2.6.1', - 'argparse>=1.4.0', 'six>=1.10.0', 'watchdog>=0.8.3'],