Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 78 additions & 6 deletions .ostree/get_ostree_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ ostree_dir="${OSTREE_DIR:-"$(dirname "$(realpath "$0")")"}"

if [ -z "${4:-}" ] || [ "${1:-}" = help ] || [ "${1:-}" = -h ]; then
cat <<EOF
Usage: $0 packages [runtime|testing] DISTRO-MAJOR[.MINOR] [json|yaml|raw|toml]
The script will use the packages and roles files in $ostree_dir to
construct the list of packages needed to build the ostree image. The script
will output the list of packages in the given format
Usage: $0 packages|repos runtime|testing DISTRO-MAJOR[.MINOR] json|yaml|raw|toml
The script will use the packages, repos and roles files in $ostree_dir to
construct the list of packages or repos needed to build the ostree image. The script
will output the list of packages or repos in the given format
- json is a JSON list like ["pkg1","pkg2",....,"pkgN"]
- yaml is the YAML list format
- raw is the list of packages, one per line
- raw is the list of packages, one per line, or repos in INI .repo format
- toml is a list of [[packages]] elements as in https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/composing_installing_and_managing_rhel_for_edge_images/index#creating-an-image-builder-blueprint-for-a-rhel-for-edge-image-using-the-command-line-interface_composing-a-rhel-for-edge-image-using-image-builder-command-line
The DISTRO-MAJOR.MINOR is the same format used by Ansible for distribution e.g. CentOS-8, RedHat-8.9, etc.
- toml is the repo format needed for osbuild-composer
EOF
exit 1
fi
Expand Down Expand Up @@ -68,7 +69,7 @@ get_packages() {
local ostree_dir pkgtype pkgfile rolefile
ostree_dir="$1"
for pkgtype in "${pkgtypes[@]}"; do
for suff in "" "-$distro" "-${distro}-${major_ver}" "-${distro}-${ver}"; do
for suff in "${suffix_list[@]}"; do
pkgfile="$ostree_dir/packages-${pkgtype}${suff}.txt"
if [ -f "$pkgfile" ]; then
cat "$pkgfile"
Expand Down Expand Up @@ -120,10 +121,81 @@ format_packages_toml() {
done
}

get_repos() {
local ostree_dir repotype repofile rolefile
ostree_dir="$1"
for repotype in "${pkgtypes[@]}"; do
for suff in "${suffix_list[@]}"; do
repofile="$ostree_dir/repos-${repotype}${suff}.repo"
if [ -f "$repofile" ]; then
cat "$repofile"
fi
done
rolefile="$ostree_dir/roles-${repotype}.txt"
if [ -f "$rolefile" ]; then
local roles role rolepath
roles="$(cat "$rolefile")"
for role in $roles; do
rolepath="$(get_rolepath "$ostree_dir" "$role")"
if [ -z "$rolepath" ]; then
1>&2 echo ERROR - could not find role "$role" - please use ANSIBLE_COLLECTIONS_PATH
exit 2
fi
get_repos "$rolepath"
done
fi
done
}

format_repos_json() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Potential risk with shell variable expansion in repo_str.replace.

Review whether escaping dollar signs in repo_str is required, as it may affect legitimate values. If necessary, clarify the reasoning in the documentation.

python -c 'import sys; import json; import configparser
cp = configparser.ConfigParser()
cp.read_file(sys.stdin)
ret = []
# supported is from osbuild-mpp
supported = ["baseurl", "metalink", "mirrorlist",
"enabled", "metadata_expire", "gpgcheck", "username", "password", "priority",
"sslverify", "sslcacert", "sslclientkey", "sslclientcert",
"skip_if_unavailable"]
for section in cp.sections():
repo = {"id": section}
for option in supported:
if cp.has_option(section, option):
repo[option] = cp.get(section, option)
ret.append(repo)
repo_str = json.dumps(ret)
repo_str = repo_str.replace("$", "$$$$")
print(repo_str)
'
}

format_repos_raw() {
cat
}

format_repos_yaml() {
python -c 'import sys; import yaml; import configparser
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: yaml.safe_dump may not preserve ordering of repo fields.

If field order matters for downstream use, consider using OrderedDict or sorting keys before dumping.

Suggested implementation:

+    python -c 'import sys; import yaml; import configparser; from collections import OrderedDict
+cp = configparser.ConfigParser()
+cp.read_file(sys.stdin)

ret = []
# supported is from osbuild-mpp
supported = ["baseurl", "metalink", "mirrorlist",
             "enabled", "metadata_expire", "gpgcheck", "username", "password", "priority",
             "sslverify", "sslcacert", "sslclientkey", "sslclientcert",
             "skip_if_unavailable"]
for section in cp.sections():
    repo = OrderedDict()
    repo["id"] = section
    for option in supported:
        if cp.has_option(section, option):

    repo = {"id": section}
    for option in supported:
        if cp.has_option(section, option):
            repo[option] = cp.get(section, option)
    ret.append(repo)
print(yaml.safe_dump(ret, sort_keys=False))
'

cp = configparser.ConfigParser()
cp.read_file(sys.stdin)
ret = []
for section in cp.sections():
repo = {"id": section}
for option in cp.options(section):
repo[option] = cp.get(section, option)
ret.append(repo)
yaml.safe_dump(ret, sys.stdout)
'
}

distro="${distro_ver%%-*}"
suffix_list=("" "-$distro")
ver="${distro_ver##*-}"
if [[ "$ver" =~ ^([0-9]*) ]]; then
major_ver="${BASH_REMATCH[1]}"
suffix_list+=("-${distro}-${major_ver}")
if [ "$ver" != "$major_ver" ]; then
suffix_list+=("-${distro}-${ver}")
fi
else
echo ERROR: cannot parse major version number from version "$ver"
exit 1
Expand Down
3 changes: 3 additions & 0 deletions .ostree/packages-runtime-CentOS-9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cuda-toolkit-12-9
libnccl-2.27.5-1+cuda12.9
libnccl-devel-2.27.5-1+cuda12.9
33 changes: 33 additions & 0 deletions .ostree/repos-runtime-CentOS-9.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[epel]
name=Extra Packages for Enterprise Linux 9
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
baseurl=https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-9&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9

[epel-next]
name=Extra Packages for Enterprise Linux 9 - Next
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
baseurl=https://dl.fedoraproject.org/pub/epel/next/9/Everything/x86_64
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-next-9&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9

[nvidia-cuda]
name=NVIDIA CUDA repository
gpgkey=https://developer.download.nvidia.com/compute/cuda/repos/rhel9/x86_64/D42D0685.pub
baseurl=https://developer.download.nvidia.com/compute/cuda/repos/rhel9/x86_64
enabled=1

[microsoft-prod]
name=Microsoft Production repository
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
baseurl=https://packages.microsoft.com/rhel/9/prod/
enabled=1
Loading