diff --git a/doc/configuration.rst b/doc/configuration.rst index 7aae3689..a0a00f21 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1227,6 +1227,14 @@ Image Build Settings based on current variant. You can use ``install_tree_from`` key to use install tree from another variant. + Both the install tree and repos can use one of following formats: + + * URL to the location + * name of variant in the current compose + * absolute path on local filesystem (which will be translated using + configured mappings or used unchanged, in which case you have to ensure + the koji builders can access it) + You can set either a single format, or a list of formats. For available values see help output for ``koji image-build`` command. diff --git a/pungi/phases/image_build.py b/pungi/phases/image_build.py index 8e4b8c2c..3fce8871 100644 --- a/pungi/phases/image_build.py +++ b/pungi/phases/image_build.py @@ -60,7 +60,12 @@ class ImageBuildPhase(base.PhaseLoggerMixin, base.ImageConfigMixin, base.ConfigG install_tree_from = image_conf.pop('install_tree_from', variant.uid) if '://' in install_tree_from: + # It's a URL, return it unchanged return install_tree_from + if install_tree_from.startswith("/"): + # It's a path on local filesystem. + return translate_path(self.compose, install_tree_from) + install_tree_source = self.compose.all_variants.get(install_tree_from) if not install_tree_source: raise RuntimeError( diff --git a/pungi/util.py b/pungi/util.py index f878a83c..83c07192 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -731,6 +731,9 @@ def get_repo_url(compose, repo, arch='$basearch'): repo = repo['baseurl'] except KeyError: raise RuntimeError('Baseurl is required in repo dict %s' % str(repo)) + if repo.startswith("/"): + # It's an absolute path, translate it and return it + return translate_path(compose, repo) if '://' not in repo: # this is a variant name if compose is not None: diff --git a/tests/test_imagebuildphase.py b/tests/test_imagebuildphase.py index fad8a820..d163929c 100644 --- a/tests/test_imagebuildphase.py +++ b/tests/test_imagebuildphase.py @@ -313,6 +313,67 @@ class TestImageBuildPhase(PungiTestCase): "scratch": False, }) + @mock.patch("pungi.phases.image_build.ThreadPool") + def test_image_build_set_install_tree_from_path(self, ThreadPool): + compose = DummyCompose(self.topdir, { + "image_build": { + "^Server$": [ + { + "image-build": { + "format": ["docker"], + "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"], + "install_tree_from": "/my/tree", + } + } + ] + }, + "koji_profile": "koji", + "translate_paths": [("/my", "http://example.com")], + }) + + self.assertValidConfig(compose.conf) + + 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.assertDictEqual(args[0][1], { + "image_conf": { + "image-build": { + "install_tree": "http://example.com/tree", + "kickstart": "fedora-docker-base.ks", + "format": ["docker"], + "repo": self.topdir + "/compose/Server/$arch/os", + "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": self.topdir + "/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg", + "image_dir": self.topdir + "/compose/Server/%(arch)s/images", + "relative_image_dir": "Server/%(arch)s/images", + "link_type": "hardlink-or-copy", + "scratch": False, + }) + @mock.patch('pungi.phases.image_build.ThreadPool') def test_image_build_set_extra_repos(self, ThreadPool): compose = DummyCompose(self.topdir, { diff --git a/tests/test_util.py b/tests/test_util.py index 04e3c883..34023a47 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -626,6 +626,10 @@ class GetRepoFuncsTestCase(unittest.TestCase): url = util.get_repo_url(self.compose, 'http://example.com/repo') self.assertEqual(url, 'http://example.com/repo') + def test_get_repo_url_from_path(self): + url = util.get_repo_url(self.compose, os.path.join(self.tmp_dir, "repo")) + self.assertEqual(url, "http://example.com/repo") + def test_get_repo_url_from_variant_uid(self): url = util.get_repo_url(self.compose, 'Server') self.assertEqual(url, 'http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os')