Skip to content

Commit b8fbcd9

Browse files
committed
get-ocp-repo.sh: drastically simplify
Now that (1) we've reworked the layered node image build to only enable the repos it needs, and (2) we've simplified the CentOS Stream GPG keys, we can delete all of the complex logic in this repo. It basically just boils down to curl'ing down all the repo files we may need to build the various artifacts that use this script.
1 parent c60f08b commit b8fbcd9

File tree

5 files changed

+20
-203
lines changed

5 files changed

+20
-203
lines changed

Diff for: Containerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ find /usr -name '*.pyc' -exec mv {} {}.bak \;
4040

4141
# fetch repos from in-cluster mirrors if we're running in OpenShift CI
4242
if [ "${OPENSHIFT_CI}" != 0 ]; then
43-
/run/src/ci/get-ocp-repo.sh --ocp-layer /run/src/packages-openshift.yaml --output-dir /etc/yum.repos.d
43+
/run/src/ci/get-ocp-repo.sh /etc/yum.repos.d/ocp.repo
4444
fi
4545

4646
# XXX: patch cri-o spec to use tmpfiles
@@ -52,9 +52,9 @@ source /etc/os-release
5252
rpm-ostree experimental compose treefile-apply \
5353
--var id=$ID /run/src/packages-openshift.yaml
5454

55-
# do any cleanups necessary to undo what `get-ocp-repo.sh` did
55+
# cleanup the repo file we injected
5656
if [ "${OPENSHIFT_CI}" != 0 ]; then
57-
/run/src/ci/get-ocp-repo.sh --output-dir /etc/yum.repos.d --cleanup
57+
rm /etc/yum.repos.d/ocp.repo
5858
fi
5959

6060
find /usr -name '*.pyc.bak' -exec sh -c 'mv $1 ${1%.bak}' _ {} \;

Diff for: ci/get-ocp-repo.sh

+11-197
Original file line numberDiff line numberDiff line change
@@ -1,205 +1,19 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
# This script is used when running within the OpenShift CI clusters to fetch
5-
# the RHEL and OCP yum repo files from an in-cluster service that mirrors the
6-
# content. It's called from three places:
7-
# - prow-entrypoint.sh: CI tests that build & and test different variants
8-
# - extensions/Dockerfile: when building the extensions container in OpenShift CI
9-
# - Containerfile: when building the node image in CI
10-
11-
print_usage_and_exit() {
12-
cat 1>&2 <<'EOF'
13-
Usage: $0 <MODE> [OPTIONS]
14-
15-
Fetch mirrored RHEL/OCP yum repo files from OpenShift CI's in-cluster service.
16-
The following modes are supported:
17-
18-
--cosa-workdir PATH Get RHEL and OCP versions from manifests in cosa workdir
19-
--ocp-layer MANIFEST Get RHEL version from /usr/lib/os-release and OCP version from manifest
20-
21-
The following options are supported
22-
23-
--output-dir PATH Directory to which to output ocp.repo file
24-
EOF
25-
exit 1
26-
}
27-
28-
info() {
29-
echo "INFO:" "$@" >&2
30-
}
31-
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-
# enablerepo added in case the repo is disabled (when building extensions)
56-
if rpm -q centos-stream-release && ! rpm -q centos-release-cloud; then
57-
dnf install -y centos-release-{cloud,nfv,virt}-common --enablerepo extras-common
58-
fi
59-
60-
# Create directory for CentOS distribution GPG keys
61-
mkdir -p /usr/share/distribution-gpg-keys/centos
62-
# Create symbolic links for GPG keys
63-
if [ ! -e "/usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-CentOS-Official" ]; then
64-
ln -s /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial /usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-CentOS-Official
65-
ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Cloud
66-
ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
67-
ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-NFV
68-
ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Virtualization
69-
fi
70-
}
71-
72-
cosa_workdir=
73-
ocp_manifest=
74-
output_dir=
75-
rc=0
76-
options=$(getopt --options h --longoptions help,cosa-workdir:,ocp-layer:,output-dir:,cleanup -- "$@") || rc=$?
77-
[ $rc -eq 0 ] || print_usage_and_exit
78-
eval set -- "$options"
79-
while [ $# -ne 0 ]; do
80-
case "$1" in
81-
-h | --help) print_usage_and_exit;;
82-
--cosa-workdir) cosa_workdir=$2; shift;;
83-
--ocp-layer) ocp_manifest=$2; shift;;
84-
--output-dir) output_dir=$2; shift;;
85-
--cleanup) cleanup_repos; exit 0;;
86-
--) break;;
87-
*) echo "$0: invalid argument: $1" >&2; exit 1;;
88-
esac
89-
shift
90-
done
91-
92-
if [ -n "$ocp_manifest" ]; then
93-
# --ocp-layer path
94-
ocp_version=$(rpm-ostree compose tree --print-only "$ocp_manifest" | jq -r '.metadata.ocp_version')
95-
ocp_version=${ocp_version//./-}
96-
info "Got OpenShift version $ocp_version from $ocp_manifest"
97-
# osname is used lower down, so set it
98-
osname=$(source /usr/lib/os-release; if [ $ID == centos ]; then echo scos; fi)
99-
100-
if [ -z "$output_dir" ]; then
101-
output_dir=$(dirname "$ocp_manifest")
102-
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
118-
else
119-
[ -n "$cosa_workdir" ]
120-
# --cosa-workdir path
121-
122-
# the OCP version always comes from packages-openshift.yaml
123-
ocp_version=$(rpm-ostree compose tree --print-only "$cosa_workdir/src/config/packages-openshift.yaml" | jq -r '.metadata.ocp_version')
124-
ocp_version=${ocp_version//./-}
125-
info "Got OpenShift version $ocp_version from packages-openshift.yaml"
126-
127-
# the RHEL version comes from the target manifest
128-
129-
# first, make sure we're looking at the right manifest
130-
manifest="$cosa_workdir/src/config/manifest.yaml"
131-
if [ -f "$cosa_workdir/src/config.json" ]; then
132-
variant="$(jq --raw-output '."coreos-assembler.config-variant"' 'src/config.json')"
133-
manifest="$cosa_workdir/src/config/manifest-${variant}.yaml"
134-
fi
135-
136-
# flatten manifest and query a couple of fields
137-
json=$(rpm-ostree compose tree --print-only "$manifest")
138-
osname=$(jq -r '.metadata.name' <<< "$json")
139-
is_ocp_variant=$(jq '.packages | contains(["cri-o"])' <<< "$json")
140-
141-
if [ "$osname" = scos ] && [ "$is_ocp_variant" = false ]; then
142-
# this is the pure SCOS case; we don't need any additional repos at all
143-
info "Building pure SCOS variant. Exiting..."
144-
exit 0
145-
elif [ "$osname" = scos ]; then
146-
# We still need the OCP repos for now unfortunately because not
147-
# everything is in the Stream repo. For the RHEL version, just use the
148-
# default variant's one.
149-
json=$(rpm-ostree compose tree --print-only "$cosa_workdir/src/config/manifest.yaml")
150-
fi
151-
version=$(jq -r '.["automatic-version-prefix"]' <<< "$json")
152-
if [ "$is_ocp_variant" = true ]; then
153-
# RHEL version is second field
154-
info "Building OCP variant"
155-
rhel_version=$(cut -f2 -d. <<< "$version")
156-
else
157-
# RHEL version is first and second field
158-
info "Building pure variant"
159-
rhel_version=$(cut -f1-2 -d. <<< "$version")
160-
rhel_version=${rhel_version//./}
161-
fi
162-
info "Got RHEL version $rhel_version from automatic-version-prefix value $version"
163-
164-
if [ -z "$output_dir" ]; then
165-
output_dir="$cosa_workdir/src/config"
166-
fi
167-
fi
168-
169-
mkdir -p "$output_dir"
170-
repo_path="$output_dir/ocp.repo"
171-
172-
set -x
173-
curl --fail -L "http://base-${ocp_version}-rhel${rhel_version}.ocp.svc.cluster.local" -o "$repo_path"
174-
set +x
175-
176-
if [ "${rhel_version}" = 96 ]; then
177-
# XXX: also currently also add 9.4 repos for crun-wasm when building extensions
4+
urls=(
5+
# theoretically that's the only one we need
6+
"http://base-4-19-rhel96.ocp.svc.cluster.local"
7+
# XXX: but also currently add 9.4 repos for crun-wasm when building extensions
1788
# https://github.com/openshift/os/issues/1680
1799
# https://github.com/openshift/os/pull/1682
18010
# https://issues.redhat.com/browse/COS-3075
181-
curl --fail -L http://base-4-19-rhel94.ocp.svc.cluster.local >> "$repo_path"
182-
fi
11+
"http://base-4-19-rhel94.ocp.svc.cluster.local"
12+
)
18313

184-
# If we're building the SCOS OKD variant, then strip away all the RHEL repos and just keep the plashet.
185-
# Temporary workaround until we have all packages for SCOS in CentOS Stream.
186-
if [ "$osname" = scos ]; then
187-
info "Neutering RHEL repos for SCOS"
188-
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-
# pull in the mirror repo as well in case there are newer versions in the composes
197-
# and we require older versions - this happens because we build the node images async
198-
# and the composes move fast.
199-
cat "$workdir/c9s.repo" >> "$repo_path.tmp"
200-
cat "$workdir/c9s-mirror.repo" >> "$repo_path.tmp"
201-
mv "$repo_path.tmp" "$repo_path"
202-
create_gpg_keys
203-
fi
14+
dest=$1; shift
20415

205-
cat "$repo_path"
16+
rm -f "$dest"
17+
for url in ${urls[$@]}; do
18+
curl --fail -L "$url" >> "$dest"
19+
done

Diff for: ci/prow-entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ cosa_init() {
6060

6161
# Initialize the .repo files
6262
prepare_repos() {
63-
src/config/ci/get-ocp-repo.sh --cosa-workdir .
63+
src/config/ci/get-ocp-repo.sh src/config/ocp.repo
6464
}
6565

6666
# Do a cosa build & cosa build-extensions only.

Diff for: extensions-ocp-rhel-9.6.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ extensions:
1313
# XXX: temporarily add rhel-9.4-appstream for crun-wasm
1414
# https://github.com/openshift/os/issues/1680
1515
# https://issues.redhat.com/browse/COS-3075
16-
# NOTE: when reverting this, also revert the associated hack in get-ocp-repo.sh
1716
- rhel-9.4-appstream
1817
packages:
1918
- crun-wasm

Diff for: extensions/Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ RUN mkdir /os
77
WORKDIR /os
88
ADD . .
99
ARG OPENSHIFT_CI=0
10-
RUN if [ "${OPENSHIFT_CI}" != 0 ]; then ci/get-ocp-repo.sh --ocp-layer packages-openshift.yaml; fi
1110
RUN --mount=type=secret,id=yumrepos,target=/os/secret.repo <<EOF
1211
set -xeuo pipefail
1312

13+
# fetch repos from in-cluster mirrors if we're running in OpenShift CI
14+
if [ "${OPENSHIFT_CI}" != 0 ]; then
15+
/run/src/ci/get-ocp-repo.sh ocp.repo
16+
fi
17+
1418
. /etc/os-release
1519
if [ $ID = rhel ]; then
1620
MANIFEST="manifest-rhel-9.6.yaml"

0 commit comments

Comments
 (0)