Skip to content

Commit

Permalink
revert accidental push deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzojive committed Oct 11, 2024
1 parent 399a62e commit e117054
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions oci/private/push.sh.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
set -o pipefail -o errexit -o nounset

readonly CRANE="{{crane_path}}"
readonly JQ="{{jq_path}}"
readonly IMAGE_DIR="{{image_dir}}"
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")
fi

# set $@ to be FIXED_ARGS+$@
ALL_ARGS=(${FIXED_ARGS[@]+"${FIXED_ARGS[@]}"} $@)
if [[ ${#ALL_ARGS[@]} -gt 0 ]]; then
set -- ${ALL_ARGS[@]}
fi

TAGS=()
ARGS=()

while (( $# > 0 )); do
case $1 in
(-v|--verbose)
VERBOSE="--verbose"
shift;;
(-t|--tag)
TAGS+=( "$2" )
shift
shift;;
(--tag=*)
TAGS+=( "${1#--tag=}" )
shift;;
(-r|--repository)
REPOSITORY="$2"
shift
shift;;
(--repository=*)
REPOSITORY="${1#--repository=}"
shift;;
(*)
ARGS+=( "$1" )
shift;;
esac
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}"

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

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

0 comments on commit e117054

Please sign in to comment.