Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
attempted srpm approach with repotrack
Browse files Browse the repository at this point in the history
  • Loading branch information
jupierce committed Mar 22, 2023
1 parent 0dec3d2 commit 18432c0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
67 changes: 67 additions & 0 deletions doozerlib/cli/__main__.py
Expand Up @@ -1637,6 +1637,73 @@ def release_calc_previous(version, arch, graph_url, graph_content_stable, graph_
print(','.join(results))


@cli.command('config:rhcos-srpms')
@click.option("--version", metavar="RHCOS_VER", help="RHCOS version for which to collection SRPMS (e.g. 413.92.202303212039-0).", required=True)
@click.option("-o", "--output", metavar="DIR", help="Output directory to sync to", required=True)
@click.option("-c", "--cachedir", metavar="DIR", help="Cache directory for yum", required=True)
@click.option("-a", "--arch",
metavar='ARCH',
help="Arch for which the repo should be generated",
default='x86_64', required=False)
@pass_runtime
def config_rhcos_src(runtime, version, output, cachedir, arch):
runtime.initialize(clone_distgits=False)

from doozerlib.rhcos import RHCOSBuildInspector

runtime.logger.info(f'Pulling RHCOS package information for {version} and arch={arch}')
inspector = RHCOSBuildInspector(runtime, pullspec_for_tag={}, brew_arch=arch, build_id=version)
package_build_objects = inspector.get_package_build_objects()
cachedir_path = pathlib.Path(cachedir)

repos = runtime.repos
yum_conf = """
[main]
cachedir={}/$basearch/$releasever
reposdir={}
keepcache=0
debuglevel=2
logfile={}/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
""".format(str(cachedir_path.absolute()), str(cachedir_path.absolute()), runtime.working_dir)

repos_content = repos.repo_file('unsigned', enabled_repos=[], arch=arch)
content = "{}\n\n{}".format(yum_conf, repos_content)

output_path = pathlib.Path(output)
output_path.mkdir(parents=True, exist_ok=True)

cachedir_path.mkdir(parents=True, exist_ok=True)

try:
# If corrupted, reposync metadata can interfere with subsequent runs.
# Ensure we have a clean space for each invocation.
metadata_dir = tempfile.mkdtemp(prefix='reposync-metadata.', dir=cachedir)
yc_file = tempfile.NamedTemporaryFile()
yc_file.write(content.encode('utf-8'))

# must flush so it can be read
yc_file.flush()

first_run_args = '--refresh' # refresh repo data on first run
for package_name, build_obj in package_build_objects.items():
package = build_obj['nvr']
cmd = f'repotrack --destdir={str(output_path)} {first_run_args} -c {yc_file.name} --enablerepo "rhel-9*" --source --arch {arch} {package_name}'
first_run_args = ''

rc, out, err = exectools.cmd_gather(cmd, realtime=True)
if rc != 0:
runtime.logger.warning('Failed to sync package {}:\nout={}\nerr={}'.format(package, out, err))

finally:
yc_file.close()
shutil.rmtree(metadata_dir, ignore_errors=True)


@cli.command("beta:reposync", short_help="Sync yum repos listed in group.yaml to local directory.")
@click.option("-o", "--output", metavar="DIR", help="Output directory to sync to", required=True)
@click.option("-c", "--cachedir", metavar="DIR", help="Cache directory for yum", required=True)
Expand Down
5 changes: 3 additions & 2 deletions doozerlib/repos.py
Expand Up @@ -247,7 +247,8 @@ def repo_file(self, repo_type, enabled_repos=[], empty_repos=[], arch=None):
:param repo_type: Whether to prefer signed or unsigned repos.
:param enabled_repos: A list of group.yml repo names which should be enabled. If a repo is enabled==1
in group.yml, that setting takes precedence over this list. If not enabled==1 in group.yml and not
found in this list, the repo will be returned as enabled==0.
found in this list, the repo will be returned as enabled==0. If '*' is included in the list,
all repos will be enabled.
:param empty_repos: A list of repo names to return defined as no-op yum repos.
:param arch: The architecture for which this repository should be generated. If None, all architectures
will be included in the returned str.
Expand All @@ -257,7 +258,7 @@ def repo_file(self, repo_type, enabled_repos=[], empty_repos=[], arch=None):
for r in self._repos.values():

enabled = r.enabled # If enabled in group.yml, it will always be enabled.
if enabled_repos and r.name in enabled_repos:
if enabled_repos and (r.name in enabled_repos or '*' in enabled_repos):
enabled = True

if arch: # Generating a single arch?
Expand Down

0 comments on commit 18432c0

Please sign in to comment.