#!/usr/bin/env sh set -eu [ -e /opt/resource/common ] && cd /opt/resource . ./common image_repository="$(jq -r .params.image < "$INPUT_FILE")" if [ -z "$image_repository" ]; then fail "must specify param 'image'" fi image_refs_file="$(mktemp -t)" oci_dir="$(mktemp -d)" cd "$oci_dir" tar xf "$1/$image_repository" cd - 1>&2 2>/dev/null crane push "$oci_dir" "$REPOSITORY:$TAG" --image-refs="$image_refs_file" additional_tags="$(jq -r '.params.additional_tags // ""' < "$INPUT_FILE")" if [ -n "$additional_tags" ] && [ "$additional_tags" != 'null' ]; then if ! [ -r "$1/$additional_tags" ]; then fail "cannot open file $1/$additional_tags" fi tr '[:space:]' '\n' < "$1/$additional_tags" | grep -v '^$' | while read -r tag; do crane tag "$REPOSITORY:@$(sed 's/^[^@]*@//' < "$image_refs_file")" "$tag" done fi filter='{ "version": {"digest": $version} } | tostring' jq -r --null-input --arg version "$(sed 's/^[^@]*@//' < "$image_refs_file")" "$filter" rm -r "$oci_dir" rm "$image_refs_file" rm "$INPUT_FILE"