Skip to content

Commit 0f99d7e

Browse files
committed
Use dnf and define repo names in build-args
Instead of rpm-ostree install we can use dnf directly. Also let's define the names of the repos we want to use for each variant in the build-args themselves, which will remove the heuristics we were doing previously inside the build-node-image.sh script to filter out the ones we didn't want.
1 parent 26d3b7b commit 0f99d7e

5 files changed

Lines changed: 28 additions & 31 deletions

File tree

Containerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ARG IMAGE_FROM=overridden
55
FROM ${IMAGE_FROM} as build
66
ARG OPENSHIFT_CI=0
77
ARG OPENSHIFT_VERSION=overridden
8+
ARG YUM_REPO_NAMES=overridden
89
RUN --mount=type=bind,target=/run/src --mount=type=secret,id=yumrepos,target=/run/src/secret.repo /run/src/build-node-image.sh
910

1011
FROM build as metadata

build-args-10.2-5.0.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ IMAGE_FROM=registry.ci.openshift.org/coreos/rhel-coreos-base:10.2
44
# Used by the generate-labels script
55
IMAGE_NAME=openshift/ose-rhel-coreos-10
66
IMAGE_CPE=cpe:/a:redhat:openshift:5.0::el10
7+
8+
# The names of the yum repos to use for the node image build.
9+
YUM_REPO_NAMES=rhel-10.2-baseos,rhel-10.2-appstream,rhel-10.2-early-kernel,rhel-10.2-fast-datapath,rhel-10.2-server-ose-5.0

build-args-9.8-5.0.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ IMAGE_FROM=registry.ci.openshift.org/coreos/rhel-coreos-base:9.8
44
# Used by the generate-labels script
55
IMAGE_NAME=openshift/ose-rhel-coreos-9
66
IMAGE_CPE=cpe:/a:redhat:openshift:5.0::el9
7+
8+
# The names of the yum repos to use for the node image build.
9+
YUM_REPO_NAMES=rhel-9.8-baseos,rhel-9.8-appstream,rhel-9.8-early-kernel,rhel-9.8-fast-datapath,rhel-9.8-server-ose-5.0

build-args-c10s-5.0.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ IMAGE_FROM=registry.ci.openshift.org/coreos/stream-coreos-base:10
44
# SCOS/OKD: no labels.json or OCI labels for name/cpe (so don't define them)
55
# IMAGE_NAME=
66
# IMAGE_CPE=
7+
8+
# The names of the yum repos to use for the node image build.
9+
# XXX: use of the rhel-*server-ose-* ART repo shouldn't happen for OKD; see related XXX
10+
# in build-node-image.sh. Also we must put the ART repo last for the modification
11+
# in the script to work.
12+
YUM_REPO_NAMES=c10s-baseos,c10s-appstream,c10s-sig-nfv,c10s-sig-cloud-okd,rhel-10.2-server-ose-5.0

build-node-image.sh

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,20 @@ source /etc/os-release
2323
# XXX: For SCOS, only allow certain packages to come from ART; everything else
2424
# should come from CentOS. We should eventually sever this.
2525
if [ $ID = centos ]; then
26-
# this says: "if the line starts with [.*], turn off printing. if the line starts with [our-repo], turn it on."
27-
awk "/\[.*\]/{p=0} /\[rhel-10.2-server-ose-5.0\]/{p=1} p" /etc/yum.repos.d/*.repo > /etc/yum.repos.d/okd.repo.tmp
28-
sed -i -e 's,\[rhel-10.2-server-ose-5.0\],\[rhel-10.2-server-ose-5.0-okd\],' /etc/yum.repos.d/okd.repo.tmp
29-
echo 'includepkgs=openshift-*,ose-aws-ecr-*,ose-azure-acr-*,ose-gcp-gcr-*,ose-crio-* ' >> /etc/yum.repos.d/okd.repo.tmp
30-
mv /etc/yum.repos.d/okd.repo{.tmp,}
26+
OPENSHIFT_ART_REPO_NAME=${YUM_REPO_NAMES/*,/} # ART repo == the last repo in the list
27+
dnf config-manager --save \
28+
--setopt="${OPENSHIFT_ART_REPO_NAME}.includepkgs=openshift-*,ose-aws-ecr-*,ose-azure-acr-*,ose-gcp-gcr-*,ose-crio-*"
3129
fi
3230

3331
# XXX: patch cri-o spec to use tmpfiles
3432
# https://github.com/CentOS/centos-bootc/issues/393
3533
mkdir -p /var/opt
3634

37-
# Disable repos that don't match the current OS version to avoid 401 errors
38-
# when rpm-ostree tries to access all repos. This replicates the conditional-include
39-
# logic that was previously in packages-openshift.yaml.
40-
if [ "$ID" = "rhel" ]; then
41-
if [ "$VERSION_ID" = "9.8" ]; then
42-
# Disable rhel-10.2 and centos repos for rhel-9.8 builds
43-
for repo in /etc/yum.repos.d/{ocp,git}.repo; do
44-
[ -f "$repo" ] && sed -i -E '/^\[(rhel-10\.2|c10s)/,/^$/s/^enabled=1$/enabled=0/g' "$repo"
45-
done
46-
elif [ "$VERSION_ID" = "10.2" ]; then
47-
# Disable rhel-9 and centos repos for rhel-10.2 builds
48-
for repo in /etc/yum.repos.d/{ocp,git}.repo; do
49-
[ -f "$repo" ] && sed -i -E '/^\[(rhel-9|c10s)/,/^$/s/^enabled=1$/enabled=0/g' "$repo"
50-
done
51-
fi
52-
elif [ "$ID" = "centos" ] && [ "$VERSION_ID" = "10" ]; then
53-
# Disable rhel repos for centos-10 builds
54-
for repo in /etc/yum.repos.d/{ocp,git}.repo; do
55-
[ -f "$repo" ] && sed -i -E '/^\[rhel-/,/^$/s/^enabled=1$/enabled=0/g' "$repo"
56-
done
57-
fi
35+
# Version lock to the specific packages installed on the system already
36+
dnf --disablerepo=* versionlock add '*'
5837

59-
# Install the OCP packages. Repos have been configured above.
60-
rpm-ostree install \
38+
# Install the OCP packages. Limit to appropriate repos for this stream.
39+
dnf --disablerepo=* --enablerepo="${YUM_REPO_NAMES}" install -y \
6140
cri-o cri-tools conmon-rs \
6241
openshift-clients openshift-kubelet \
6342
openvswitch3.5 \
@@ -67,6 +46,14 @@ rpm-ostree install \
6746
ose-gcp-gcr-image-credential-provider \
6847
ose-crio-credential-provider
6948

49+
# clear the versionlock and clean up any dnf caches / yum repo files we created.
50+
# note `redhat.repo` gets created when you run dnf (via subscription-manager plugin),
51+
# so we'll clean that up too.
52+
dnf --disablerepo=* versionlock clear
53+
dnf clean all
54+
rm -vf /etc/yum.repos.d/{ocp,git,redhat}.repo
55+
56+
7057
# --- postprocess steps ---
7158
# These were previously in the `postprocess` section of packages-openshift.yaml.
7259

@@ -149,8 +136,5 @@ fi
149136

150137
# --- end postprocess steps ---
151138

152-
# cleanup any repo files we injected
153-
rm -f /etc/yum.repos.d/{ocp,git,okd}.repo
154-
155139
find /usr -name '*.pyc.bak' -exec sh -c 'mv $1 ${1%.bak}' _ {} \;
156140
ostree container commit

0 commit comments

Comments
 (0)