[image-build] Use repo from another variant
The config can now additionally specify other variants whose repos will be passed on to koji. The previous way of specifying extra repos is still available, as is the automatic adding of repo for current variant. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
7f815d80f5
commit
d2ea1dd288
@ -613,6 +613,9 @@ Image Build Settings
|
||||
automatically transformed into format suitable for ``koji``. A repo for the
|
||||
currently built variant will be added as well.
|
||||
|
||||
You can also add extra variants to get repos from with key ``repo_from``.
|
||||
The value should be a list of variant names.
|
||||
|
||||
Please don't set ``install_tree``. This gets automatically set by *pungi*
|
||||
based on current variant. You can use ``install_tree_from`` key to use
|
||||
install tree from another variant.
|
||||
@ -659,8 +662,9 @@ Example
|
||||
# only build this type of image on x86_64
|
||||
'arches': ['x86_64']
|
||||
|
||||
# Use install tree from Everything variant.
|
||||
# Use install tree and repo from Everything variant.
|
||||
'install_tree_from': 'Everything',
|
||||
'repo_from': ['Everything'],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
import copy
|
||||
import os
|
||||
import time
|
||||
from kobo import shortcuts
|
||||
|
||||
from pungi.util import get_variant_data, resolve_git_url
|
||||
from pungi.phases.base import PhaseBase
|
||||
@ -46,6 +47,30 @@ class ImageBuildPhase(PhaseBase):
|
||||
self.compose.paths.compose.os_tree('$arch', install_tree_source)
|
||||
)
|
||||
|
||||
def _get_repo(self, image_conf, variant):
|
||||
"""
|
||||
Get a comma separated list of repos. First included are those
|
||||
explicitly listed in config, followed by repos from other variants,
|
||||
finally followed by repo for current variant.
|
||||
|
||||
The `repo_from` key is removed from the dict (if present).
|
||||
"""
|
||||
repo = shortcuts.force_list(image_conf.get('repo', []))
|
||||
|
||||
extras = shortcuts.force_list(image_conf.pop('repo_from', []))
|
||||
extras.append(variant.uid)
|
||||
|
||||
for extra in extras:
|
||||
v = self.compose.variants.get(extra)
|
||||
if not v:
|
||||
raise RuntimeError(
|
||||
'There is no variant %s to get repo from when building image for %s.'
|
||||
% (extra, variant.uid))
|
||||
repo.append(translate_path(self.compose,
|
||||
self.compose.paths.compose.os_tree('$arch', v)))
|
||||
|
||||
return ",".join(repo)
|
||||
|
||||
def run(self):
|
||||
for variant in self.compose.get_variants():
|
||||
arches = set([x for x in variant.arches if x != 'src'])
|
||||
@ -79,12 +104,7 @@ class ImageBuildPhase(PhaseBase):
|
||||
format = image_conf["format"]
|
||||
image_conf["format"] = ",".join([x[0] for x in image_conf["format"]])
|
||||
|
||||
repo = image_conf.get('repo', [])
|
||||
if isinstance(repo, str):
|
||||
repo = [repo]
|
||||
repo.append(translate_path(self.compose, self.compose.paths.compose.os_tree('$arch', variant)))
|
||||
# supply repo as str separated by , instead of list
|
||||
image_conf['repo'] = ",".join(repo)
|
||||
image_conf['repo'] = self._get_repo(image_conf, variant)
|
||||
|
||||
cmd = {
|
||||
"format": format,
|
||||
|
@ -221,6 +221,61 @@ class TestImageBuildPhase(unittest.TestCase):
|
||||
"link_type": 'hardlink-or-copy',
|
||||
})
|
||||
|
||||
@mock.patch('pungi.phases.image_build.ThreadPool')
|
||||
def test_image_build_set_extra_repos(self, ThreadPool):
|
||||
compose = _DummyCompose({
|
||||
'image_build': {
|
||||
'^Server$': [
|
||||
{
|
||||
'format': [('docker', 'tar.xz')],
|
||||
'name': 'Fedora-Docker-Base',
|
||||
'target': 'f24',
|
||||
'version': 'Rawhide',
|
||||
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
||||
'kickstart': "fedora-docker-base.ks",
|
||||
'distro': 'Fedora-20',
|
||||
'disk_size': 3,
|
||||
'arches': ['x86_64'],
|
||||
'repo_from': 'Everything',
|
||||
}
|
||||
]
|
||||
},
|
||||
'koji_profile': 'koji',
|
||||
})
|
||||
|
||||
phase = ImageBuildPhase(compose)
|
||||
|
||||
phase.run()
|
||||
|
||||
# assert at least one thread was started
|
||||
self.assertTrue(phase.pool.add.called)
|
||||
|
||||
self.assertTrue(phase.pool.queue_put.called_once)
|
||||
args, kwargs = phase.pool.queue_put.call_args
|
||||
self.assertEqual(args[0][0], compose)
|
||||
self.maxDiff = None
|
||||
self.assertDictEqual(args[0][1], {
|
||||
"format": [('docker', 'tar.xz')],
|
||||
"image_conf": {
|
||||
'install_tree': '/ostree/$arch/Server',
|
||||
'kickstart': 'fedora-docker-base.ks',
|
||||
'format': 'docker',
|
||||
'repo': '/ostree/$arch/Everything,/ostree/$arch/Server',
|
||||
'variant': compose.variants['Server'],
|
||||
'target': 'f24',
|
||||
'disk_size': 3,
|
||||
'name': 'Fedora-Docker-Base',
|
||||
'arches': 'x86_64',
|
||||
'version': 'Rawhide',
|
||||
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
||||
'distro': 'Fedora-20',
|
||||
},
|
||||
"conf_file": 'Server-Fedora-Docker-Base-docker',
|
||||
"image_dir": '/image_dir/Server/%(arch)s',
|
||||
"relative_image_dir": 'image_dir/Server/%(arch)s',
|
||||
"link_type": 'hardlink-or-copy',
|
||||
})
|
||||
|
||||
|
||||
class TestCreateImageBuildThread(unittest.TestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user