OpenMediaVault-Plugin-Developers / openmediavault-compose

openmediavault plugin for docker-compose
18 stars 6 forks source link

Pruning does not work in scheduled tasks #27

Closed lldsolitude closed 7 months ago

lldsolitude commented 7 months ago

Hi,

I set up a scheduled task in compose plugin with both update and prune enabled, but after the scheduled task executed, the images were updated but dangling images were not pruned as expected. I tried setting up a task with only prune selected but an error popped up saying "You must select at least one action type".

As a previous issue pointed out I could just set up a general scheduled task to prune dangling images, but now that the function is already in the plugin it would make sense for it to work?

I'm running omv 7.0.5 with openmediavault-compose 7.1.3

Thanks!

ryecoaaron commented 7 months ago

now that the function is already in the plugin it would make sense for it to work?

Of course. I will look at it.

ryecoaaron commented 7 months ago

I have fixed the issue where you can't select only prune for a job. https://github.com/OpenMediaVault-Plugin-Developers/openmediavault-compose/commit/d088bfd65791a289fcd2af729a810f6e050e25b7

I set up a scheduled task in compose plugin with both update and prune enabled, but after the scheduled task executed, the images were updated but dangling images were not pruned as expected.

The plugin is just running "docker image prune -f". If that doesn't prune an image, docker doesn't think it can be pruned. Can you post the output of the following:

cat /etc/cron.d/omv-compose-prune

lldsolitude commented 7 months ago

After checking cat /etc/cron.d/omv-compose-prune I think I know what the problem is. I was expecting the prune to execute after the update is finished, but it looks like it's executed as soon as the update is invoked but not finished, so of course nothing gets pruned. Is this the intended behavior?

cat /etc/cron.d/omv-compose-prune

# This file is auto-generated by openmediavault (https://www.openmediavault.org)
# WARNING: Do not edit this file, your changes will get lost.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user    command
0 6 * * 5 root docker image prune -f >/dev/null 2>&1
ryecoaaron commented 7 months ago

Is this the intended behavior?

Kind of. Even though the update script gets kicked off at the same time as the backup script, the update script waits for the backup script to complete. When I added the prune, I figured it would be scheduled by itself but it doesn't have to be. It just means there might be an extra image around that would be pruned the next time it runs. I would have to write a wrapper script around the docker prune command to wait for the update script to finish.

ryecoaaron commented 7 months ago

7.1.4 is in the repo. I added a wrapper script for the prune to wait for the update script. https://github.com/OpenMediaVault-Plugin-Developers/openmediavault-compose/commit/701e9bced2ca7b6a09d332ed0630fc5180fd79a8