Skip to content

Commit

Permalink
Fix duplicates showing in list output
Browse files Browse the repository at this point in the history
This removes an additional step when listing info about containers and
images. Until now we were filtering output of podman ps to get names of
containers that came from toolbox and then we got info about them. But
the lack of regex support in podman caused duplicates showing when there
was a "." present in the name of container. So this removes this step
and simply gets all the data in the first step. This is possible thanks
to the format flag in 'podman ps' that allows multiple columns to be
requested.
  • Loading branch information
HarryMichal committed Aug 1, 2019
1 parent 049bb92 commit dd9e175
Showing 1 changed file with 32 additions and 74 deletions.
106 changes: 32 additions & 74 deletions toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -507,29 +507,6 @@ image_reference_has_domain()
)


images_get_details()
(
images="$1"

if ! echo "$images" | while read -r image; do
[ "$image" = "" ] 2>&3 && continue

if ! $prefix_sudo podman images \
--format "{{.ID}} {{.Repository}}:{{.Tag}} {{.Created}}" \
--noheading \
"$image" 2>&3; then
echo "$base_toolbox_command: failed to get details for image $image" >&2
return 1
fi
echo
done; then
return 1
fi

return 0
)


is_etc_profile_d_toolbox_a_bind_mount()
{
container="$1"
Expand All @@ -541,29 +518,6 @@ is_etc_profile_d_toolbox_a_bind_mount()
}


list_container_names()
(
if ! containers_old=$($prefix_sudo podman ps \
--all \
--filter "label=com.redhat.component=fedora-toolbox" \
--format "{{.Names}}" 2>&3); then
echo "$base_toolbox_command: failed to list containers with com.redhat.component=fedora-toolbox" >&2
return 1
fi

if ! containers=$($prefix_sudo podman ps \
--all \
--filter "label=com.github.debarshiray.toolbox=true" \
--format "{{.Names}}" 2>&3); then
echo "$base_toolbox_command: failed to list containers with com.github.debarshiray.toolbox=true" >&2
return 1
fi

printf "%s\n%s\n" "$containers_old" "$containers" | sort 2>&3 | uniq 2>&3
return 0
)


pull_base_toolbox_image()
(
domain=""
Expand Down Expand Up @@ -1189,31 +1143,37 @@ run()
)


list_images()
get_images()
(
output=""

if ! images_old=$($prefix_sudo podman images \
--filter "label=com.redhat.component=fedora-toolbox" \
--format "{{.Repository}}:{{.Tag}}" 2>&3); then
--format "{{.ID}} {{.Repository}}:{{.Tag}} {{.Created}}" 2>&3); then
echo "$base_toolbox_command: failed to list images with com.redhat.component=fedora-toolbox" >&2
return 1
fi

if ! images=$($prefix_sudo podman images \
--filter "label=com.github.debarshiray.toolbox=true" \
--format "{{.Repository}}:{{.Tag}}" 2>&3); then
--format "{{.ID}} {{.Repository}}:{{.Tag}} {{.Created}}" 2>&3); then
echo "$base_toolbox_command: failed to list images with com.github.debarshiray.toolbox=true" >&2
return 1
fi

images=$(printf "%s\n%s\n" "$images_old" "$images" | sort 2>&3 | uniq 2>&3)
if ! details=$(images_get_details "$images"); then
printf "%s\n%s\n" "$images_old" "$images " | sort 2>&3 | uniq 2>&3
return 0
)


list_images()
(
output=""

if ! images_info=$(get_images); then
return 1
fi

if [ "$details" != "" ] 2>&3; then
table_data=$(printf "%s\t%s\t%s\n" "IMAGE ID" "IMAGE NAME" "CREATED"; echo "$details")
if [ "$images_info" != "" ] 2>&3; then
table_data=$(printf "%s\t%s\t%s\n" "IMAGE ID" "IMAGE NAME" "CREATED"; echo "$images_info")
if ! output=$(echo "$table_data" | sed "s/ \{2,\}/\t/g" 2>&3 | column -s "$tab" -t 2>&3); then
echo "$base_toolbox_command: failed to parse list of images" >&2
return 1
Expand All @@ -1230,23 +1190,25 @@ list_images()
)


containers_get_details()
get_containers()
(
containers="$1"

if ! echo "$containers" | while read -r container; do
[ "$container" = "" ] 2>&3 && continue
if ! containers_old=$($prefix_sudo podman ps \
--all \
--filter "label=com.redhat.component=fedora-toolbox" \
--format "{{.ID}} {{.Names}} {{.Created}} {{.Status}} {{.Image}}" 2>&3); then
echo "$base_toolbox_command: failed to list containers with com.redhat.component=fedora-toolbox" >&2
return 1
fi

if ! $prefix_sudo podman ps --all \
--filter "name=$container" \
--format "{{.ID}} {{.Names}} {{.Created}} {{.Status}} {{.Image}}" 2>&3; then
echo "$base_toolbox_command: failed to get details for container $container" >&2
return 1
fi
done; then
if ! containers=$($prefix_sudo podman ps \
--all \
--filter "label=com.github.debarshiray.toolbox=true" \
--format "{{.ID}} {{.Names}} {{.Created}} {{.Status}} {{.Image}}" 2>&3); then
echo "$base_toolbox_command: failed to list containers with com.github.debarshiray.toolbox=true" >&2
return 1
fi

printf "%s\n%s\n" "$containers_old" "$containers" | sort 2>&3 | uniq 2>&3
return 0
)

Expand All @@ -1255,17 +1217,13 @@ list_containers()
(
output=""

if ! containers=$(list_container_names); then
return 1
fi

if ! details=$(containers_get_details "$containers"); then
if ! containers=$(get_containers); then
return 1
fi

if [ "$details" != "" ] 2>&3; then
if [ "$containers" != "" ] 2>&3; then
table_data=$(printf "%s\t%s\t%s\t%s\t%s\n" "CONTAINER ID" "CONTAINER NAME" "CREATED" "STATUS" "IMAGE NAME"
echo "$details")
echo "$containers")
if ! output=$(echo "$table_data" | sed "s/ \{2,\}/\t/g" 2>&3 | column -s "$tab" -t 2>&3); then
echo "$base_toolbox_command: failed to parse list of containers" >&2
return 1
Expand Down

0 comments on commit dd9e175

Please sign in to comment.