Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NO-JIRA: ci/get-ocp-repo.sh: add --output-dir #1702

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ARG OPENSHIFT_CI=0
# any Python apps that run (e.g. dnf) will cause pyc creation.
RUN --mount=type=bind,target=/run/src \
find /usr -name '*.pyc' -exec mv {} {}.bak \; && \
if [ "${OPENSHIFT_CI}" != 0 ]; then /run/src/ci/get-ocp-repo.sh --ocp-layer /run/src/packages-openshift.yaml; fi && \
if [ "${OPENSHIFT_CI}" != 0 ]; then /run/src/ci/get-ocp-repo.sh --ocp-layer /run/src/packages-openshift.yaml --output-dir /run/yum.repos.d; fi && \
/run/src/scripts/apply-manifest /run/src/packages-openshift.yaml && \
find /usr -name '*.pyc.bak' -exec sh -c 'mv $1 ${1%.bak}' _ {} \; && \
ostree container commit
49 changes: 33 additions & 16 deletions ci/get-ocp-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ set -euo pipefail

print_usage_and_exit() {
cat 1>&2 <<'EOF'
Usage: $0 <MODE>
Usage: $0 <MODE> [OPTIONS]

Fetch mirrored RHEL/OCP yum repo files from OpenShift CI's in-cluster service.
The following modes are supported:

--cosa-workdir PATH Get RHEL and OCP versions from manifests in cosa workdir
--ocp-layer MANIFEST Get RHEL version from /usr/lib/os-release and OCP version from manifest

The following options are supported

--output-dir PATH Directory to which to output ocp.repo file
EOF
exit 1
}
Expand All @@ -25,20 +29,24 @@ info() {
echo "INFO:" "$@" >&2
}

if [ $# -eq 0 ]; then
print_usage_and_exit
else
mode=$1; shift
cosa_workdir=
ocp_manifest=
if [ "$mode" = "--cosa-workdir" ]; then
cosa_workdir=$1; shift
elif [ "$mode" = "--ocp-layer" ]; then
ocp_manifest=$1; shift
else
print_usage_and_exit
fi
fi
cosa_workdir=
ocp_manifest=
output_dir=
rc=0
options=$(getopt --options h --longoptions help,cosa-workdir:,ocp-layer:,output-dir: -- "$@") || rc=$?
[ $rc -eq 0 ] || print_usage_and_exit
eval set -- "$options"
while [ $# -ne 0 ]; do
case "$1" in
-h | --help) print_usage_and_exit;;
--cosa-workdir) cosa_workdir=$2; shift;;
--ocp-layer) ocp_manifest=$2; shift;;
--output-dir) output_dir=$2; shift;;
--) break;;
*) echo "$0: invalid argument: $1" >&2; exit 1;;
esac
shift
done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously --cosa-workdir and --ocp-layer were exclusive, or at least only the first one would be considered. Do we want to do anything specific if a user passed both here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... when switching to getopt, keeping that check didn't feel worth the lines. The current behaviour of just letting --ocp-layer win seemed fine to me. This script doesn't need a lot of polish. All users of it are in this repo.


if [ -n "$ocp_manifest" ]; then
# --ocp-layer path
Expand All @@ -49,6 +57,10 @@ if [ -n "$ocp_manifest" ]; then
info "Got OpenShift version $ocp_version from $ocp_manifest"
# osname is used lower down, so set it
osname=$(source /usr/lib/os-release; if [ $ID == centos ]; then echo scos; fi)

if [ -z "$output_dir" ]; then
output_dir=$(dirname "$ocp_manifest")
fi
else
[ -n "$cosa_workdir" ]
# --cosa-workdir path
Expand Down Expand Up @@ -94,9 +106,14 @@ else
rhel_version=${rhel_version//./}
fi
info "Got RHEL version $rhel_version from automatic-version-prefix value $version"

if [ -z "$output_dir" ]; then
output_dir="$cosa_workdir/src/config"
fi
fi

repo_path="$cosa_workdir/src/config/ocp.repo"
mkdir -p "$output_dir"
repo_path="$output_dir/ocp.repo"

set -x
curl --fail -L "http://base-${ocp_version}-rhel${rhel_version}.ocp.svc.cluster.local" -o "$repo_path"
Expand Down