From 8b64f220ceb68952ef6d4548dd690011240eccee Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 19 Dec 2024 10:20:23 -0500 Subject: [PATCH 1/3] ci/get-ocp-repo.sh: use getopt to parse options Prep for adding another option, which would then make the getopt option more obviously cleaner than the ad-hoc approach. --- ci/get-ocp-repo.sh | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/ci/get-ocp-repo.sh b/ci/get-ocp-repo.sh index 0088db548..ebc7cf8c5 100755 --- a/ci/get-ocp-repo.sh +++ b/ci/get-ocp-repo.sh @@ -25,20 +25,22 @@ 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= +rc=0 +options=$(getopt --options h --longoptions help,cosa-workdir:,ocp-layer: -- "$@") || 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;; + --) break;; + *) echo "$0: invalid argument: $1" >&2; exit 1;; + esac + shift +done if [ -n "$ocp_manifest" ]; then # --ocp-layer path From 3888a6e556160ce01c258bdf6dd3735af692e0a1 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 19 Dec 2024 10:23:25 -0500 Subject: [PATCH 2/3] ci/get-ocp-repo.sh: fix `--ocp-layer` case There is no cosa workdir when building the extensions image or the node image and so we shouldn't reference the `cosa_workdir` variable. Instead output the repo file to the same directory in which the OCP manifest is. --- ci/get-ocp-repo.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ci/get-ocp-repo.sh b/ci/get-ocp-repo.sh index ebc7cf8c5..576771246 100755 --- a/ci/get-ocp-repo.sh +++ b/ci/get-ocp-repo.sh @@ -51,6 +51,8 @@ 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) + + output_dir=$(dirname "$ocp_manifest") else [ -n "$cosa_workdir" ] # --cosa-workdir path @@ -96,9 +98,12 @@ else rhel_version=${rhel_version//./} fi info "Got RHEL version $rhel_version from automatic-version-prefix value $version" + + output_dir="$cosa_workdir/src/config" 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" From bd70c7771d796e1b837ad284f6f838230efd04b4 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 19 Dec 2024 10:25:43 -0500 Subject: [PATCH 3/3] ci/get-ocp-repo.sh: add `--output-dir` In the node layering case, we're directly bind-mounting the build context dir. It's mounted read-only, so we can't write `ocp.repo` there. And even if we could, we shouldn't modify the build context if we don't need to. Add a new `--output-dir` option to allow changing the directory to which to write `ocp.repo`. Use this in the node layering flow to output to `/run/yum.repos.d`, which is an already established API for transient repo definitions. --- Containerfile | 2 +- ci/get-ocp-repo.sh | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Containerfile b/Containerfile index 5ccec3d2f..2243f0aba 100644 --- a/Containerfile +++ b/Containerfile @@ -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 diff --git a/ci/get-ocp-repo.sh b/ci/get-ocp-repo.sh index 576771246..c66d5c3ac 100755 --- a/ci/get-ocp-repo.sh +++ b/ci/get-ocp-repo.sh @@ -10,13 +10,17 @@ set -euo pipefail print_usage_and_exit() { cat 1>&2 <<'EOF' -Usage: $0 +Usage: $0 [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 } @@ -27,8 +31,9 @@ info() { cosa_workdir= ocp_manifest= +output_dir= rc=0 -options=$(getopt --options h --longoptions help,cosa-workdir:,ocp-layer: -- "$@") || rc=$? +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 @@ -36,6 +41,7 @@ while [ $# -ne 0 ]; do -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 @@ -52,7 +58,9 @@ if [ -n "$ocp_manifest" ]; then # osname is used lower down, so set it osname=$(source /usr/lib/os-release; if [ $ID == centos ]; then echo scos; fi) - output_dir=$(dirname "$ocp_manifest") + if [ -z "$output_dir" ]; then + output_dir=$(dirname "$ocp_manifest") + fi else [ -n "$cosa_workdir" ] # --cosa-workdir path @@ -99,7 +107,9 @@ else fi info "Got RHEL version $rhel_version from automatic-version-prefix value $version" - output_dir="$cosa_workdir/src/config" + if [ -z "$output_dir" ]; then + output_dir="$cosa_workdir/src/config" + fi fi mkdir -p "$output_dir"