Skip to content

Commit 5a4f740

Browse files
committed
Remove build docker volumes if OS_BUILD_ENV_CLEAN_BUILD_VOLUME is set.
1 parent a213e8c commit 5a4f740

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

hack/lib/build/environment.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,21 @@ readonly -f os::build::environment::release::workingdir
9999
# (unless OS_BUILD_ENV_LEAVE_CONTAINER is set, in which case it will only stop the container).
100100
function os::build::environment::cleanup() {
101101
local container=$1
102+
local volume=$2
103+
local tmp_volume=$3
102104
os::log::debug "Stopping container ${container}"
103105
docker stop --time=0 "${container}" > /dev/null || true
104106
if [[ -z "${OS_BUILD_ENV_LEAVE_CONTAINER:-}" ]]; then
105107
os::log::debug "Removing container ${container}"
106108
docker rm "${container}" > /dev/null
107109

108110
if [[ -z "${OS_BUILD_ENV_REUSE_TMP_VOLUME:-}" ]]; then
109-
os::log::debug "Removing tmp volume"
110-
os::build::environment::remove_volume "${OS_BUILD_ENV_TMP_VOLUME}"
111+
os::log::debug "Removing tmp build volume"
112+
os::build::environment::remove_volume "${tmp_volume}"
113+
fi
114+
if [[ -n "${OS_BUILD_ENV_CLEAN_BUILD_VOLUME:-}" ]]; then
115+
os::log::debug "Removing build volume"
116+
os::build::environment::remove_volume "${volume}"
111117
fi
112118
fi
113119
}
@@ -257,7 +263,7 @@ function os::build::environment::run() {
257263

258264
local container
259265
container="$( os::build::environment::create "$@" )"
260-
trap "os::build::environment::cleanup ${container}" EXIT
266+
trap "os::build::environment::cleanup ${container} ${volume} ${tmp_volume}" EXIT
261267

262268
os::log::debug "Using container ${container}"
263269

0 commit comments

Comments
 (0)