Skip to content

Commit

Permalink
introduce dkr-images command
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-dartigues committed Dec 29, 2022
1 parent d28da2f commit 396c0f8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/docker/packaging
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ DOCKER_ARCHIVE=$(
head -1
)

mkdir -p "${BOSH_INSTALL_TARGET:?}/bin"
install -Dv "${BOSH_COMPILE_TARGET:?}/docker/dkr-images" "${BOSH_INSTALL_TARGET:?}/bin/dkr-images"
tar -C "${BOSH_INSTALL_TARGET}/bin" --strip-components 1 -xvf "${DOCKER_ARCHIVE}"
find "${BOSH_INSTALL_TARGET}/bin" -type f -exec chmod -c +x {} +
1 change: 1 addition & 0 deletions packages/docker/spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ name: docker
dependencies: []
files:
- docker.tgz
- docker/*
44 changes: 44 additions & 0 deletions src/docker/dkr-images
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

EXCLUDE=
k=
while getopts s:x OPT
do
case "$OPT" in
s)
case "$OPTARG" in
[0-9]) k=$OPTARG;;
[Ii][Dd]) k=1;;
[Ss]|[Ss]ize) k=2h;;
[CcDd]|[Cc]rea*|[Dd]ate) k=3;;
[Rr]epo*|[Ii]mage*|[Nn]ame) k=4;;
*)
printf 'Unknown sort key: "%s"\n' "$OPTARG"
return 64
esac
;;
x) EXCLUDE=1;;
?)
printf 'Usage: %s [-s sort-key]\n' "$0"
return 64
esac
done
shift $((OPTIND - 1))

FILTER=""
for arg in "$@"
do FILTER="${FILTER}${FILTER:+|}${arg}"
done

if [ -z "${FILTER##*/*}" ]
then FILTER="$(echo "$FILTER" | sed 's#/#\\&#g')"
fi

{
printf '#ID Size CreatedAt Repository:Tag\n'
docker image ls --format '{{ json . }}' |
jq -r '[.ID, .Size, .CreatedAt[0:10]+"T"+.CreatedAt[11:16], .Repository + ":" + .Tag] | join(" ")' |
LC_ALL=C sort -k "${k:-2h}"
} |
awk "${FILTER:+\$NF ${EXCLUDE:+!}~ /${FILTER}/}{print}" |
column -t

0 comments on commit 396c0f8

Please sign in to comment.