Skip to content

Commit

Permalink
Introduce cleanup-after-build.sh to clean all docker volumes generate…
Browse files Browse the repository at this point in the history
…d during rpm building
  • Loading branch information
ingvagabund committed Aug 31, 2017
1 parent 665899f commit cb65468
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hack/cleanup-after-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# This script cleans up resources allocated during image building

source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

# delete all docker volumes used to build images to free space
os::cleanup::buildvolumes
42 changes: 42 additions & 0 deletions hack/lib/util/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,45 @@ function os::util::environment::setup_images_vars() {
export MAX_IMAGES_BULK_IMPORTED_PER_REPOSITORY="${MAX_IMAGES_BULK_IMPORTED_PER_REPOSITORY:-3}"
}
readonly -f os::util::environment::setup_images_vars

# os::cleanup::docker::volumes clens all docker volumes with a given prefix.
#
# Globals:
# None
# Arguments:
# - 1: docker volume prefix
# Returns:
# None
function os::cleanup::docker::volumes() {
local prefix=${1}
local volumes="$(docker volume ls -q | grep ${prefix})"
if [[ "${volumes}" != "" ]]; then
docker volume rm ${volumes}
fi
}
readonly -f os::cleanup::docker::volumes

# os::cleanup::buildvolumes clens all volumes with origin-build prefix
#
# Globals:
# None
# Arguments:
# None
# Returns:
# None
function os::cleanup::buildvolumes() {
local result=1
if os::util::find::system_binary 'imagebuilder' >/dev/null; then
os::log::warning "volumes cleaning not implemented for imagebuilder"
result=0
else
os::log::warning "Unable to locate 'imagebuilder' on PATH, falling back to Docker"
if os::cleanup::docker::volumes "origin-build"; then
result=0
fi
fi

return "${result}"
}

readonly -f os::cleanup::buildvolumes

0 comments on commit cb65468

Please sign in to comment.