Skip to content

Commit

Permalink
Define the reposync URL in line and fetch modulemd remotely
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Sep 1, 2023
1 parent 0993b40 commit 2f27cc1
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions build_stage_repository
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/usr/bin/env python3

from subprocess import check_output, STDOUT, CalledProcessError
from urllib.request import urlretrieve
import os
import yaml
import glob
import shutil
import time
import hashlib
import sys
import tempfile


def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, source=False):
def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, dist, source=False):
if source:
print(f"Moving {collection} Source RPMs from Copr directory to stage repository")
else:
Expand All @@ -19,7 +21,7 @@ def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, s
if not os.path.exists(dest_folder):
os.mkdir(dest_folder)

repo_folder = f"{src_folder}/el8-{collection}-{version}"
repo_folder = f"{src_folder}/{dist}-{collection}-{version}"

if source:
files = glob.glob(repo_folder + f"/**/*.src.rpm")
Expand All @@ -34,7 +36,8 @@ def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, s


def modulemd_yaml(collection):
return f"modulemd/modulemd-{collection}-el8.yaml"
path, headers = urlretrieve(f"https://raw.githubusercontent.com/theforeman/foreman-packaging/rpm/develop/modulemd/modulemd-{collection}-el8.yaml")
return path


def generate_modulemd_version(version):
Expand Down Expand Up @@ -70,7 +73,7 @@ def create_modulemd(collection, version, stage_dir):
with open(modulemd_yaml(collection), 'r') as file:
modules = yaml.safe_load(file)

modules['data']['artifacts'] = {'rpms': output.splitlines()}
modules['data']['artifacts'] = {'rpms': [str(rpm, 'UTF-8') for rpm in output.splitlines()]}
modules['data']['version'] = generate_modulemd_version(version)
modules['data']['context'] = generate_modulemd_context(collection, version)
modules_yaml = os.path.join(stage_dir, 'repodata', 'modules.yaml')
Expand All @@ -85,7 +88,7 @@ def create_repository(repo_dir):
check_output(['createrepo', repo_dir])


def sync_copr_repository(collection, version, target_dir, source=False):
def sync_copr_repository(collection, version, target_dir, dist, source=False):
if source:
print(f"Syncing {collection} {version} Source RPM repository from Copr")
else:
Expand All @@ -96,9 +99,9 @@ def sync_copr_repository(collection, version, target_dir, source=False):
'reposync',
'--newest-only',
'--repo',
f"el8-{collection}-{version}",
'--config',
'reposync_config.conf',
f"{dist}-{collection}-{version}",
'--repofrompath',
f"{dist}-{collection}-{version},https://download.copr.fedorainfracloud.org/results/@theforeman/{collection}-{version}-staging/rhel-{dist.replace('el', '')}-x86_64/",
'--download-path',
target_dir
]
Expand All @@ -120,15 +123,15 @@ def main():
try:
collection = sys.argv[1]
version = sys.argv[2]
operating_system = sys.argv[3]
dist = sys.argv[3]
except IndexError:
raise SystemExit(f"Usage: {sys.argv[0]} collection version os")

base_dir = 'tmp'
rpm_sync_dir = f"{base_dir}/rpms"
srpm_sync_dir = f"{base_dir}/srpms"

stage_dir = f"{base_dir}/{collection}/{version}/{operating_system}/"
stage_dir = f"{base_dir}/{collection}/{version}/{dist}/"
rpm_dir = f"{stage_dir}/x86_64"
srpm_dir = f"{stage_dir}/source"

Expand All @@ -144,16 +147,16 @@ def main():
if not os.path.exists(srpm_dir):
os.makedirs(srpm_dir)

sync_copr_repository(collection, version, rpm_sync_dir)
sync_copr_repository(collection, version, srpm_sync_dir, source=True)
sync_copr_repository(collection, version, rpm_sync_dir, dist)
sync_copr_repository(collection, version, srpm_sync_dir, dist, source=True)

move_rpms_from_copr_to_stage(collection, version, srpm_sync_dir, srpm_dir, source=True)
move_rpms_from_copr_to_stage(collection, version, rpm_sync_dir, rpm_dir)
move_rpms_from_copr_to_stage(collection, version, srpm_sync_dir, srpm_dir, dist, source=True)
move_rpms_from_copr_to_stage(collection, version, rpm_sync_dir, rpm_dir, dist)

create_repository(rpm_dir)
create_repository(srpm_dir)

if collection in ['foreman', 'katello'] and operating_system == 'el8':
if collection in ['foreman', 'katello'] and dist == 'el8':
create_modulemd(collection, version, rpm_dir)


Expand Down

0 comments on commit 2f27cc1

Please sign in to comment.