|
1 | 1 | #!/bin/bash
|
2 | 2 | set -euo pipefail
|
3 | 3 |
|
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 |
178 | 8 | # https://github.com/openshift/os/issues/1680
|
179 | 9 | # https://github.com/openshift/os/pull/1682
|
180 | 10 | # 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 | +) |
183 | 13 |
|
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 |
204 | 15 |
|
205 |
| -cat "$repo_path" |
| 16 | +rm -f "$dest" |
| 17 | +for url in ${urls[$@]}; do |
| 18 | + curl --fail -L "$url" >> "$dest" |
| 19 | +done |
0 commit comments