Add support for local component repository using file://.

This is needed for offline local builds to build a component which is
stored on local git repository.

This PR also adds OfflineLocalBuildConfiguration configuration class
for offline local builds to set the RESOLVER.
This commit is contained in:
Jan Kaluza
2019-04-01 10:21:29 +02:00
committed by mprahl
parent 67a5a9d1b0
commit 360a8f3b84
4 changed files with 52 additions and 9 deletions

View File

@@ -139,6 +139,12 @@ class LocalBuildConfiguration(BaseConfiguration):
ALLOW_CUSTOM_SCMURLS = True
RESOLVER = 'mbs'
RPMS_ALLOW_REPOSITORY = True
MODULES_ALLOW_REPOSITORY = True
class OfflineLocalBuildConfiguration(LocalBuildConfiguration):
RESOLVER = 'local'
class DevConfiguration(LocalBuildConfiguration):

View File

@@ -542,6 +542,25 @@ class MockModuleBuilder(GenericBuilder):
if self.module.state == models.BUILD_STATES["done"]:
self._createrepo(include_module_yaml=True)
@classmethod
def get_built_rpms_in_module_build(cls, mmd):
"""
:param Modulemd mmd: Modulemd to get the built RPMs from.
:return: list of NVRs
"""
with models.make_session(conf) as db_session:
build = models.ModuleBuild.get_build_from_nsvc(
db_session, mmd.get_name(), mmd.get_stream(), mmd.get_version(),
mmd.get_context())
if build.koji_tag.startswith("repofile://"):
# Modules from local repository have already the RPMs filled in mmd.
return list(mmd.get_rpm_artifacts().get())
else:
koji_session = KojiModuleBuilder.get_session(conf, login=False)
rpms = koji_session.listTaggedRPMS(build.koji_tag, latest=True)[0]
nvrs = set(kobo.rpmlib.make_nvr(rpm, force_epoch=True) for rpm in rpms)
return list(nvrs)
class BaseBuilder(object):
def __init__(self, config, resultsdir):
@@ -565,9 +584,14 @@ class SCMBuilder(BaseBuilder):
def __init__(self, config, resultsdir, source, artifact_name):
super(SCMBuilder, self).__init__(config, resultsdir)
with open(config, "a") as f:
branch = source.split("?#")[1]
git_repo, branch = source.split("?#")
distgit_cmds = self._get_distgit_commands(source)
distgit_get = distgit_cmds[0].format(artifact_name)
if source.startswith("file://"):
# For local git repositories, pass the full path to repository to git command.
distgit_get = distgit_cmds[0].format(git_repo)
else:
distgit_get = distgit_cmds[0].format(artifact_name)
# mock-scm cannot checkout particular commit hash, but only branch.
# We therefore use a command that combines the distgit-command with
@@ -587,10 +611,23 @@ class SCMBuilder(BaseBuilder):
artifact_name),
"config_opts['scm_opts']['distgit_get'] = {!r}\n".format(
distgit_get_branch),
"config_opts['scm_opts']['distgit_src_get'] = '{}'\n".format(
distgit_cmds[1]),
])
# Set distgit_src_get only if it's defined.
if distgit_cmds[1]:
f.write("config_opts['scm_opts']['distgit_src_get'] = '{}'\n".format(
distgit_cmds[1]))
# The local git repositories cloned by `fedpkg clone` typically do not have
# the tarballs with sources committed in a git repo. They normally live in lookaside
# cache on remote server, but we should not try getting them from there for true
# local builds.
# Instead, get them from local path with git repository by passing that path to Mock
# using the `ext_src_dir`.
if git_repo.startswith("file://"):
src_dir = git_repo[len("file://"):]
f.write("config_opts['scm_opts']['ext_src_dir'] = '{}'\n".format(src_dir))
def _make_executable(self, path):
mode = os.stat(path).st_mode
mode |= (mode & 0o444) >> 2 # copy R bits to X

View File

@@ -67,7 +67,10 @@ def init_config(app):
# Load LocalBuildConfiguration section in case we are building modules
# locally.
if "build_module_locally" in sys.argv:
config_section = "LocalBuildConfiguration"
if "--offline"in sys.argv:
config_section = "OfflineLocalBuildConfiguration"
else:
config_section = "LocalBuildConfiguration"
# try getting config_file from os.environ
if 'MBS_CONFIG_FILE' in os.environ:
@@ -333,6 +336,7 @@ class Config(object):
'default': {
'https://src.fedoraproject.org': ('fedpkg clone --anonymous {}',
'fedpkg --release module sources'),
'file://': ('git clone {}', None),
},
'desc': 'Mapping between dist-git and command to '},
'mock_config': {

View File

@@ -126,10 +126,6 @@ def build_module_locally(local_build_nsvs=None, yaml_file=None, srpms=None,
conf.set_item("system", "mock")
conf.set_item("base_module_repofiles", platform_repofiles)
# Use the "local" resolver for offline module builds.
if offline:
conf.set_item("resolver", "local")
# Use our own local SQLite3 database.
confdir = os.path.abspath(os.getcwd())
dbdir = os.path.abspath(os.path.join(confdir, '..')) if confdir.endswith('conf') \