Skip to content

Commit

Permalink
Mount bazel cache folder of HOME as tmpfs with exec option
Browse files Browse the repository at this point in the history
This saves at least 6GB of diskspace and shrinks the
container_shadow_workspace by 90%

CMK-21123

Change-Id: If105e100a786343a281cc61e9bd7d7d0b2ba473a
  • Loading branch information
JonasScharpf committed Jan 22, 2025
1 parent 8cc0d5d commit aa647a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions buildscripts/scripts/utils/docker_image_aliases_helper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ inside_container = {Map arg1=[:], Closure arg2 ->
+ (args.ulimit_nofile ? ["--ulimit nofile=${args.ulimit_nofile}:${args.ulimit_nofile}"] : [])
+ (privileged ? ["-v /var/run/docker.sock:/var/run/docker.sock"] : [])
+ ["-v \"${container_shadow_workspace}/home:${env.HOME}\""]
+ "--tmpfs ${env.HOME}/.cache/bazel:exec,size=10g,mode=777"
+ (mount_credentials ? ["-v ${env.HOME}/.cmk-credentials:${env.HOME}/.cmk-credentials"] : [])
+ (mount_host_user_files ? ["-v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro"] : [])
+ ((mount_reference_repo && reference_repo_dir) ? ["-v ${reference_repo_dir}:${reference_repo_dir}:ro"] : [])
Expand Down Expand Up @@ -117,6 +118,8 @@ inside_container = {Map arg1=[:], Closure arg2 ->
# create mount dirs for $HOME/.cache (not to confuse with <checkout_dir>/.cache)
mkdir -p "${container_shadow_workspace}/home_cache"
mkdir -p "${container_shadow_workspace}/home_cache/bazel"
mkdir -p "${container_shadow_workspace}/home/.cache"
# create mount dirs for <checkout_dir>/.cache
Expand Down
9 changes: 9 additions & 0 deletions scripts/run-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ mkdir -p "${CONTAINER_SHADOW_WORKSPACE}/home"
touch "${CONTAINER_SHADOW_WORKSPACE}/home/.cmk-credentials"
mkdir -p "${CONTAINER_SHADOW_WORKSPACE}/home/.cache"
mkdir -p "${CONTAINER_SHADOW_WORKSPACE}/home_cache"
mkdir -p "${CONTAINER_SHADOW_WORKSPACE}/home_cache/bazel"
mkdir -p "${CONTAINER_SHADOW_WORKSPACE}/omd_build"
mkdir -p "${CHECKOUT_ROOT}/shared_cargo_folder"
mkdir -p "${CHECKOUT_ROOT}/omd/build"
Expand All @@ -83,6 +84,14 @@ mkdir -p "${HOME}/shared_cargo_folder"
# UNCONDITIONAL MOUNTS
DOCKER_MOUNT_ARGS="-v ${CONTAINER_SHADOW_WORKSPACE}/home:${HOME}"
DOCKER_MOUNT_ARGS="${DOCKER_MOUNT_ARGS} -v ${CONTAINER_SHADOW_WORKSPACE}/home_cache:${HOME}/.cache"

# with "--mount" the execution of binaries is not allowed and can not be changed
# use "--tmpfs" instead
# see https://docs.docker.com/engine/storage/tmpfs/#options-for---tmpfs
# mount the bazel cache as tmpfs to save minimum 6GB of diskspace
DOCKER_MOUNT_ARGS="${DOCKER_MOUNT_ARGS} --tmpfs ${HOME}/.cache/bazel:exec,size=10g,mode=777"
# other folders in HOME/.cache are not touched to ensure a fast venv creation

DOCKER_MOUNT_ARGS="${DOCKER_MOUNT_ARGS} -v ${HOME}/shared_cargo_folder:${CHECKOUT_ROOT}/shared_cargo_folder"
DOCKER_MOUNT_ARGS="${DOCKER_MOUNT_ARGS} -v ${CHECKOUT_ROOT}:${CHECKOUT_ROOT}"
DOCKER_MOUNT_ARGS="${DOCKER_MOUNT_ARGS} -v ${GIT_COMMON_DIR}:${GIT_COMMON_DIR}"
Expand Down

0 comments on commit aa647a5

Please sign in to comment.