Automatic local image expiration (how to set expires_at)

TLDR: How to set expires_at field for images created by publishing container?

I am trying to use LXD for testing purposes. My framework generates unique alias for image from source files and generates image for that alias. On next run, unless source files have not changed for container, the framework can reuse image and that makes tests execution much more faster. The problem with this approach I have is that it lefts unused local images. In general I need same expiration like there is for cached images. Initial idea was to convince LXD that that local image is cached one. The problem is how to do it without exporting it, modifying metadata and importing it. I also noticed that there another option that is available for not cached images and that is explicit expiration date. I can bump that date every time I use image so this can be easy enough replacement and LXD would manage my containers removal for me. Only problem is that I don’t see a way how to set that field. Modifying image using lxc edit does not seem to do the trick or I am just not sure what key am I suppose to use. Can you please help me with this? How can I set explicit expiration date?

Possibly this can be also feature request. Could it be possible to have option for image to be removed automatically when it is not used for some time even when it is local one? Something like per-image settable expiration (something like there is for snapshots).

Right now the expiry field is read-only, I don’t think there’s a particularly good reason for that so we could make it writable at which point lxc image edit would let you change it.

Feel free to file a feature request at https://github.com/lxc/lxd/issues and we may get around it soon or try to have someone from the community contribute it.

Thank you for quick response. I created issue https://github.com/lxc/lxd/issues/6220 and I hope somebody is going to get around to it.

I am going to use cron job for time being.

1 Like