Skip to content

Commit 3a36d0c

Browse files
authored
Add bash scripts for building and running docker from terminal (#17)
* added PARALLEL_JOBS RAM usage table and Docker helper scripts info * added relative path of workspace * scripts: move docker run script into docker/, update HOST_WS and simplify entrypoint * Updated README with Docker build/launch instructions; cleaned up comments and spacing * Added a newline at the end of bash scripts
1 parent a4ac4ab commit 3a36d0c

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,30 @@ git submodule update --init --recursive
4444
The project supports both Dockerized workspaces (recommended) or a local installation for developing and running the humanoid MPC.
4545

4646
<details>
47-
<summary>Dockerized Workspace</summary>
47+
<summary>Build & run Dockerized workspace in VS Code</summary>
4848

49-
We provide a [Dockerfile](https://github.com/manumerous/wb_humanoid_mpc/blob/main/docker/Dockerfile) to enable running and devloping the project from a containerized environment. Check out the [devcontainer.json](https://github.com/manumerous/wb_humanoid_mpc/blob/main/.devcontainer/devcontainer.json) for the arguments that must be supplied to the `docker build` and `docker run` commands.
49+
We provide a [Dockerfile](https://github.com/manumerous/wb_humanoid_mpc/blob/main/docker/Dockerfile) to enable running and devloping the project from a containerized environment. Check out the [devcontainer.json](https://github.com/manumerous/wb_humanoid_mpc/blob/main/.devcontainer/devcontainer.json) for the arguments that must be supplied to the `docker build` and `docker run` commands.
5050

5151
For working in **Visual Studio Code**, we recommend to install the [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension. Then, with the root of this repository as the root of your VS Code workspace, enter `Ctrl + Shift + P` and select `Dev Containers: Rebuild and Reopen in Container` at the top of the screen. VS Code will then automatically handle calling the `docker build` and `docker run` commands for you and will reopen the window at the root of the containerized workspace. Once this step is completed, you are ready to [build and run the code](https://github.com/manumerous/wb_humanoid_mpc/tree/main?tab=readme-ov-file#building-the-mpc).
5252

5353
</details>
5454

55+
<details>
56+
<summary> Build & run Dockerized workspace with bash scripts</summary>
57+
58+
This repository includes two helper scripts: `image_build.bash` builds the `wb-humanoid-mpc:dev` Docker image using the arguments defined in `devcontainer.json`. `launch_wb_mpc.bash` starts the Docker container, mounts your workspace, and drops you into a bash shell ready to build and run the WB Humanoid MPC code. Example of building docker image:
59+
```
60+
cd /path/to/humanoid_mpc_ws/src/wb_humanoid_mpc/docker
61+
./image_build.bash
62+
```
63+
and launching the docker container:
64+
```
65+
cd /path/to/humanoid_mpc_ws/src/wb_humanoid_mpc/docker
66+
./launch_wb_mpc.bash
67+
```
68+
69+
</details>
70+
5571
<details>
5672
<summary>Install Dependencies Locally</summary>
5773

@@ -65,6 +81,7 @@ envsubst < dependencies.txt | xargs sudo apt install -y
6581
```
6682
</details>
6783

84+
6885
### Building the MPC
6986

7087
Building the WB MPC consumes a significant amount of RAM. We recommend saving all open work before starting the first build. The RAM usage can be adjusted by setting the PARALLEL_JOBS environment variable. Our recommendation is:

docker/image_build.bash

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Usage:
4+
#
5+
# $ cd ~/your_colcon_ws/src/wb_humanoid_mpc/docker
6+
# $ ./image_build.bash # Build the WB Humanoid MPC Docker image
7+
#
8+
# (Cross reference this file with the "build" section of ../.devcontainer/devcontainer.json)
9+
#
10+
set -euo pipefail
11+
12+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13+
DOCKERFILE="${SCRIPT_DIR}/Dockerfile"
14+
CONTEXT="${SCRIPT_DIR}/.."
15+
TARGET="base"
16+
17+
18+
: "# Workspace directory inside container"
19+
WB_HUMANOID_MPC_DIR="/wb_humanoid_mpc_ws"
20+
PYTHON_VERSION="3.12"
21+
USER_ID="$(id -u)"
22+
GROUP_ID="$(id -g)"
23+
GIT_USER_NAME="$(git config --global user.name || echo '')"
24+
GIT_USER_EMAIL="$(git config --global user.email || echo '')"
25+
26+
IMAGE_TAG="wb-humanoid-mpc:dev"
27+
28+
docker build \
29+
--file "${DOCKERFILE}" \
30+
--target "${TARGET}" \
31+
--build-arg WB_HUMANOID_MPC_DIR="${WB_HUMANOID_MPC_DIR}" \
32+
--build-arg PYTHON_VERSION="${PYTHON_VERSION}" \
33+
--build-arg USER_ID="${USER_ID}" \
34+
--build-arg GROUP_ID="${GROUP_ID}" \
35+
--build-arg GIT_USER_NAME="${GIT_USER_NAME}" \
36+
--build-arg GIT_USER_EMAIL="${GIT_USER_EMAIL}" \
37+
--tag "${IMAGE_TAG}" \
38+
"${CONTEXT}"
39+
40+
echo "Built image: ${IMAGE_TAG}"
41+

docker/launch_wb_mpc.bash

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Usage:
4+
#
5+
# $ cd ~/your_colcon_ws/src/wb_humanoid_mpc/docker
6+
# $ ./launch_wb_mpc.bash # Launch the WB Humanoid MPC Docker container
7+
#
8+
# (Cross reference this file with the "run" section of ../.devcontainer/devcontainer.json)
9+
#
10+
set -euo pipefail
11+
12+
# Allow GUI applications
13+
xhost +SI:localuser:root
14+
15+
# Generate Xauthority file for X11 forwarding
16+
XAUTH=/tmp/.docker.xauth
17+
if [ ! -f "${XAUTH}" ]; then
18+
touch "${XAUTH}"
19+
xauth nlist "${DISPLAY}" \
20+
| sed -e 's/^..../ffff/' \
21+
| xauth -f "${XAUTH}" nmerge -
22+
chmod a+r "${XAUTH}"
23+
fi
24+
25+
# ROOT_COLCON_WS
26+
HOST_WS="$(realpath "${PWD}/../../..")"
27+
28+
# Run the container, mounting the entire workspace
29+
docker run --rm -it \
30+
--name wb-mpc-dev \
31+
--net host \
32+
--privileged \
33+
-u root \
34+
-e DISPLAY \
35+
-e QT_X11_NO_MITSHM=1 \
36+
-e XAUTHORITY="${XAUTH}" \
37+
-e XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/tmp}" \
38+
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
39+
-v "${XAUTH}:${XAUTH}:rw" \
40+
-v "${HOST_WS}:/wb_humanoid_mpc_ws:cached" \
41+
--workdir /wb_humanoid_mpc_ws \
42+
wb-humanoid-mpc:dev \
43+
bash
44+
45+
echo "Done."
46+

0 commit comments

Comments
 (0)