Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove build docker volume if OS_BUILD_ENV_CLEAN_BUILD_VOLUME is set #16073

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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