Skip to content

Commit 251c1e9

Browse files
committed
ci/get-ocp-repo.sh: Fixes for scos to accomodate building images in CI
- For scos, we need the rhel-9.x-server-ose repo to get the Openshift releated binaries (kubelet, oc..) - Append the c9s.repo so the packages for the rest of the images come from the CentOS Stream repos. - Install centos stream packages so GPG keys are available when accessing the CentOS Stream repos
1 parent acad1a7 commit 251c1e9

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

Containerfile

+1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ RUN --mount=type=bind,target=/run/src --mount=type=secret,id=yumrepos,target=/et
3535
find /usr -name '*.pyc' -exec mv {} {}.bak \; && \
3636
if [ "${OPENSHIFT_CI}" != 0 ]; then /run/src/ci/get-ocp-repo.sh --ocp-layer /run/src/packages-openshift.yaml --output-dir /etc/yum.repos.d; fi && \
3737
/run/src/scripts/apply-manifest /run/src/packages-openshift.yaml && \
38+
if [ "${OPENSHIFT_CI}" != 0 ]; then /run/src/ci/get-ocp-repo.sh --output-dir /etc/yum.repos.d --cleanup; fi && \
3839
find /usr -name '*.pyc.bak' -exec sh -c 'mv $1 ${1%.bak}' _ {} \; && \
3940
ostree container commit

ci/get-ocp-repo.sh

+66-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,50 @@ info() {
2929
echo "INFO:" "$@" >&2
3030
}
3131

32+
cleanup_repos() {
33+
# if we had installed the packages and created symlinks, remove it
34+
if rpm -q centos-release-cloud; then
35+
dnf remove -y centos-release-{cloud,nfv,virt}-common
36+
find "/usr/share/distribution-gpg-keys/centos" -type l -exec rm -f {} \;
37+
echo "Removed all symbolic links and packages installed for scos"
38+
fi
39+
# remove ocp.repo file
40+
if [ -n "$ocp_manifest" ]; then
41+
if [ -z "$output_dir" ]; then
42+
output_dir=$(dirname "$ocp_manifest")
43+
fi
44+
else
45+
if [ -z "$output_dir" ]; then
46+
output_dir="$cosa_workdir/src/config"
47+
fi
48+
fi
49+
rm "$output_dir/ocp.repo"
50+
echo "Removed repo file $output_dir/ocp.repo"
51+
}
52+
53+
create_gpg_keys() {
54+
# Check if centos-stream-release is installed and centos-release-cloud is not
55+
if rpm -q centos-stream-release && ! rpm -q centos-release-cloud; then
56+
dnf install -y centos-release-{cloud,nfv,virt}-common
57+
fi
58+
59+
# Create directory for CentOS distribution GPG keys
60+
mkdir -p /usr/share/distribution-gpg-keys/centos
61+
# Create symbolic links for GPG keys
62+
if [ ! -e "/usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-CentOS-Official" ]; then
63+
ln -s /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial /usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-CentOS-Official
64+
ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Cloud
65+
ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
66+
ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-NFV
67+
ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Virtualization
68+
fi
69+
}
70+
3271
cosa_workdir=
3372
ocp_manifest=
3473
output_dir=
3574
rc=0
36-
options=$(getopt --options h --longoptions help,cosa-workdir:,ocp-layer:,output-dir: -- "$@") || rc=$?
75+
options=$(getopt --options h --longoptions help,cosa-workdir:,ocp-layer:,output-dir:,cleanup,create-gpg-keys -- "$@") || rc=$?
3776
[ $rc -eq 0 ] || print_usage_and_exit
3877
eval set -- "$options"
3978
while [ $# -ne 0 ]; do
@@ -42,6 +81,8 @@ while [ $# -ne 0 ]; do
4281
--cosa-workdir) cosa_workdir=$2; shift;;
4382
--ocp-layer) ocp_manifest=$2; shift;;
4483
--output-dir) output_dir=$2; shift;;
84+
--cleanup) cleanup_repos; exit 0;;
85+
--create-gpg-keys) create_gpg_keys; exit 0;;
4586
--) break;;
4687
*) echo "$0: invalid argument: $1" >&2; exit 1;;
4788
esac
@@ -50,8 +91,6 @@ done
5091

5192
if [ -n "$ocp_manifest" ]; then
5293
# --ocp-layer path
53-
rhel_version=$(source /usr/lib/os-release; echo ${VERSION_ID//./})
54-
info "Got RHEL version $rhel_version from /usr/lib/os-release"
5594
ocp_version=$(rpm-ostree compose tree --print-only "$ocp_manifest" | jq -r '.metadata.ocp_version')
5695
ocp_version=${ocp_version//./-}
5796
info "Got OpenShift version $ocp_version from $ocp_manifest"
@@ -61,6 +100,21 @@ if [ -n "$ocp_manifest" ]; then
61100
if [ -z "$output_dir" ]; then
62101
output_dir=$(dirname "$ocp_manifest")
63102
fi
103+
104+
# get rhel version corresponding to the release so we can get the
105+
# correct OpenShift rpms from those for scos. These packages are not
106+
# available in CentOS Stream
107+
if [ "$osname" = scos ]; then
108+
workdir=$(dirname "$ocp_manifest")
109+
manifest="$workdir/manifest.yaml"
110+
json=$(rpm-ostree compose tree --print-only "$manifest")
111+
version=$(jq -r '.["automatic-version-prefix"]' <<< "$json")
112+
rhel_version=$(cut -f2 -d. <<< "$version")
113+
info "Got RHEL version $rhel_version from rhel manifest for scos"
114+
else
115+
rhel_version=$(source /usr/lib/os-release; echo ${VERSION_ID//./})
116+
info "Got RHEL version $rhel_version from /usr/lib/os-release"
117+
fi
64118
else
65119
[ -n "$cosa_workdir" ]
66120
# --cosa-workdir path
@@ -132,7 +186,16 @@ fi
132186
if [ "$osname" = scos ]; then
133187
info "Neutering RHEL repos for SCOS"
134188
awk '/server-ose/,/^$/' "$repo_path" > "$repo_path.tmp"
189+
# only pull in certain Openshift packages as the rest come from the c9s repo
190+
sed -i '/^baseurl = /a includepkgs=openshift-* ose-aws-ecr-* ose-azure-acr-* ose-gcp-gcr-*' "$repo_path.tmp"
191+
# add the contents of the CentOS Stream repo
192+
workdir="$cosa_workdir/src/config"
193+
if [ -n "$ocp_manifest" ]; then
194+
workdir=$(dirname "$ocp_manifest")
195+
fi
196+
cat "$workdir/c9s.repo" >> "$repo_path.tmp"
135197
mv "$repo_path.tmp" "$repo_path"
198+
create_gpg_keys
136199
fi
137200
138201
cat "$repo_path"

extensions/Dockerfile

+1-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@ WORKDIR /os
88
ADD . .
99
ARG COSA
1010
ARG VARIANT
11-
RUN if [[ -z "$COSA" ]] ; then ci/get-ocp-repo.sh --ocp-layer packages-openshift.yaml; fi
12-
# on SCOS, we need to add the GPG keys of the various SIGs we need
13-
RUN if rpm -q centos-stream-release && ! rpm -q centos-release-cloud; then dnf install -y centos-release-{cloud,nfv,virt}-common; fi
14-
RUN mkdir -p /usr/share/distribution-gpg-keys/centos
15-
RUN ln -s /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial /usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-CentOS-Official
16-
RUN ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Cloud
17-
RUN ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
18-
RUN ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-NFV
19-
RUN ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Virtualization
11+
RUN if [[ -z "$COSA" ]] ; then ci/get-ocp-repo.sh --ocp-layer packages-openshift.yaml; else ci/get-ocp-repo.sh --create-gpg-keys; fi
2012
RUN if [[ -n "${VARIANT}" ]]; then MANIFEST="manifest-${VARIANT}.yaml"; EXTENSIONS="extensions-${VARIANT}.yaml"; else MANIFEST="manifest.yaml"; EXTENSIONS="extensions.yaml"; fi && rpm-ostree compose extensions --rootfs=/ --output-dir=/usr/share/rpm-ostree/extensions/ ./"${MANIFEST}" ./"${EXTENSIONS}"
2113

2214
## Creates the repo metadata for the extensions.

0 commit comments

Comments
 (0)