From 09bb930e4793881a10ad561e105db631858e10ff Mon Sep 17 00:00:00 2001 From: Patricia Salajova Date: Tue, 23 Jun 2026 14:13:35 +0200 Subject: [PATCH] fix: mount files into container for -f/--from-file --- hack/secret-manager.sh | 50 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/hack/secret-manager.sh b/hack/secret-manager.sh index 6faf0cd653a20..4de79ec490b02 100755 --- a/hack/secret-manager.sh +++ b/hack/secret-manager.sh @@ -31,11 +31,59 @@ if [ -t 0 ] && [ -t 1 ]; then tty_flags=(-it) fi +resolve_path() { + if [[ "$1" = /* ]]; then + echo "$1" + else + echo "$(pwd)/$1" + fi +} + +args=() +file_mount=() +while [[ $# -gt 0 ]]; do + case "$1" in + -f|--from-file) + if [[ -n "${2:-}" ]]; then + host_path="$(resolve_path "$2")" + if [[ -f "$host_path" ]]; then + container_path="/input/$(basename "$host_path")" + file_mount=(-v "$host_path:$container_path:ro,z") + args+=("$1" "$container_path") + else + args+=("$1" "$2") + fi + shift 2 + else + args+=("$1") + shift + fi + ;; + --from-file=*) + file_arg="${1#--from-file=}" + host_path="$(resolve_path "$file_arg")" + if [[ -f "$host_path" ]]; then + container_path="/input/$(basename "$host_path")" + file_mount=(-v "$host_path:$container_path:ro,z") + args+=("--from-file=$container_path") + else + args+=("$1") + fi + shift + ;; + *) + args+=("$1") + shift + ;; + esac +done + if ! "$CONTAINER_ENGINE" image exists "$IMAGE" 2>/dev/null; then "$CONTAINER_ENGINE" pull "$IMAGE" >/dev/null fi exec "$CONTAINER_ENGINE" run --rm "${tty_flags[@]}" \ -v "$GCLOUD_CONFIG_PATH:/gcloud:z" \ + ${file_mount[@]+"${file_mount[@]}"} \ -e CLOUDSDK_CONFIG=/gcloud \ -e GOOGLE_CLOUD_QUOTA_PROJECT=openshift-ci-secrets \ - "$IMAGE" "$@" + "$IMAGE" "${args[@]}"