Remove build docker volumes if OS_BUILD_ENV_CLEAN_BUILD_VOLUME is set.
@@ -99,6 +99,8 @@ readonly -f os::build::environment::release::workingdir
# (unless OS_BUILD_ENV_LEAVE_CONTAINER is set, in which case it will only stop the container).
function os::build::environment::cleanup() {
local container=$1
+ local volume=$2
+ local tmp_volume=$3
os::log::debug "Stopping container ${container}"
docker stop --time=0 "${container}" > /dev/null || true
if [[ -z "${OS_BUILD_ENV_LEAVE_CONTAINER:-}" ]]; then
@@ -106,8 +108,12 @@ function os::build::environment::cleanup() {
docker rm "${container}" > /dev/null
if [[ -z "${OS_BUILD_ENV_REUSE_TMP_VOLUME:-}" ]]; then
- os::log::debug "Removing tmp volume"
- os::build::environment::remove_volume "${OS_BUILD_ENV_TMP_VOLUME}"
+ os::log::debug "Removing tmp build volume"
+ os::build::environment::remove_volume "${tmp_volume}"
+ fi
+ if [[ -n "${OS_BUILD_ENV_CLEAN_BUILD_VOLUME:-}" ]]; then
+ os::log::debug "Removing build volume"
+ os::build::environment::remove_volume "${volume}"
fi
fi
}
@@ -257,7 +263,7 @@ function os::build::environment::run() {
local container
container="$( os::build::environment::create "$@" )"
- trap "os::build::environment::cleanup ${container}" EXIT
+ trap "os::build::environment::cleanup ${container} ${volume} ${tmp_volume}" EXIT
os::log::debug "Using container ${container}"
