Initial pass at the basic logic
This commit is contained in:
parent
77ae302213
commit
0834ab407c
18
README.rst
18
README.rst
@ -9,9 +9,13 @@ tox and virtualenv for python. There are two elements to its configuration:
|
||||
|
||||
* 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.
|
||||
If there is a dox.yml file, you're set. You want to specify what image to
|
||||
use and what commands to run. You win::
|
||||
|
||||
image: ubuntu:trusty
|
||||
commands: |
|
||||
pip install . -r test-requirements.txt
|
||||
python setup.py test
|
||||
|
||||
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.
|
||||
@ -50,9 +54,11 @@ If there is a tox.ini file, and it contains a [docker] section, the value in
|
||||
[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.
|
||||
If there is not an image key in the docker section or an image key in the
|
||||
dox.yml but there is a Dockerfile in the repo, an new image will be built
|
||||
using the Dockerfile and the test commands will be run inside of the image.
|
||||
|
||||
If all of that fails, tests are going to run in a bare ubuntu image. Good luck!
|
||||
|
||||
Additional information
|
||||
----------------------
|
||||
|
@ -15,5 +15,4 @@
|
||||
import pbr.version
|
||||
|
||||
|
||||
__version__ = pbr.version.VersionInfo(
|
||||
'dox').version_string()
|
||||
__version__ = pbr.version.VersionInfo('dox').version_string()
|
||||
|
49
dox/cmd.py
49
dox/cmd.py
@ -1,30 +1,23 @@
|
||||
import docker
|
||||
import docker.unixconn
|
||||
from docker.unixconn import unixconn
|
||||
import requests
|
||||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import dox.locations
|
||||
import dox.payloads
|
||||
|
||||
|
||||
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())
|
||||
def main():
|
||||
location = dox.locations.get_location()
|
||||
payload = dox.payloads.get_payload()
|
||||
return location.run(payload)
|
||||
|
49
dox/locations.py
Normal file
49
dox/locations.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import ConfigParser
|
||||
import os
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
def get_location():
|
||||
'''Examine the local environment and figure out where we should run.'''
|
||||
|
||||
# Set default image value
|
||||
if os.path.exists('Dockerfile'):
|
||||
image = None
|
||||
else:
|
||||
image = 'ubuntu'
|
||||
|
||||
if os.path.exists('dox.yml'):
|
||||
dox_yaml = yaml.load(open('dox.yml', 'r'))
|
||||
image = dox_yaml.get('image', image)
|
||||
elif os.path.exists('tox.ini'):
|
||||
tox_ini = ConfigParser.ConfigParser()
|
||||
tox_ini.read('tox.ini')
|
||||
if tox_ini.has_option('docker', 'image'):
|
||||
image = tox_ini.get('docker', 'image')
|
||||
return Location(image=image)
|
||||
|
||||
|
||||
class Location(object):
|
||||
|
||||
def __init__(self, image):
|
||||
self.image = image
|
||||
|
||||
def run(self, payload):
|
||||
print("Going to run {0} in {1}".format(
|
||||
payload.get_payload(), self.image))
|
49
dox/payloads.py
Normal file
49
dox/payloads.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import ConfigParser
|
||||
import os
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
def get_payload():
|
||||
'''Examine the local environment and figure out what we should run.'''
|
||||
|
||||
if os.path.exists('dox.yml'):
|
||||
dox_yml = yaml.load(open('dox.yml'))
|
||||
payload = dox_yml.get('commands', None)
|
||||
if payload is None and os.path.exists('tox.ini'):
|
||||
tox_ini = ConfigParser.ConfigParser()
|
||||
tox_ini.read('tox.ini')
|
||||
if tox_ini.has_option('testenv', 'commands'):
|
||||
payload = tox_ini.get('testenv', 'commands')
|
||||
else:
|
||||
payload = None
|
||||
if payload is None and os.path.exists('.travis.yml'):
|
||||
travis_yml = yaml.load(open('.travis.yml'))
|
||||
payload = travis_yml.get('script')
|
||||
return Payload(payload=payload)
|
||||
|
||||
|
||||
class Payload(object):
|
||||
|
||||
def __init__(self, payload):
|
||||
self.payload = payload
|
||||
|
||||
def get_payload(self):
|
||||
if hasattr(self.payload, 'append'):
|
||||
return "\n".join(self.payload)
|
||||
return self.payload
|
@ -1,13 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
@ -1,3 +1,4 @@
|
||||
pbr>=0.5.21,<1.0
|
||||
|
||||
docker-py
|
||||
PyYAML
|
||||
sh
|
||||
|
Loading…
x
Reference in New Issue
Block a user