Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Might crash on incorrect image:tag format #8

Open
JesseChisholm opened this issue Jun 11, 2020 · 1 comment
Open

Might crash on incorrect image:tag format #8

JesseChisholm opened this issue Jun 11, 2020 · 1 comment

Comments

@JesseChisholm
Copy link

JesseChisholm commented Jun 11, 2020

Out of curiosity, I ran this:

mapfile -t images < <(docker images | awk '{print $1 ":" $2}')
for I in "${images[@]}"; do
    echo "--- $I ---"
    python dimgx.py "$I"
done

It crashed on the REPOSITORY:TAG line.
It crashed on the <none>:<none> line.

Changed my loop to:

for I in "${images[@]}"; do
  if [[ "$I" != "REPOSITORY"* ]] && [[ "$I" != "<none>"* ]]; then
    echo "--- $I ---"
    python dimgx.py "$I"
  fi
done

The crash looked like this:

$ python dimgx.py '<none>:<none>'
Traceback (most recent call last):
  File "dimgx.py", line 549, in <module>
    _main()
  File "D:\Documents\Mine\dimgx\_dimgx\cmd.py", line 268, in main
    layers_dict = inspectlayers(dc, args.image)
  File "D:\Documents\Mine\dimgx\dimgx.py", line 361, in inspectlayers
    raise RuntimeError('{} not found among the layers retreieved for that image'.format(image_spec))
RuntimeError: <none>:<none> not found among the layers retreieved for that image

I realize that the two tests are bad image names, and thus outside the defined behavior of your excellent tool. Just thought you'd want to know about this.

@posita
Copy link
Owner

posita commented Jun 22, 2020

Thanks! I suppose the RuntimeError isn't the greatest UX for a missing image. I'm actually surprised dimgx is still useful to anyone, though! Also, it's been literally years since I touched docker directly, so don't trust my memory, but I think you can pass an ID instead of a repo:tag pair. So maybe something like the following might work?

(  # do this in a subshell, because we're mucking with IFS and we don't want to pollute our current environment
  IFS=$'\n'  # only split variables on newlines
  for line in $( docker images --format '{{.ID}}:{{.Repository}} {{.Tag}}' ) ; do
    image_id="${line%%:*}"
    image_repo_tag="${line#*:}"
    echo "--- ${image_repo_tag} (${image_id}) ---"
    python dimgx.py "${image_id}"  # assuming I got everything else right, this might work
  done
)

If you don't need to print out the repo or tag before calling dimgx.py, you could probably just do:

for image_id in $( docker images --format '{{.ID}}' ) ; do
  echo "--- ${image_id} ---"
  python dimgx.py "${image_id}"
done

Let me know if any of that helps. I'm curious….

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants