SaaShup / netbox-docker-agent

Agent for Netbox Docker Plugin
https://saashup.com
BSD 3-Clause "New" or "Revised" License
30 stars 1 forks source link

:bug: Determine if image was pulled by checking if digest is returned #111

Closed linkdd closed 1 week ago

linkdd commented 2 weeks ago

Decision Record

After pulling an image, the stdout stream contains a sequence of JSON records, one per line. For example:

{"status": "Pulling ..."}
{"status": "Process layer ..."}
{"status": "Digest: sha256:..."}

Or when the image already exists:

{"status": "Pulling ..."}
{"status": "... already exists"}
{"status": "Digest: sha256:..."}

Or when failed:

{"message": "..."}

As you can see, whenever the image exists locally (because we just pulled it, or it was pulled long before), one of the record contains the image's digest.

Therefore, by splitting stdout by newlines (\n), parsing each line as a JSON record, and checking if one of the record contains a digest, we should be able to determine with accuracy if an image has been pulled or not. Way more accurately than checking if the number of characters in stdout is bellow or above 512.

Changes