Add more outputs to get step, allow multiple tags for put step.

This commit is contained in:
redxef 2022-08-29 22:03:23 +02:00
parent 9afde6ced0
commit 76fcedd569
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
3 changed files with 31 additions and 4 deletions

View file

@ -9,3 +9,5 @@ filter='[
{"digest": $version} {"digest": $version}
] | tostring' ] | tostring'
jq -r --null-input --arg version "$(crane digest "$REPOSITORY:$TAG")" "$filter" jq -r --null-input --arg version "$(crane digest "$REPOSITORY:$TAG")" "$filter"
rm "$INPUT_FILE"

13
src/in
View file

@ -6,12 +6,23 @@ set -eu
. ./common . ./common
oci_dir="$(mktemp -d)" oci_dir="$(mktemp -d)"
crane pull --format=oci "$REPOSITORY:@$(jq -r .version.digest "$INPUT_FILE")" "$oci_dir" digest="$(jq -r .version.digest < "$INPUT_FILE")"
crane pull --format=oci "$REPOSITORY:@$digest" "$oci_dir"
cd "$oci_dir" cd "$oci_dir"
# write outputs
tar cf "$1/image.tar" ./* tar cf "$1/image.tar" ./*
echo "$REPOSITORY" > "$1/repository"
echo "$digest" > "$1/digest"
cd - 1>&2 2>/dev/null cd - 1>&2 2>/dev/null
# output
filter='{ filter='{
"version": .version "version": .version
} | tostring' } | tostring'
jq -r "$filter" < "$INPUT_FILE" jq -r "$filter" < "$INPUT_FILE"
# cleanup
rm -r "$oci_dir"
rm "$INPUT_FILE"

20
src/out
View file

@ -5,14 +5,28 @@ set -eu
[ -e /opt/resource/common ] && cd /opt/resource [ -e /opt/resource/common ] && cd /opt/resource
. ./common . ./common
IMAGE_REFS_FILE="$(mktemp -t)" image_refs_file="$(mktemp -t)"
oci_dir="$(mktemp -d)" oci_dir="$(mktemp -d)"
cd "$oci_dir" cd "$oci_dir"
tar xf "$1/$(jq -r .params.image < "$INPUT_FILE")" tar xf "$1/$(jq -r .params.image < "$INPUT_FILE")"
cd - 1>&2 2>/dev/null cd - 1>&2 2>/dev/null
crane push "$oci_dir" "$REPOSITORY:$TAG" --image-refs="$IMAGE_REFS_FILE"
crane push "$oci_dir" "$REPOSITORY:$TAG" --image-refs="$image_refs_file"
additional_tags="$(jq .params.additional_tags < "$INPUT_FILE")"
if [ -n "$additional_tags" ]; then
if ! [ -e "$additional_tags" ]; then
fail "additional_tags specified, but doesn't exist"
fi
tr ' \n\t' '\n\n\n' | grep -v '^$' | while read -r tag; do
crane tag "$REPOSITORY:@$(cat "$image_refs_file)" "$tag"
done
fi
filter='{ filter='{
"version": {"digest": $version} "version": {"digest": $version}
} | tostring' } | tostring'
jq -r --null-input --arg version "$(sed 's/^[^@]*@//' < "$IMAGE_REFS_FILE")" "$filter" jq -r --null-input --arg version "$(sed 's/^[^@]*@//' < "$image_refs_file")" "$filter"
rm -r "$oci_dir"
rm "$image_refs_file"
rm "$INPUT_FILE"