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

Adds a dockerfile for webots with nuwebots and robocup environments #101

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
66 changes: 66 additions & 0 deletions webots-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ARG BASE_IMAGE=nvidia/cuda:11.8.0-base-ubuntu22.04
FROM ${BASE_IMAGE} AS downloader

# Determine Webots version to be used and set default argument
ARG WEBOTS_VERSION=R2022b
ARG WEBOTS_PACKAGE_PREFIX=

# Disable dpkg/gdebi interactive dialogs
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install --yes wget bzip2 && rm -rf /var/lib/apt/lists/ && \
JesseWilliamson marked this conversation as resolved.
Show resolved Hide resolved
wget https://github.com/cyberbotics/webots/releases/download/$WEBOTS_VERSION/webots-$WEBOTS_VERSION-x86-64$WEBOTS_PACKAGE_PREFIX.tar.bz2 && \
tar xjf webots-*.tar.bz2 && rm webots-*.tar.bz2

FROM ${BASE_IMAGE}

# Disable dpkg/gdebi interactive dialogs
ENV DEBIAN_FRONTEND=noninteractive


# Install Webots runtime dependencies
RUN apt-get update && apt-get install --yes wget xvfb git python3-pip sudo && rm -rf /var/lib/apt/lists/ && \
wget https://raw.githubusercontent.com/cyberbotics/webots/master/scripts/install/linux_runtime_dependencies.sh && \
chmod +x linux_runtime_dependencies.sh && ./linux_runtime_dependencies.sh && rm ./linux_runtime_dependencies.sh

# Install NUWebots dependencies
RUN wget https://raw.githubusercontent.com/NUbots/NUWebots/main/webots-docker/dependencies.sh && \
chmod +x dependencies.sh && ./dependencies.sh && rm ./dependencies.sh && rm -rf /var/lib/apt/lists/

# Install Webots
WORKDIR /usr/local
COPY --from=downloader /webots /usr/local/webots/
ENV QTWEBENGINE_DISABLE_SANDBOX=1
ENV WEBOTS_HOME /usr/local/webots
ysims marked this conversation as resolved.
Show resolved Hide resolved
ENV PATH /usr/local/webots:${PATH}

# Enable OpenGL capabilities
ENV NVIDIA_DRIVER_CAPABILITIES=graphics

RUN useradd -ms /bin/bash webots && usermod -aG sudo webots && echo "webots ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
ENV HOME=/home/webots
JesseWilliamson marked this conversation as resolved.
Show resolved Hide resolved
USER webots

WORKDIR $HOME
JesseWilliamson marked this conversation as resolved.
Show resolved Hide resolved

# Build the latest version of the RoboCup Humanoid TC fork of GameController
RUN git clone https://github.com/RoboCup-Humanoid-TC/GameController ./GameController && cd GameController && ant

# Build the robocup controllers
RUN git clone https://github.com/RoboCup-Humanoid-TC/hlvs_webots.git ./hlvs_webots && \
pip3 install -r ./hlvs_webots/controllers/referee/requirements.txt && make -j$(nproc) -C ./hlvs_webots
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering - does $(nproc) affect caching if you ran it on a computer with a different amount of cores? Is it worth putting that in a script for that reason? (Presuming my suspicion is correct)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make sense, but I haven't been able to find any solid info on it, so I'll need to test it. I don't understand why two computers would be building from the same cache though? Maybe I don't understand what you mean.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't change caching. All that would change it is if you changed the actual text here


# Set environment variables for GameController
ENV GAME_CONTROLLER_HOME=${HOME}/GameController JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

# Install the NUbots-developed environment
RUN git clone https://github.com/NUbots/NUWebots.git ./NUWebots && cd ./NUWebots && pip3 install -r ./requirements.txt && \
./b configure -- -DENABLE_CLANG_TIDY=OFF && ./b build

RUN wget https://raw.githubusercontent.com/NUbots/NUWebots/main/webots-docker/webots-config.py && \
wget https://raw.githubusercontent.com/NUbots/NUWebots/main/webots-docker/entrypoint.sh && \
chmod +x entrypoint.sh

# Configure robocup game.json file based on environment variables
ENTRYPOINT ["./entrypoint.sh"]
CMD ["bash"]
3 changes: 3 additions & 0 deletions webots-docker/dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
apt-get update
apt-get install -y ant cmake-curses-gui libprotobuf-dev protobuf-compiler libeigen3-dev libyaml-cpp-dev ninja-build clang-tidy python3-dev libjpeg9-dev sudo vim nano
5 changes: 5 additions & 0 deletions webots-docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
python3 docker-config.py ${HOME}/hlvs_webots/controllers/referee/game.json
rm docker-config.py
JesseWilliamson marked this conversation as resolved.
Show resolved Hide resolved
# Run the command given by CMD or docker run parameter, replacing current process
exec "$@"
15 changes: 15 additions & 0 deletions webots-docker/webots-config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import json, os, sys
JesseWilliamson marked this conversation as resolved.
Show resolved Hide resolved

TEAM_NAME = os.environ.get('TEAM_NAME')
ROBOT_HOSTS = os.environ.get('ROBOT_HOSTS')

filename = sys.argv[1]

with open(filename, 'r') as f:
game_config = json.load(f)

if TEAM_NAME: game_config['red']['config'] = 'teams/' + TEAM_NAME + '.json'
JesseWilliamson marked this conversation as resolved.
Show resolved Hide resolved
if ROBOT_HOSTS: game_config['red']['hosts'] += ROBOT_HOSTS.split(",")

with open(filename, 'w') as f:
json.dump(game_config, f, indent=2)