Added fpm_options parameter for building package
Some parameters can be added into package informations. Change-Id: I625339b6fdc44340fcb41842b5527263a8afd2b4
This commit is contained in:
parent
1476f6c3aa
commit
c5dbd00821
|
@ -11,3 +11,8 @@ settings:
|
||||||
projects:
|
projects:
|
||||||
- name: glance
|
- name: glance
|
||||||
gitref: stable/mitaka
|
gitref: stable/mitaka
|
||||||
|
fpm_options:
|
||||||
|
# Additional FPM options: https://github.com/jordansissel/fpm/wiki#usage
|
||||||
|
- '--architecture all'
|
||||||
|
- '--provides some-package'
|
||||||
|
- '--replaces second-package'
|
||||||
|
|
|
@ -28,6 +28,10 @@ class BuildSpec(object):
|
||||||
self.version = version
|
self.version = version
|
||||||
self.build_type = build_type
|
self.build_type = build_type
|
||||||
manifest_settings = self._manifest['settings']
|
manifest_settings = self._manifest['settings']
|
||||||
|
if 'projects' in self._manifest:
|
||||||
|
self.fpm_options = \
|
||||||
|
self._get_project_requirements(self._manifest['projects'],
|
||||||
|
'fpm_options')
|
||||||
if version:
|
if version:
|
||||||
manifest_settings['version'] = version
|
manifest_settings['version'] = version
|
||||||
if build_type:
|
if build_type:
|
||||||
|
@ -38,6 +42,15 @@ class BuildSpec(object):
|
||||||
self.settings = Settings.factory(manifest_settings)
|
self.settings = Settings.factory(manifest_settings)
|
||||||
self.projects = self._render_projects(limit_projects)
|
self.projects = self._render_projects(limit_projects)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_project_requirements(projects, cmd):
|
||||||
|
pkg_req = []
|
||||||
|
for project in projects:
|
||||||
|
if cmd in project:
|
||||||
|
(pkg_req.append(project[cmd])
|
||||||
|
if project[cmd] is not None else False)
|
||||||
|
return pkg_req
|
||||||
|
|
||||||
def _render_projects(self, limit_projects):
|
def _render_projects(self, limit_projects):
|
||||||
projects = []
|
projects = []
|
||||||
if 'projects' in self._manifest:
|
if 'projects' in self._manifest:
|
||||||
|
|
|
@ -103,7 +103,8 @@ class PackageBuilder(Builder):
|
||||||
pkg = Package(project.package_name, project.version,
|
pkg = Package(project.package_name, project.version,
|
||||||
project.install_path, self._spec.settings.output_dir,
|
project.install_path, self._spec.settings.output_dir,
|
||||||
self._spec.settings.force_overwrite,
|
self._spec.settings.force_overwrite,
|
||||||
project.system_dependencies)
|
project.system_dependencies,
|
||||||
|
self._spec.fpm_options)
|
||||||
pkg.build()
|
pkg.build()
|
||||||
|
|
||||||
def _finalize_build(self):
|
def _finalize_build(self):
|
||||||
|
|
|
@ -39,7 +39,7 @@ class OpenstackProject(object):
|
||||||
gitdepth=None, venv_command=None, install_command=None,
|
gitdepth=None, venv_command=None, install_command=None,
|
||||||
install_path=None, package_name=None, stackforge=False,
|
install_path=None, package_name=None, stackforge=False,
|
||||||
system_dependencies=[], pip_dependencies=[],
|
system_dependencies=[], pip_dependencies=[],
|
||||||
postinstall_dependencies=[]):
|
postinstall_dependencies=[], fpm_options=None):
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
self.name = name
|
self.name = name
|
||||||
self._version = version
|
self._version = version
|
||||||
|
@ -55,6 +55,7 @@ class OpenstackProject(object):
|
||||||
self.system_dependencies = system_dependencies
|
self.system_dependencies = system_dependencies
|
||||||
self.pip_dependencies = pip_dependencies
|
self.pip_dependencies = pip_dependencies
|
||||||
self.postinstall_dependencies = postinstall_dependencies
|
self.postinstall_dependencies = postinstall_dependencies
|
||||||
|
self.fpm_options = fpm_options
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def version(self):
|
def version(self):
|
||||||
|
|
|
@ -29,13 +29,14 @@ SUPPORTED_DISTROS = {
|
||||||
class Package(object):
|
class Package(object):
|
||||||
|
|
||||||
def __init__(self, name, version, install_path, output_dir,
|
def __init__(self, name, version, install_path, output_dir,
|
||||||
overwrite=False, dependencies=None):
|
overwrite=False, dependencies=None, fpm_options=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.version = version
|
self.version = version
|
||||||
self.install_path = install_path
|
self.install_path = install_path
|
||||||
self.output_dir = output_dir
|
self.output_dir = output_dir
|
||||||
self.overwrite = overwrite
|
self.overwrite = overwrite
|
||||||
self.dependencies = dependencies
|
self.dependencies = dependencies
|
||||||
|
self.fpm_options = fpm_options
|
||||||
|
|
||||||
def _get_platform_target(self):
|
def _get_platform_target(self):
|
||||||
current_distro = platform.linux_distribution()[0]
|
current_distro = platform.linux_distribution()[0]
|
||||||
|
@ -46,6 +47,15 @@ class Package(object):
|
||||||
raise Exception("Sorry, '%s' is an unsupported distribution" %
|
raise Exception("Sorry, '%s' is an unsupported distribution" %
|
||||||
current_distro)
|
current_distro)
|
||||||
|
|
||||||
|
def _add_commands(self, command_type):
|
||||||
|
# You can have defined multiple projects in yaml, iterate on projects
|
||||||
|
# and add to the command strings declared in yaml e.g.: copy_file
|
||||||
|
command = ''
|
||||||
|
for project in command_type:
|
||||||
|
for cmd in project:
|
||||||
|
command += '%s ' % cmd
|
||||||
|
return command
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
target = self._get_platform_target()
|
target = self._get_platform_target()
|
||||||
overwrite = ''
|
overwrite = ''
|
||||||
|
@ -60,6 +70,19 @@ class Package(object):
|
||||||
os.makedirs(self.output_dir)
|
os.makedirs(self.output_dir)
|
||||||
|
|
||||||
# not wrapping in a try block - handled by caller
|
# not wrapping in a try block - handled by caller
|
||||||
execute("fpm %s -s dir -t %s -n %s -v %s %s %s" % (overwrite,
|
execute_command = "fpm %s -s dir -t %s -n %s -v %s " % (overwrite,
|
||||||
target, self.name, self.version, deps, self.install_path),
|
target,
|
||||||
self.output_dir)
|
self.name,
|
||||||
|
self.version)
|
||||||
|
|
||||||
|
if self.fpm_options:
|
||||||
|
# Adding fpm options e.g.: like architecture, description, etc.
|
||||||
|
# More actions have been described:
|
||||||
|
# https://github.com/jordansissel/fpm/wiki#usage
|
||||||
|
execute_command += self._add_commands(self.fpm_options)
|
||||||
|
execute(execute_command, self.output_dir)
|
||||||
|
else:
|
||||||
|
# Execute standard command
|
||||||
|
execute_command = "%s %s %s" % (execute_command, deps,
|
||||||
|
self.install_path)
|
||||||
|
execute(execute_command, self.output_dir)
|
||||||
|
|
|
@ -59,3 +59,26 @@ class TestBuildSpec(unittest.TestCase):
|
||||||
self.assertEqual(2, len(bs.projects))
|
self.assertEqual(2, len(bs.projects))
|
||||||
for project in bs.projects:
|
for project in bs.projects:
|
||||||
self.assertEqual('99', project.version)
|
self.assertEqual('99', project.version)
|
||||||
|
|
||||||
|
def test_build_spec_projects_with_fpm_options(self):
|
||||||
|
fpm_options = ['--architecture all', '--replaces some-package',
|
||||||
|
'--provides funny-package',
|
||||||
|
'--depends very-funny-package']
|
||||||
|
manifest = {
|
||||||
|
'settings': {},
|
||||||
|
'projects': [
|
||||||
|
{
|
||||||
|
'name': 'project1',
|
||||||
|
'fpm_options': fpm_options,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
with tempfile.TemporaryFile(mode='w+') as tf:
|
||||||
|
version = '0'
|
||||||
|
yaml.safe_dump(manifest, tf)
|
||||||
|
tf.flush()
|
||||||
|
tf.seek(0)
|
||||||
|
bs = build_spec.BuildSpec(tf, version)
|
||||||
|
self.assertEqual(1, len(bs.projects))
|
||||||
|
for project in bs.projects:
|
||||||
|
self.assertEqual(fpm_options, project.fpm_options)
|
||||||
|
|
Loading…
Reference in New Issue