forked from ansible/ansible-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
133 lines (121 loc) · 4.79 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import sys
import shlex
import shutil
import distutils.cmd
import distutils.log
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
from setuptools.command.sdist import sdist as SDistCommand
try:
from pip._internal.req import parse_requirements
except ImportError:
from pip.req import parse_requirements
import container
class PlaybookAsTests(TestCommand):
user_options = [('ansible-args=', None, "Extra ansible arguments")]
def initialize_options(self):
self.ansible_args = u''
TestCommand.initialize_options(self)
def run(self):
if sys.platform == 'darwin':
# Docker for Mac exports certain paths into the virtual machine
# actually running Docker. The default tempdir isn't one of them,
# but /tmp is.
os.environ['TMPDIR'] = '/tmp'
return TestCommand.run(self)
def run_tests(self):
import subprocess
p = subprocess.Popen(
['ansible-playbook'] +
shlex.split(self.ansible_args) +
['run_tests.yml'],
cwd=os.path.join(os.getcwd(), 'test'),
)
rc = p.wait()
sys.exit(rc)
class BundleConductorFiles(SDistCommand):
def run(self):
shutil.copyfile('./setup.py', 'container/docker/files/setup.py')
shutil.copyfile('./conductor-requirements.txt',
'container/docker/files/conductor-requirements.txt')
shutil.copyfile('./conductor-requirements.yml',
'container/docker/files/conductor-requirements.yml')
return SDistCommand.run(self)
class PrebakeConductors(distutils.cmd.Command):
description = 'Pre-bake Conductor base images'
user_options = [
# The format is (long option, short option, description).
('debug', None, 'Enable debug output'),
('no-cache', None, 'Cache me offline, how bout dat?'),
('ignore-errors', None, 'Ignore build failures and continue building other distros'),
('distros=', None, 'Only pre-bake certain supported distros. Comma-separated.'),
('conductor-provider=', None, 'Possibility to specify custom provider, default ansible')
]
def initialize_options(self):
"""Set default values for options."""
# Each user option must be listed here with their default value.
self.debug = False
self.ignore_errors = False
self.distros = ''
self.conductor_provider = 'ansible'
def finalize_options(self):
self.distros = self.distros.strip().split(',') if self.distros else []
self.cache = not getattr(self, 'no_cache', False)
def run(self):
"""Run command."""
from container.cli import LOGGING
from logging import config
from container import core
if self.debug:
LOGGING['loggers']['container']['level'] = 'DEBUG'
config.dictConfig(LOGGING)
core.hostcmd_prebake(self.distros, debug=self.debug, cache=self.cache,
ignore_errors=self.ignore_errors, conductor_provider=self.conductor_provider)
if container.ENV == 'host':
install_reqs = parse_requirements('requirements.txt', session=False)
setup_kwargs = dict(
install_requires=[str(ir.req) for ir in install_reqs if ir.match_markers()],
tests_require=[
'ansible>=2.3.0',
'pytest>=3',
'docker>=2.4.0,<3.0',
'jmespath>=0.9'
],
extras_require={
'docker': ['docker>=2.4.0,<3.0'],
'docbuild': ['Sphinx>=1.5.0'],
'openshift': ['openshift==0.3.4'],
'k8s': ['openshift==0.3.4']
},
#dependency_links=[
# 'https://github.com/ansible/ansible/archive/devel.tar.gz#egg=ansible-2.4.0',
#],
cmdclass={'test': PlaybookAsTests,
'sdist': BundleConductorFiles,
'prebake': PrebakeConductors},
entry_points={
'console_scripts': [
'ansible-container = container.cli:host_commandline']
}
)
else:
setup_kwargs = dict(
entry_points={
'console_scripts': ['conductor = container.cli:conductor_commandline']
},
)
setup(
name='ansible-container',
version=container.__version__,
packages=find_packages(include='container.*'),
include_package_data=True,
zip_safe=False,
url='https://github.com/ansible/ansible-container',
license='LGPLv3 (See LICENSE file for terms)',
author='Joshua "jag" Ginsberg, Chris Houseknecht, and others (See AUTHORS file for contributors)',
author_email='[email protected]',
description=('Ansible Container empowers you to orchestrate, build, run, and ship '
'Docker images built from Ansible playbooks.'),
**setup_kwargs
)