Skip to content

Commit

Permalink
fix: pass global crane flags to all invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
ahans committed Oct 17, 2024
1 parent a002daf commit 465e2c2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions oci/private/push.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,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 +61,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}"
"${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

0 comments on commit 465e2c2

Please sign in to comment.