diff --git a/board/common/rootfs/usr/sbin/container b/board/common/rootfs/usr/sbin/container index 1791e935..4bc99d9a 100755 --- a/board/common/rootfs/usr/sbin/container +++ b/board/common/rootfs/usr/sbin/container @@ -24,6 +24,7 @@ all="" env="" port="" force=${force:-} +reset_volumes= # Variable shared across subshells export meta_sha="" @@ -897,6 +898,9 @@ while [ "$1" != "" ]; do shift restart=$1 ;; + -R | --reset-volumes) + reset_volumes=true + ;; -s | --simple) simple=true ;; @@ -1251,6 +1255,20 @@ case $cmd in container stop "$name" echo "done" + # If --reset-volumes requested, delete named volumes so they re-initialize from new image + if [ -n "$reset_volumes" ]; then + printf ">> Resetting named volumes (all configuration will be lost): " + grep -oE -- '-v [^ ]+' "$script" | awk '{print $2}' | cut -d: -f1 | \ + while read -r vol_name; do + if podman volume exists "$vol_name" 2>/dev/null; then + printf "%s " "$vol_name" + log "Removing volume $vol_name" + podman volume rm -f "$vol_name" >/dev/null || true + fi + done + echo "done" + fi + # Set force flag to ensure fresh pull/fetch of image export force="-f" diff --git a/src/klish-plugin-infix/xml/containers.xml b/src/klish-plugin-infix/xml/containers.xml index 4360e1b5..8691a75b 100644 --- a/src/klish-plugin-infix/xml/containers.xml +++ b/src/klish-plugin-infix/xml/containers.xml @@ -179,8 +179,14 @@ + + + - doas container upgrade $KLISH_PARAM_name + if env | grep -q 'reset-volumes' >/dev/null; then + opt="-R" + fi + doas container $opt upgrade $KLISH_PARAM_name