netbox-docker-agent icon indicating copy to clipboard operation
netbox-docker-agent copied to clipboard

:sparkles: Add local image/registry index

Open linkdd opened this issue 1 year ago • 1 comments

Decision Record

The Netbox models a relationship that the local Docker daemon is not aware of:

erDiagram
    IMAGE ||--|| REGISTRY : "pull using"

When the agent is performing a "refresh", it has no way of knowing which registry was associated to the images it is recreating.

The PR #131 introduces one way of inferring the relationship, if the registry is named after the image (aka: they both have the same name). Otherwise, it fallbacks to "dockerhub".

However, this puts a constraint on the "Registry" entity in Netbox that is not modelled in said Netbox.

One easy solution is to duplicate that relationship on the agent, such that it is able to restore it when performing the "refresh".

Changes

  • [x] :sparkles: Create $DATAPATH/image-registry.index.json file at startup, containing {}
  • [x] :sparkles: When an image is successfully pulled, add the pair ${img.name}+":"+${img.version} = ${img.registry.id} to the index
  • [x] :sparkles: When an image is deleted, remove it from the index
  • [x] :sparkles: When a refresh is done, fetch the registry ID from the index, if not found fallback to the behavior introduced in #131
  • [x] :bookmark: v0.35.0

linkdd avatar Oct 01 '24 14:10 linkdd

I have looked at the flow and here I would change :

  • Initialize Image/Registry Index as subflow makes no sense as it will be used once
  • It is never good to work on file directly. The best approach is to work on a global var et every Xsecs to flush the global into the file. Look at the save config in the INIT flow
  • in the "add host" registries are not used. should be the same as refresh
  • in the UI would be good to the registries with the associated image

lvenier avatar Oct 02 '24 11:10 lvenier

this one is implemented in 1.0.0

lvenier avatar Nov 06 '24 11:11 lvenier