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

fix: pass global args to all crane invocations #709

Merged
Merged
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
21 changes: 14 additions & 7 deletions oci/private/push.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ readonly TAGS_FILE="{{tags}}"
readonly FIXED_ARGS=({{fixed_args}})
readonly REPOSITORY_FILE="{{repository_file}}"

VERBOSE=""

REPOSITORY=""
if [ -f $REPOSITORY_FILE ] ; then
REPOSITORY=$(tr -d '\n' < "$REPOSITORY_FILE")
Expand All @@ -22,12 +20,21 @@ if [[ ${#ALL_ARGS[@]} -gt 0 ]]; then
fi

TAGS=()

# global crane flags to be passed with every crane invocation
GLOBAL_FLAGS=()

# this will hold args specific to `crane push``
ARGS=()

while (( $# > 0 )); do
case $1 in
(-v|--verbose)
VERBOSE="--verbose"
(--allow-nondistributable-artifacts|--insecure|-v|--verbose)
GLOBAL_FLAGS+=( "$1" )
shift;;
(--platform)
GLOBAL_FLAGS+=( "--platform" "$2" )
shift
shift;;
(-t|--tag)
TAGS+=( "$2" )
Expand All @@ -52,13 +59,13 @@ done
DIGEST=$("${JQ}" -r '.manifests[0].digest' "${IMAGE_DIR}/index.json")

REFS=$(mktemp)
"${CRANE}" push ${VERBOSE} "${IMAGE_DIR}" "${REPOSITORY}@${DIGEST}" "${ARGS[@]+"${ARGS[@]}"}" --image-refs "${REFS}"
ahans marked this conversation as resolved.
Show resolved Hide resolved
"${CRANE}" push "${GLOBAL_FLAGS[@]+"${GLOBAL_FLAGS[@]}"}" "${IMAGE_DIR}" "${REPOSITORY}@${DIGEST}" "${ARGS[@]+"${ARGS[@]}"}" --image-refs "${REFS}"

for tag in "${TAGS[@]+"${TAGS[@]}"}"
do
"${CRANE}" tag ${VERBOSE} $(cat "${REFS}") "${tag}"
"${CRANE}" tag "${GLOBAL_FLAGS[@]+"${GLOBAL_FLAGS[@]}"}" $(cat "${REFS}") "${tag}"
done

if [[ -e "${TAGS_FILE:-}" ]]; then
cat "${TAGS_FILE}" | xargs -r -n1 "${CRANE}" tag ${VERBOSE} $(cat "${REFS}")
cat "${TAGS_FILE}" | xargs -r -n1 "${CRANE}" tag "${GLOBAL_FLAGS[@]+"${GLOBAL_FLAGS[@]}"}" $(cat "${REFS}")
fi
Loading