From 0cad470c5a3579975dbfcfe77dc351b5fa564d59 Mon Sep 17 00:00:00 2001 From: Erik Dannenberg Date: Mon, 18 Feb 2019 13:20:04 +0100 Subject: [PATCH] Also remove unused volumes during clean -p/postbuild. ty @r7l for the suggestion --- cmd/argbash/clean.sh | 2 +- cmd/clean.sh | 2 ++ engine/docker.sh | 7 +++++-- kubler.conf | 7 ++++++- lib/core.sh | 2 ++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/argbash/clean.sh b/cmd/argbash/clean.sh index e64ac19d..64c985d1 100755 --- a/cmd/argbash/clean.sh +++ b/cmd/argbash/clean.sh @@ -24,7 +24,7 @@ print_help () { printf 'Usage: %s clean [-b|--build-artifacts] [-p|--prune-dangling-images] [-i|--image-ns ] [-I|--all-images] [-N|--nuke-from-orbit] [-w|--working-dir ]\n' "${_KUBLER_BIN}" printf "\t%s\n" "-b,--build-artifacts: Delete rootfs.tar, Dockerfile and PACKAGES.md files, this is the default and can be omitted" - printf "\t%s\n" "-p,--prune-dangling-images: Run docker image prune" + printf "\t%s\n" "-p,--prune-dangling-images: Run docker image/volume prune" printf "\t%s\n" "-i,--image-ns: Delete all Docker images for given namespace (repeatable)" printf "\t%s\n" "-I,--all-images: Delete all Kubler related images for all namespaces, except stage3 base images and portage" printf "\t%s\n" "-N,--nuke-from-orbit: Same as activating all of the above options, also deletes stage3 base images and portage" diff --git a/cmd/clean.sh b/cmd/clean.sh index 766ac994..3c3e0718 100644 --- a/cmd/clean.sh +++ b/cmd/clean.sh @@ -53,6 +53,8 @@ function main() { source_build_engine 'docker' _status_msg="exec docker image prune" pwrap "${DOCKER}" image prune -f || die + _status_msg="exec docker volume prune" + pwrap "${DOCKER}" volume prune -f || die msg_ok 'done.' fi diff --git a/engine/docker.sh b/engine/docker.sh index e35f5bff..7aad0ccf 100644 --- a/engine/docker.sh +++ b/engine/docker.sh @@ -246,8 +246,11 @@ function build_image() { _status_msg="tag image ${image_id}:latest" pwrap 'nolog' "${DOCKER}" tag "${image_id}:${IMAGE_TAG}" "${image_id}:latest" || die "${_status_msg}" - _status_msg="remove untagged images" - pwrap "${DOCKER}" image prune -f + [[ "${KUBLER_POSTBUILD_IMAGE_PRUNE}" == 'true' ]] \ + && _status_msg="remove untagged images" && pwrap "${DOCKER}" image prune -f + + [[ "${KUBLER_POSTBUILD_VOLUME_PRUNE}" == 'true' ]] \ + && _status_msg="remove unused volumes" && pwrap "${DOCKER}" volume prune -f add_documentation_header "${image_id}" "${image_type}" || die "Failed to generate PACKAGES.md for ${image_id}" local has_tests done_text diff --git a/kubler.conf b/kubler.conf index 20d512aa..ed846572 100644 --- a/kubler.conf +++ b/kubler.conf @@ -15,7 +15,8 @@ # Gentoo's binary package cache location #KUBLER_PACKAGES_DIR="${KUBLER_DATA_DIR}/packages" -# Lock --working-dir to given path. If you enable this use an absolute path or ensure KUBLER_DATA_DIR above is set. +# Lock --working-dir to given path. If you enable this, it's not set per default, use an absolute path or ensure +# that KUBLER_DATA_DIR above is set. #KUBLER_WORKING_DIR="${KUBLER_DATA_DIR}" # Ouput related config @@ -34,6 +35,10 @@ #KUBLER_DISABLE_KUBLER_NS='false' # Effectively always enables -s for the build command #KUBLER_DISABLE_GPG='false' +# Remove untagged/dangling images after each build +#KUBLER_POSTBUILD_IMAGE_PRUNE='true' +# Remove unused docker volumes after each build +#KUBLER_POSTBUILD_VOLUME_PRUNE='true' # Portage snapshot date that is used to bootstrap the portage container, 'latest' is highly recommended #PORTAGE_DATE='latest' diff --git a/lib/core.sh b/lib/core.sh index 77ef89eb..ed292bf8 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -28,6 +28,8 @@ KUBLER_DOWNLOAD_DIR="${KUBLER_DOWNLOAD_DIR:-${KUBLER_DATA_DIR}/downloads}" KUBLER_DISTFILES_DIR="${KUBLER_DISTFILES_DIR:-${KUBLER_DATA_DIR}/distfiles}" KUBLER_PACKAGES_DIR="${KUBLER_PACKAGES_DIR:-${KUBLER_DATA_DIR}/packages}" KUBLER_DEPGRAPH_IMAGE="${KUBLER_DEPGRAPH_IMAGE:-kubler/graph-easy}" +KUBLER_POSTBUILD_IMAGE_PRUNE="${KUBLER_POSTBUILD_IMAGE_PRUNE:-true}" +KUBLER_POSTBUILD_VOLUME_PRUNE="${KUBLER_POSTBUILD_VOLUME_PRUNE:-true}" AUTHOR="${AUTHOR:-Erik Dannenberg }"