Save docmachine image in local cache #2

Closed
opened 2023-04-01 14:33:25 +00:00 by glenux · 2 comments
Owner

There is no way to avoid having the image being pruned, and image gets downloaded over and over again.

To avoid unnecessary pull, we should follow the strategy below:

if docmachine image does not exists in local registry
  if docmachine image cache exists
    load docmachine from cache
  else
    pull the docmachine image from remote registry
    save the downloaded image in cache
  endif
endif
run docmachine

Ex: ~/.cache/docmachine/docmachine.TAG.tar.bz2

There is no way to avoid having the image being pruned, and image gets downloaded over and over again. To avoid unnecessary pull, we should follow the strategy below: ``` if docmachine image does not exists in local registry if docmachine image cache exists load docmachine from cache else pull the docmachine image from remote registry save the downloaded image in cache endif endif run docmachine ``` Ex: `~/.cache/docmachine/docmachine.TAG.tar.bz2`
glenux added this to the By Status project 2023-10-18 21:03:34 +00:00
Author
Owner

Contexte/etat actuel dans le code (HEAD 8da1820):

  • La logique de cache cote docmachine build est dans src/build/run.cr#_pull_image.
  • Le cache est un fichier unique ~/.cache/docmachine/image.tar (ou $XDG_CACHE_HOME/docmachine/image.tar).
  • En pratique le cache n'est jamais utilise car enable_cache est desactive par defaut et non exposé dans la CLI (voir issue #21).

Pistes complementaires (non couvertes ici):

  • cacher par image/tag (eviter un seul image.tar partage), + metadata/digest pour verifier que l'archive correspond bien a l'image demandee.
  • ajouter un mode offline / docker run --pull=never pour garantir qu'un run ne telecharge jamais si on veut forcer le cache.

Je propose d'ouvrir des tickets dedies pour ces points (sauf si on prefere enrichir celui-ci).

Contexte/etat actuel dans le code (HEAD 8da1820): - La logique de cache cote `docmachine build` est dans `src/build/run.cr#_pull_image`. - Le cache est un fichier unique `~/.cache/docmachine/image.tar` (ou `$XDG_CACHE_HOME/docmachine/image.tar`). - En pratique le cache n'est jamais utilise car `enable_cache` est desactive par defaut et non exposé dans la CLI (voir issue #21). Pistes complementaires (non couvertes ici): - cacher par image/tag (eviter un seul `image.tar` partage), + metadata/digest pour verifier que l'archive correspond bien a l'image demandee. - ajouter un mode offline / `docker run --pull=never` pour garantir qu'un run ne telecharge jamais si on veut forcer le cache. Je propose d'ouvrir des tickets dedies pour ces points (sauf si on prefere enrichir celui-ci).
Author
Owner

Implemented minimal fix to skip cache/pull when the image already exists locally.

Details:

  • Added image_exists?(image_tag) to the container engine interface and implemented it for Docker (docker image inspect) and Podman (podman image exists).
  • Build runner now logs a decision summary (local image presence + cache enabled + cache file presence when cache is enabled).
  • _pull_image short-circuits when the image is already present locally.
  • Added spec coverage for the local-image short-circuit and updated stubs accordingly.

Files touched (core):

  • src/build/run.cr
  • src/container/abstract_container_engine.cr
  • src/container/docker_engine.cr
  • src/container/podman_engine.cr
  • spec/build/run_spec.cr
  • spec/support/container_stub_engine.cr
Implemented minimal fix to skip cache/pull when the image already exists locally. Details: - Added `image_exists?(image_tag)` to the container engine interface and implemented it for Docker (`docker image inspect`) and Podman (`podman image exists`). - Build runner now logs a decision summary (local image presence + cache enabled + cache file presence when cache is enabled). - `_pull_image` short-circuits when the image is already present locally. - Added spec coverage for the local-image short-circuit and updated stubs accordingly. Files touched (core): - `src/build/run.cr` - `src/container/abstract_container_engine.cr` - `src/container/docker_engine.cr` - `src/container/podman_engine.cr` - `spec/build/run_spec.cr` - `spec/support/container_stub_engine.cr`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
glenux/docmachine-cli#2
No description provided.