Skip to content

Commit 9e329c4

Browse files
committed
Introduce cleanup-after-build.sh to clean all docker volumes generated during rpm building
1 parent 665899f commit 9e329c4

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

hack/cleanup-after-build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# This script cleans up resources allocated during image building
4+
5+
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
6+
7+
# delete all docker volumes used to build images to free space
8+
os::cleanup::buildvolumes

hack/lib/build/environment.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,10 @@ function os::build::environment::run() {
230230
local volume
231231
local tmp_volume
232232

233-
volume="$( os::build::environment::volume_name "origin-build" "${commit}" "${OS_BUILD_ENV_REUSE_VOLUME:-}" )"
234-
tmp_volume="$( os::build::environment::volume_name "origin-build-tmp" "${commit}" "${OS_BUILD_ENV_REUSE_TMP_VOLUME:-}" )"
233+
export OS_BUILD_ENV_VOLUME_PREFIX="origin-build"
234+
235+
volume="$( os::build::environment::volume_name "${OS_BUILD_ENV_VOLUME_PREFIX}" "${commit}" "${OS_BUILD_ENV_REUSE_VOLUME:-}" )"
236+
tmp_volume="$( os::build::environment::volume_name "${OS_BUILD_ENV_VOLUME_PREFIX}-tmp" "${commit}" "${OS_BUILD_ENV_REUSE_TMP_VOLUME:-}" )"
235237

236238
export OS_BUILD_ENV_VOLUME="${volume}"
237239
export OS_BUILD_ENV_TMP_VOLUME="${tmp_volume}"

hack/lib/cleanup.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,44 @@ function os::cleanup::processes() {
339339
done
340340
}
341341
readonly -f os::cleanup::processes
342+
343+
# os::cleanup::docker::volumes clens all docker volumes with a given prefix.
344+
#
345+
# Globals:
346+
# None
347+
# Arguments:
348+
# - 1: docker volume prefix
349+
# Returns:
350+
# None
351+
function os::cleanup::docker::volumes() {
352+
local prefix=${1}
353+
local volumes="$(docker volume ls -q | grep ${prefix})"
354+
echo $volumes
355+
if [[ "${volumes}" != "" ]]; then
356+
docker volume rm ${volumes}
357+
fi
358+
}
359+
readonly -f os::cleanup::docker::volumes
360+
361+
# os::cleanup::buildvolumes clens all volumes with origin-build prefix
362+
#
363+
# Globals:
364+
# None
365+
# Arguments:
366+
# None
367+
# Returns:
368+
# None
369+
function os::cleanup::buildvolumes() {
370+
local result=1
371+
if os::util::find::system_binary 'imagebuilder' >/dev/null; then
372+
os::log::warning "volumes cleaning not implemented for imagebuilder"
373+
result=0
374+
else
375+
os::log::warning "Unable to locate 'imagebuilder' on PATH, falling back to Docker"
376+
if os::cleanup::docker::volumes "origin-build"; then
377+
result=0
378+
fi
379+
fi
380+
381+
return "${result}"
382+
}

0 commit comments

Comments
 (0)