Skip to content

Commit

Permalink
Remove build docker volumes if OS_BUILD_ENV_CLEAN_BUILD_VOLUME is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
ingvagabund committed Sep 1, 2017
1 parent a213e8c commit 5a4f740
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions hack/lib/build/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,21 @@ 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
os::log::debug "Removing container ${container}"
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
}
Expand Down Expand Up @@ -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}"

Expand Down

0 comments on commit 5a4f740

Please sign in to comment.