Skip to content

Commit 176d885

Browse files
Merge pull request #1935 from locriandev/rpm-ostree-install-legacy
ART-14453: Use rpm-ostree install directly in legacy build pipeline
2 parents 17084e8 + b70494e commit 176d885

6 files changed

Lines changed: 133 additions & 186 deletions

Containerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
ARG IMAGE_FROM=overridden
55
FROM ${IMAGE_FROM} as build
66
ARG OPENSHIFT_CI=0
7-
RUN --mount=type=bind,target=/run/src --mount=type=secret,id=yumrepos,target=/etc/yum.repos.d/secret.repo /run/src/build-node-image.sh
7+
ARG OPENSHIFT_VERSION=overridden
8+
ARG YUM_REPO_NAMES=overridden
9+
RUN --mount=type=bind,target=/run/src --mount=type=secret,id=yumrepos,target=/run/src/secret.repo /run/src/build-node-image.sh
810

911
FROM build as metadata
1012
ARG IMAGE_NAME

build-args-10.2-5.0.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
OPENSHIFT_VERSION=5.0
12
IMAGE_FROM=registry.ci.openshift.org/coreos/rhel-coreos-base:10.2
3+
4+
# Used by the generate-labels script
25
IMAGE_NAME=openshift/ose-rhel-coreos-10
36
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
OPENSHIFT_VERSION=5.0
12
IMAGE_FROM=registry.ci.openshift.org/coreos/rhel-coreos-base:9.8
3+
4+
# Used by the generate-labels script
25
IMAGE_NAME=openshift/ose-rhel-coreos-9
36
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
OPENSHIFT_VERSION=5.0
12
IMAGE_FROM=registry.ci.openshift.org/coreos/stream-coreos-base:10
2-
# SCOS/OKD: no labels.json or OCI labels for name/cpe
3+
4+
# SCOS/OKD: no labels.json or OCI labels for name/cpe (so don't define them)
5+
# IMAGE_NAME=
6+
# 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: 107 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,127 @@ if [ "${OPENSHIFT_CI}" != 0 ]; then
1414
/run/src/ci/get-ocp-repo.sh /etc/yum.repos.d/ocp.repo
1515
fi
1616

17-
# add all the repos from the src repo into `/etc/yum.repos.d` so dnf sees them
17+
# add all the repos from the src repo (including mounted in secret.repo)
18+
# into `/etc/yum.repos.d` so dnf sees them
1819
cat /run/src/*.repo >> /etc/yum.repos.d/git.repo
1920

2021
source /etc/os-release
2122

2223
# XXX: For SCOS, only allow certain packages to come from ART; everything else
2324
# should come from CentOS. We should eventually sever this.
2425
if [ $ID = centos ]; then
25-
# this says: "if the line starts with [.*], turn off printing. if the line starts with [our-repo], turn it on."
26-
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
27-
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
28-
echo 'includepkgs=openshift-*,ose-aws-ecr-*,ose-azure-acr-*,ose-gcp-gcr-*,ose-crio-* ' >> /etc/yum.repos.d/okd.repo.tmp
29-
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-*"
3029
fi
3130

3231
# XXX: patch cri-o spec to use tmpfiles
3332
# https://github.com/CentOS/centos-bootc/issues/393
3433
mkdir -p /var/opt
3534

36-
# this is where all the real work happens
37-
rpm-ostree experimental compose treefile-apply \
38-
--var "osversion=${ID}-${VERSION_ID}" /run/src/packages-openshift.yaml
35+
# Version lock to the specific packages installed on the system already
36+
dnf --disablerepo=* versionlock add '*'
3937

40-
# cleanup any repo files we injected
41-
rm -f /etc/yum.repos.d/{ocp,git,okd}.repo
38+
# Install the OCP packages. Limit to appropriate repos for this stream.
39+
dnf --repo="${YUM_REPO_NAMES}" install -y \
40+
cri-o cri-tools conmon-rs \
41+
openshift-clients openshift-kubelet \
42+
openvswitch3.5 \
43+
NetworkManager-ovs \
44+
ose-aws-ecr-image-credential-provider \
45+
ose-azure-acr-image-credential-provider \
46+
ose-gcp-gcr-image-credential-provider \
47+
ose-crio-credential-provider
48+
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+
57+
# --- postprocess steps ---
58+
# These were previously in the `postprocess` section of packages-openshift.yaml.
59+
60+
# Disable any built-in repos. We need to work in disconnected environments by
61+
# default, and default-enabled repos will be attempted to be fetched by
62+
# rpm-ostree when doing node-local kernel overrides today for e.g. kernel-rt.
63+
for x in $(find /etc/yum.repos.d/ -name '*.repo'); do
64+
sed -i -e 's/enabled\s*=\s*1/enabled=0/g' "$x"
65+
done
66+
67+
# Enable librhsm which enables host subscriptions to work in containers
68+
# https://github.com/rpm-software-management/librhsm/blob/fcd972cbe7c8a3907ba9f091cd082b1090231492/rhsm/rhsm-context.c#L30
69+
ln -sr /run/secrets/etc-pki-entitlement /etc/pki/entitlement-host
70+
ln -sr /run/secrets/rhsm /etc/rhsm-host
71+
72+
# Manually modify SELinux booleans that are needed for OCP use cases
73+
semanage boolean --modify --on container_use_cephfs # RHBZ#1694045
74+
semanage boolean --modify --on virt_use_samba # RHBZ#1754825
75+
76+
# https://gitlab.cee.redhat.com/coreos/redhat-coreos/merge_requests/812
77+
# https://bugzilla.redhat.com/show_bug.cgi?id=1796537
78+
mkdir -p /usr/share/containers/oci/hooks.d
79+
80+
# crio conmon symlink
81+
mkdir -p /usr/libexec/crio
82+
ln -sr /usr/bin/conmon /usr/libexec/crio/conmon
83+
84+
# Inject OpenShift-specific release fields
85+
cat >> /usr/lib/os-release <<EOF
86+
OPENSHIFT_VERSION="${OPENSHIFT_VERSION}"
87+
EOF
88+
89+
# Generate MOTD
90+
# Detect variant based on the Containerfile metadata. In the absence of
91+
# rpm-ostree treefile metadata, we use a heuristic: centos builds are SCOS.
92+
if [ "$ID" = "centos" ]; then
93+
colloquial_name=SCOS
94+
project_name=OKD
95+
else
96+
colloquial_name=RHCOS
97+
project_name=OpenShift
98+
fi
99+
# in the el-only variants, we already have CoreOS in the NAME, so don't
100+
# re-add it when building the node image
101+
if [[ $NAME != *CoreOS* ]]; then
102+
NAME="$NAME CoreOS"
103+
fi
104+
cat > /etc/motd <<EOF
105+
$NAME $OSTREE_VERSION
106+
Part of ${project_name} ${OPENSHIFT_VERSION}, ${colloquial_name} is a Kubernetes-native operating system
107+
managed by the Machine Config Operator (\`clusteroperator/machine-config\`).
108+
109+
WARNING: Direct SSH access to machines is not recommended; instead,
110+
make configuration changes via \`machineconfig\` objects:
111+
https://docs.openshift.com/container-platform/${OPENSHIFT_VERSION}/architecture/architecture-rhcos.html
112+
113+
---
114+
EOF
115+
116+
# Delete leftover files in the layering path
117+
if [ -f /run/.containerenv ]; then
118+
# lockfiles and backup files
119+
rm -f /etc/.pwd.lock /etc/group- /etc/gshadow- /etc/shadow- /etc/passwd-
120+
rm -f /etc/selinux/targeted/*.LOCK
121+
# cache, logs, etc...
122+
rm -rf /var && mkdir /var
123+
# All the entries here should instead be part of their respective
124+
# packages. But we carry them here for now to maintain compatibility.
125+
cat > /usr/lib/tmpfiles.d/openshift.conf << EOF
126+
L /opt/cni - - - - ../../usr/lib/opt/cni
127+
d /var/lib/cni 0755 root root - -
128+
d /var/lib/cni/bin 0755 root root - -
129+
d /var/lib/containers 0755 root root - -
130+
d /var/lib/openvswitch 0755 root root - -
131+
d /var/lib/openvswitch/pki 0755 root root - -
132+
d /var/log/openvswitch 0750 openvswitch hugetlbfs - -
133+
d /var/lib/unbound 0755 unbound unbound - -
134+
EOF
135+
fi
136+
137+
# --- end postprocess steps ---
42138

43139
find /usr -name '*.pyc.bak' -exec sh -c 'mv $1 ${1%.bak}' _ {} \;
44140
ostree container commit

packages-openshift.yaml

Lines changed: 0 additions & 173 deletions
This file was deleted.

0 commit comments

Comments
 (0)