From 77ae302213a4819d5e3a2497cbbcf9ab70ac2591 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 22 Jul 2014 12:32:44 -0700 Subject: [PATCH] Clean up build and write a README --- CONTRIBUTING.rst | 4 +-- README.rst | 74 ++++++++++++++++++++++++++++++++++++++----- dox/cmd.py | 30 ++++++++++++++++++ openstack-common.conf | 7 ---- requirements.txt | 3 +- setup.cfg | 8 ++--- setup.py | 4 +-- test-requirements.txt | 2 +- tox.ini | 6 +--- 9 files changed, 108 insertions(+), 30 deletions(-) create mode 100644 dox/cmd.py delete mode 100644 openstack-common.conf diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 09e24c2..2e3eaa2 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -12,6 +12,6 @@ the workflow documented at: Pull requests submitted through GitHub will be ignored. -Bugs should be filed on Launchpad, not GitHub: +Bugs should be filed on Storyboard, not GitHub: - https://bugs.launchpad.net/dox \ No newline at end of file + https://storyboard.openstack.org diff --git a/README.rst b/README.rst index e221549..6bf3feb 100644 --- a/README.rst +++ b/README.rst @@ -1,13 +1,71 @@ -=============================== +=== dox -=============================== +=== -dox runs tox descriptions in docker containers +dox is a tool for using docker containers to run local tests, inspired by +tox and virtualenv for python. There are two elements to its configuration: -* Free software: Apache license -* Documentation: http://docs.openstack.org/developer/dox +* What commands should be run? -Features +* In what image should they be run? + +If there is a dox.yml file, you're set. You want a docker section to specify +what image to use and a testenv section to specify the commands to run. You +win. + +You might either not be willing to commit to dox as a way of life yet, or you +may want to use dox in a project that similarly has not done so. + +What commands should be run +--------------------------- + +dox.yml wins. + +If there is a tox.ini file, the commands specified in the base [testenv] +will be used. + +If there is a .travis.yml file, the script section will be used. + +If there are none of those things, dox will do its best to infer what +should be done. Examining the directory can often provide hints if you +haven't been too clever. For instance, if you have a Gruntfile, you probably +want to run grunt. If you have a Makefile, then make && make test is probably +your bag. If you have a Makefile.am, you probably want to run autotools first. +If you have a setup.py file, python setup.py test is a likely choice (although +in that case, you probably haven't done it right because setuptools support +for this is quite awful.) + +After all of that, if we still can't figure out what you want - it's probably +easiest to just edit a file called dox.yml and put in a section telling us +what to do. + +In what image should they be run +-------------------------------- + +Again, dox.yml wins, and thanks for making things easy! + +If there is a tox.ini file, and it contains a [docker] section, the value in +"image" will be used:: + + [docker] + image=ubuntu:trusty + +If there is not an image key in the docker section but there is a Dockerfile +in the repo, an image will be built using the Dockerfile and the test +commands will be run inside of the image. + +Additional information +---------------------- + +Regardless, dox will mount the current source dir as a volume at `/src` in +the container and will run commands in that context. + +dox will attempt to reuse containers. Since the source is bind-mounted into +the container, things that might be expensive like copying source dirs or +re-installing the source into the system can be minimized. + +Advanced -------- - -* TODO \ No newline at end of file +The dox.yml file can reference multiple images, such as if your test suite +needs things like a MySQL server. At least, that's the theory. This is not +yet implemented. diff --git a/dox/cmd.py b/dox/cmd.py new file mode 100644 index 0000000..efcef3a --- /dev/null +++ b/dox/cmd.py @@ -0,0 +1,30 @@ +import docker +import docker.unixconn +from docker.unixconn import unixconn +import requests + + +def _get_docker_api_version(): + session = requests.Session() + session.mount( + "http+unix://", + docker.unixconn.unixconn.UnixAdapter( + "http+unix://var/run/docker.sock", 60)) + response = session.get('/version') + try: + api_version = response.json()['ApiVersion'] + except KeyError: + # For now, fall back to 1.10 as a safety net + api_version = '1.10' + return api_version + + +def _version_string_to_tuple(version): + return tuple([int(f) for f in version.split('.')]) + + +class Dox(object): + + + def __init__(self): + self.client = docker.Client(version=_get_docker_api_version()) diff --git a/openstack-common.conf b/openstack-common.conf deleted file mode 100644 index af27a85..0000000 --- a/openstack-common.conf +++ /dev/null @@ -1,7 +0,0 @@ -[DEFAULT] - -# The list of modules to copy from oslo-incubator.git -module=install_venv_common - -# The base module to hold the copy of openstack.common -base=dox \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8646341..24d61b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pbr>=0.5.21,<1.0 -Babel>=0.9.6 \ No newline at end of file + +docker-py diff --git a/setup.cfg b/setup.cfg index de3eab0..b51f35f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,9 +19,9 @@ classifier = Programming Language :: Python :: 3 Programming Language :: Python :: 3.3 -[files] -packages = - dox +[entry_points] +console_scripts = + dox = dox.cmd:main [build_sphinx] source-dir = doc/source @@ -43,4 +43,4 @@ input_file = dox/locale/dox.pot [extract_messages] keywords = _ gettext ngettext l_ lazy_gettext mapping_file = babel.cfg -output_file = dox/locale/dox.pot \ No newline at end of file +output_file = dox/locale/dox.pot diff --git a/setup.py b/setup.py index 33f185a..70c2b3f 100755 --- a/setup.py +++ b/setup.py @@ -18,5 +18,5 @@ import setuptools setuptools.setup( - setup_requires=['pbr>=0.5.21,<1.0'], - pbr=True) \ No newline at end of file + setup_requires=['pbr'], + pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt index 3434db1..9dab35b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -8,4 +8,4 @@ sphinx>=1.1.2 oslo.sphinx testrepository>=0.0.17 testscenarios>=0.4,<0.5 -testtools>=0.9.32 \ No newline at end of file +testtools>=0.9.32 diff --git a/tox.ini b/tox.ini index 453559d..a6a2f51 100644 --- a/tox.ini +++ b/tox.ini @@ -25,10 +25,6 @@ commands = {posargs} commands = python setup.py testr --coverage --testr-args='{posargs}' [flake8] -# H803 skipped on purpose per list discussion. -# E123, E125 skipped as they are invalid PEP-8. - show-source = True -ignore = E123,E125,H803 builtins = _ -exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build \ No newline at end of file +exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build