Initial impl download; adjust example.sh to show multiple files
This commit is contained in:
parent
804696ccb9
commit
5a23f8ba31
@ -52,6 +52,30 @@ function main {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function download {
|
||||||
|
local image="$1" files=("${@:2}") registry repo tag token labels
|
||||||
|
{ read -r registry; read -r repo; read -r tag; } <<< "$(image_parts "$1")"
|
||||||
|
token="$(get_token "$registry" "$repo")"
|
||||||
|
labels="$(list_json "$registry" "$repo" "$tag" "$token")"
|
||||||
|
# safely convert bash array of args into json array
|
||||||
|
files="$(for i in "${files[@]}"; do jq -n --arg f "$i" '$f'; done | jq -s '.')"
|
||||||
|
# test if all of the requested files are present in manifest labels
|
||||||
|
if ! jq -e --argjson f "$files" 'keys|contains($f)' <<< "$labels" > /dev/null ; then
|
||||||
|
echo " ** These files are not avilable to download from $image:"
|
||||||
|
echo "$(jq -r --argjson f "$files" '$f - keys | .[]' <<< "$labels" | sed 's_^_ _')"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# filter labels to just the ones that match files
|
||||||
|
labels="$(jq --argjson f "$files" 'with_entries(select(. as $e | $f | index($e.key)))' <<< "$labels")"
|
||||||
|
local shas="$(jq -r 'to_entries | map({(.value): {(.key): null}}) | reduce .[] as $i {{}; . * $i) | to_entries | map({key:.key, value:(.value|keys)}' <<< "$labels")"
|
||||||
|
echo "$shas"
|
||||||
|
#local a="$(xargs -L1 -I {} bash -c \
|
||||||
|
#'curl -s -L -H "Authorization: Bearer $1" "$2/$3" | tar -xz -O "$3"' \
|
||||||
|
#_ "$token" "https://$registry/v2/$repo/blobs/" {} \
|
||||||
|
#<<< "$shas")"
|
||||||
|
echo "Done!"
|
||||||
|
}
|
||||||
|
|
||||||
function list {
|
function list {
|
||||||
local registry repo tag token list
|
local registry repo tag token list
|
||||||
{ read -r registry; read -r repo; read -r tag; } <<< "$(image_parts "$1")"
|
{ read -r registry; read -r repo; read -r tag; } <<< "$(image_parts "$1")"
|
||||||
@ -112,7 +136,6 @@ function get_token {
|
|||||||
*.dkr.ecr.*.amazonaws.com)
|
*.dkr.ecr.*.amazonaws.com)
|
||||||
aws ecr get-authorization-token | jq -r '.authorizationData[0].authorizationToken'
|
aws ecr get-authorization-token | jq -r '.authorizationData[0].authorizationToken'
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,23 +1,26 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
pushd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null
|
pushd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null
|
||||||
|
|
||||||
# Build example image
|
# Build example image
|
||||||
echo "Rebuilding docker image infogulch/artifact-test"
|
>&2 printf "Rebuilding docker image infogulch/artifact-test\n"
|
||||||
printf 'FROM busybox \n RUN mkdir app && echo "Hello World!" > /app/testfile.txt' | docker build -t infogulch/artifact-test -
|
printf 'FROM busybox \n RUN mkdir app && echo "Test data" > /app/testfile.txt && echo "Hello world!" > /hello.txt' | docker build -t infogulch/artifact-test -
|
||||||
|
|
||||||
# Execute docker artifact to add a label that identifies /app/testfile.txt
|
>&2 printf "\nLabeling /app/testfile.txt and /hello.txt in infogulch/artifact-test\n"
|
||||||
echo ""
|
../docker-artifact.sh artifact label infogulch/artifact-test /app/testfile.txt /hello.txt
|
||||||
echo "Labeling /app/testfile.txt in infogulch/artifact-test"
|
|
||||||
../docker-artifact.sh artifact label infogulch/artifact-test /app/testfile.txt
|
|
||||||
|
|
||||||
echo ""
|
>&2 printf "\nPushing image infogulch/artifact-test\n"
|
||||||
echo "Pushing image infogulch/artifact-test"
|
|
||||||
docker push infogulch/artifact-test
|
docker push infogulch/artifact-test
|
||||||
|
|
||||||
echo ""
|
>&2 printf "\nListing files in infogulch/artifact-test\n"
|
||||||
echo "Listing files in infogulch/artifact-test"
|
|
||||||
../docker-artifact.sh artifact ls infogulch/artifact-test
|
../docker-artifact.sh artifact ls infogulch/artifact-test
|
||||||
|
|
||||||
|
>&2 printf "\nAttempt to download missing file /oops.txt\n"
|
||||||
|
! ../docker-artifact.sh artifact download infogulch/artifact-test /oops.txt
|
||||||
|
|
||||||
|
>&2 printf "\nDownloading /hello.txt and /app/testfile.txt\n"
|
||||||
|
../docker-artifact.sh artifact download infogulch/artifact-test /hello.txt /app/testfile.txt
|
||||||
|
|
||||||
popd &> /dev/null
|
popd &> /dev/null
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user