Skip to content

Commit

Permalink
docker_shell: Normalize execroot path and run docker in background on…
Browse files Browse the repository at this point in the history
…ly for bazel build

Signed-off-by: Eryk Szpotanski <[email protected]>
  • Loading branch information
eszpotanski committed May 2, 2024
1 parent 5dba539 commit 447f9fb
Showing 1 changed file with 59 additions and 43 deletions.
102 changes: 59 additions & 43 deletions docker_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ if [[ $DIR == */external/bazel-orfs~override ]]; then
DOCKER_ARGS="$DOCKER_ARGS -v $BAZLE_ORFS_DIR:$BAZLE_ORFS_DIR"
fi

if [[ "${1}" == "--interactive" ]]; then
if test -t 0; then
DOCKER_INTERACTIVE=-ti
else
echo "STDIN not opened in the terminal, --interactive has no effect"
fi
shift 1
fi

XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
Expand Down Expand Up @@ -74,46 +83,53 @@ chmod -R +w $WORKSPACE_EXECROOT/bazel-out/k8-fastbuild/bin

export MAKEFILES=$FLOW_HOME/Makefile

# Handle TERM signals
# this option requires `supports-graceful-termination` tag in Bazel rule
trap handle_sigterm SIGTERM

# Most of these options below has to do with allowing to
# run the OpenROAD GUI from within Docker.
docker run --name "bazel-orfs-$uuid" --rm \
-u $(id -u ${USER}):$(id -g ${USER}) \
-e LIBGL_ALWAYS_SOFTWARE=1 \
-e "QT_X11_NO_MITSHM=1" \
-e XDG_RUNTIME_DIR=/tmp/xdg-run \
-e DISPLAY=$DISPLAY \
-e QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb \
-v $XSOCK:$XSOCK \
-v $XAUTH:$XAUTH \
-e XAUTHORITY=$XAUTH \
-e BUILD_DIR=$WORKSPACE_EXECROOT \
-e FLOW_HOME=$FLOW_HOME \
-e MAKEFILES=$MAKEFILES \
-e DESIGN_CONFIG=$DESIGN_CONFIG_PREFIXED \
-e STAGE_CONFIG=$STAGE_CONFIG_PREFIXED \
-e MAKE_PATTERN=$MAKE_PATTERN_PREFIXED \
-e WORK_HOME=$WORKSPACE_EXECROOT/$RULEDIR \
$MOCK_AREA_TCL_PREFIXED \
$MEMORY_DUMP_TCL_PREFIXED \
$MEMORY_DUMP_PY_PREFIXED \
-v $WORKSPACE_ROOT:$WORKSPACE_ROOT \
-v $WORKSPACE_ORIGIN:$WORKSPACE_ORIGIN \
--network host \
$DOCKER_INTERACTIVE \
$DOCKER_ARGS \
${OR_IMAGE:-openroad/flow-ubuntu22.04-builder:latest} \
bash -c \
"set -ex
. ./env.sh
cd \$BUILD_DIR
$ARGUMENTS
" &

# Wait for Docker container to finish
# Docker container has to be run in subprocess,
# otherwise signal will not be handled immediately
wait $!
function run_docker() {
# Most of these options below has to do with allowing to
# run the OpenROAD GUI from within Docker.
docker run --name "bazel-orfs-$uuid" --rm \
-u $(id -u ${USER}):$(id -g ${USER}) \
-e LIBGL_ALWAYS_SOFTWARE=1 \
-e "QT_X11_NO_MITSHM=1" \
-e XDG_RUNTIME_DIR=/tmp/xdg-run \
-e DISPLAY=$DISPLAY \
-e QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb \
-v $XSOCK:$XSOCK \
-v $XAUTH:$XAUTH \
-e XAUTHORITY=$XAUTH \
-e BUILD_DIR=$WORKSPACE_EXECROOT \
-e FLOW_HOME=$FLOW_HOME \
-e MAKEFILES=$MAKEFILES \
-e DESIGN_CONFIG=$DESIGN_CONFIG_PREFIXED \
-e STAGE_CONFIG=$STAGE_CONFIG_PREFIXED \
-e MAKE_PATTERN=$MAKE_PATTERN_PREFIXED \
-e WORK_HOME=$WORKSPACE_EXECROOT/$RULEDIR \
$MOCK_AREA_TCL_PREFIXED \
$MEMORY_DUMP_TCL_PREFIXED \
$MEMORY_DUMP_PY_PREFIXED \
-v $WORKSPACE_ROOT:$WORKSPACE_ROOT \
-v $WORKSPACE_ORIGIN:$WORKSPACE_ORIGIN \
--network host \
$DOCKER_INTERACTIVE \
$DOCKER_ARGS \
${OR_IMAGE:-openroad/flow-ubuntu22.04-builder:latest} \
bash -c \
"set -ex
. ./env.sh
cd \$BUILD_DIR
$ARGUMENTS
"
}

if [[ "$DOCKER_INTERACTIVE" == "" ]]; then
# Handle TERM signals
# this option requires `supports-graceful-termination` tag in Bazel rule
trap handle_sigterm SIGTERM
run_docker &

# Wait for Docker container to finish
# Docker container has to be run in subprocess,
# otherwise signal will not be handled immediately
wait $!
else
run_docker
fi

0 comments on commit 447f9fb

Please sign in to comment.