Skip to content

Commit

Permalink
Merge branch 'M1chaelM/rocker_support' into 'jessica/mwes' so we can …
Browse files Browse the repository at this point in the history
…test server and competitor image together
  • Loading branch information
M1chaelM committed Jun 22, 2023
2 parents 790c7ee + 4ac35d4 commit 437f4cd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 186 deletions.
6 changes: 3 additions & 3 deletions run_trial.bash
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ else
fi

COMP_GENERATED_DIR=${DIR}/generated/task_generated/${TASK_NAME}
if [ -f "${COMP_GENERATED_DIR}/worlds/${TASK_NAME}${TRIAL_NUM}.world" ]; then
echo "Successfully found: ${COMP_GENERATED_DIR}/worlds/${TASK_NAME}${TRIAL_NUM}.world"
if [ -f "${COMP_GENERATED_DIR}/worlds/${TASK_NAME}${TRIAL_NUM}.sdf" ]; then
echo "Successfully found: ${COMP_GENERATED_DIR}/worlds/${TASK_NAME}${TRIAL_NUM}.sdf"
else
echo -e "${RED}Err: ${COMP_GENERATED_DIR}/worlds/${TASK_NAME}${TRIAL_NUM}.world not found."; exit 1;
echo -e "${RED}Err: ${COMP_GENERATED_DIR}/worlds/${TASK_NAME}${TRIAL_NUM}.sdf not found."; exit 1;
fi

# Ensure any previous containers are killed and removed.
Expand Down
55 changes: 20 additions & 35 deletions vrx_server/build_image.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,39 @@ NOCOLOR='\033[0m'
# Get directory of this file
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Setup docker args
USERID=`id -u`
GROUPID=`id -g`
if [[ ${USERID} != 0 ]]; then
DOCKER_ARGS="--build-arg USERID=${USERID} --build-arg GROUPID=${GROUPID}"
fi
# Parse arguments
local_base_name="vrx-local-base"
image_name="vrx-server-jammy"

DOCKER_ARGS="--build-arg BASEIMG=$local_base_name"
# DOCKER_ARGS="$DOCKER_ARGS --no-cache"
JOY=/dev/input/js0

# Parse arguments
BUILD_BASE=""
image_name="vrx-server-noetic"

# Parse args related to NVIDIA
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
-n|--nvidia)
BUILD_BASE="--build-arg BASEIMG=nvidia/opengl:1.0-glvnd-devel-ubuntu20.04"
image_name="$image_name-nvidia"
shift
;;
*) # unknown option
POSITIONAL+=("$1")
shift
;;
esac
done

set -- "${POSITIONAL[@]}"

# Usage
if [ $# -gt 0 ]
then
echo "Usage: $0 [-n --nvidia]"
echo "Usage: $0 "
exit 1
fi

ROCKER_ARGS="--dev-helpers --devices $JOY --nvidia --x11 --user --user-override-name=developer --image-name $local_base_name"
rocker ${ROCKER_ARGS} npslearninglab/watery_robots:vrx_base "echo -e '${GREEN}Created $local_base_name.${NOCOLOR}\n'"

CONTAINER_NAME="vrx-server-system"

# Build image
echo "Build image: $image_name"
echo "Building image: <${image_name}> from <$local_base_name>"
set -x
image_plus_tag=$image_name:$(export LC_ALL=C; date +%Y_%m_%d_%H%M)
docker build --force-rm ${DOCKER_ARGS} --tag $image_plus_tag --build-arg USER=$USER --build-arg GROUP=$USER $BUILD_BASE $DIR/vrx-server && \
docker tag $image_plus_tag $image_name:latest && \
echo "Built $image_plus_tag and tagged as $image_name:latest"
image_plus_tag=${image_name}:$(export LC_ALL=C; date +%Y_%m_%d_%H%M)
docker build --force-rm ${DOCKER_ARGS} --tag $image_plus_tag $DIR/vrx-server && \
docker tag $image_plus_tag ${image_name}:latest && \
echo "Built $image_plus_tag and tagged as ${image_name}:latest"

#echo "Using image <$IMG_NAME> to start container <$CONTAINER_NAME>"
# --name $CONTAINER_NAME


set +x
echo -e "${GREEN}Done.${NOCOLOR}\n"
31 changes: 14 additions & 17 deletions vrx_server/run_container.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ do
;;
*) # unknown option
POSITIONAL+=("$1")
[ruby $(which gz) sim-1] qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
shift
;;
esac
Expand All @@ -45,6 +46,7 @@ set -- "${POSITIONAL[@]}"

if [[ $# -lt 2 ]]
then
[ruby $(which gz) sim-1] qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
echo "Usage: $0 [-n --nvidia] <container_name> <image_name> [<docker_extra_args> <command>]"
exit 1
fi
Expand All @@ -56,36 +58,31 @@ COMMAND=$4

# Make sure processes in the container can connect to the x server
# Necessary so gazebo can create a context for OpenGL rendering (even headless)
XAUTH=/tmp/.docker.xauth
XAUTH=/tmp/.dockervrx.xauth
if [ ! -f $XAUTH ]
then
xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/')
if [ ! -z "$xauth_list" ]
then
echo $xauth_list | xauth -f $XAUTH nmerge -
else
touch $XAUTH
fi
chmod a+r $XAUTH
touch $XAUTH
fi

USERID=$(id -u)
GROUPID=$(id -g)
xauth_list=$(xauth nlist $DISPLAY | sed -e 's/^..../ffff/')
if [ ! -z "$xauth_list" ]
then
echo $xauth_list | xauth -f $XAUTH nmerge -
fi
chmod a+r $XAUTH

docker run --name ${CONTAINER} \
-e DISPLAY \
-e TERM \
-e QT_X11_NO_MITSHM=1 \
-e XAUTHORITY=$XAUTH \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
-v "$XAUTH:$XAUTH" \
-v "/tmp/.X11-unix:/tmp/.X11-unix" \
-v "/etc/localtime:/etc/localtime:ro" \
-v "/tmp/.docker.xauth:/tmp/.docker.xauth" \
-v /dev/log:/dev/log \
-v "/dev/input:/dev/input" \
--runtime=$RUNTIME \
--gpus all \
--privileged \
--security-opt seccomp=unconfined \
-u $USERID:$GROUPID \
${DOCKER_EXTRA_ARGS} \
${IMAGE_NAME} \
${COMMAND}
Expand Down
135 changes: 9 additions & 126 deletions vrx_server/vrx-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,144 +1,27 @@
ARG BASEIMG=ubuntu:focal
ARG BASEIMG=npslearninglab/watery_robots:vrx_base
FROM $BASEIMG

# Set ROS distribution
ARG DIST=noetic

# Set Gazebo verison
ARG GAZ=gazebo11

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt update \
&& apt install -y \
tzdata \
&& ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime \
&& dpkg-reconfigure --frontend noninteractive tzdata \
&& apt clean

# Tools useful during development.
RUN apt update \
&& apt install -y \
build-essential \
cmake \
cppcheck \
curl \
git \
language-pack-en \
libeigen3-dev \
libgles2-mesa-dev \
lsb-release \
gdb \
mercurial \
pkg-config \
psmisc \
python3-dbg \
python3-pip \
python3-venv \
qtbase5-dev \
ruby \
software-properties-common \
sudo \
vim \
wget \
&& apt clean

# Get ROS and Gazebo
RUN wget -P /tmp/ http://packages.osrfoundation.org/gazebo.key
RUN wget -P /tmp/ http://packages.ros.org/ros.key
RUN /bin/sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' \
&& apt-key add /tmp/ros.key \
&& /bin/sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" > /etc/apt/sources.list.d/gazebo-stable.list' \
&& apt-key add /tmp/gazebo.key \
&& apt update \
&& apt install -y \
${GAZ} \
lib${GAZ}-dev \
ros-${DIST}-compressed-image-transport \
ros-${DIST}-ros-base \
ros-${DIST}-gazebo-plugins \
ros-${DIST}-gazebo-ros \
ros-${DIST}-hector-gazebo-plugins \
ros-${DIST}-joy \
ros-${DIST}-joy-teleop \
ros-${DIST}-key-teleop \
ros-${DIST}-robot-localization \
ros-${DIST}-robot-state-publisher \
ros-${DIST}-rviz \
ros-${DIST}-teleop-tools \
ros-${DIST}-teleop-twist-keyboard \
ros-${DIST}-velodyne-simulator \
ros-${DIST}-xacro \
&& apt clean

# Removed
# python-rosdep \
# && rosdep init \
# RUN rosdep update

# Set USER and GROUP
ARG USER=developer
ARG GROUP=developer
ARG USERID=1000
ARG GROUPID=1000

# Add a user with the same user_id as the user outside the container
# Requires a docker build argument `user_id`.

RUN curl -SsL https://github.com/boxboat/fixuid/releases/download/v0.4/fixuid-0.4-linux-amd64.tar.gz | tar -C /usr/local/bin -xzf - && \
chown root:root /usr/local/bin/fixuid && \
chmod 4755 /usr/local/bin/fixuid && \
mkdir -p /etc/fixuid && \
printf "user: $USER\ngroup: $GROUP\n" > /etc/fixuid/config.yml

RUN addgroup --gid $GROUPID $USER && \
useradd --no-log-init --create-home --uid $USERID --gid $GROUPID --home-dir /home/$USER --shell /bin/sh -c "" $USER

RUN adduser $USER sudo \
&& echo "$USER ALL=NOPASSWD: ALL" >> /etc/sudoers.d/$USER

# Commands below run as the developer user.
USER $USER:$GROUP

# When running a container start in the developer's home folder.
WORKDIR /home/$USER
ARG ROSDIST=humble

# Create workspace
RUN mkdir -p vrx_ws/src
RUN mkdir -p ~/vrx_ws/src

# Copy the VRX repository from the local file system
# We can't use the USER:GROUP variables until Docker adds support to --chown
# COPY --chown=developer:developer . vrx_ws/src/vrx/
RUN git clone -b 1.6.2 https://github.com/osrf/vrx.git
RUN mv ./vrx ./vrx_ws/src
# TODO: restore version tag
RUN git clone https://github.com/osrf/vrx.git \
&& mv ./vrx ~/vrx_ws/src

# Compile the VRX project.
RUN /bin/bash -c ". /opt/ros/${DIST}/setup.bash && cd vrx_ws && catkin_make"
RUN /bin/bash -c ". /opt/ros/${ROSDIST}/setup.bash && cd ~/vrx_ws && colcon build --merge-install"

# Source all the needed environment files.
RUN /bin/sh -c 'echo ". /opt/ros/${DIST}/setup.bash" >> ~/.bashrc' \
&& /bin/sh -c 'echo ". /usr/share/gazebo/setup.sh" >> ~/.bashrc' \
&& /bin/sh -c 'echo ". ~/vrx_ws/devel/setup.sh" >> ~/.bashrc'
RUN /bin/sh -c 'echo ". /opt/ros/${ROSDIST}/setup.bash" >> ~/.bashrc' \
&& /bin/sh -c 'echo ". ~/vrx_ws/install/setup.sh" >> ~/.bashrc'
## END OF SECTION BASED ON vrx/docker/Dockerfile

# Expose port used to communiate with gzserver
EXPOSE 11345

# Stuff for nvidia-docker
LABEL com.nvidia.volumes.needed="nvidia_driver"
ENV PATH /usr/local/nvidia/bin:${PATH}
ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH}

# Set encoding to use unicode characters
# RUN sudo locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8

# Takes too long to do, probably not needed
# Get gazebo models early since it is big
# RUN wget -P /tmp/ https://bitbucket.org/osrf/gazebo_models/get/default.tar.gz \
# && mkdir -p $HOME/.gazebo/models \
# && tar -xvf /tmp/default.tar.gz -C $HOME/.gazebo/models --strip 1 \
# && rm /tmp/default.tar.gz

# setup entrypoint
COPY ./vrx_entrypoint.sh /
COPY ./run_vrx_trial.sh /
Expand Down
7 changes: 2 additions & 5 deletions vrx_server/vrx-server/vrx_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/bin/bash
set -e

# first, execute overriden entrypoint from gazebo
source "/usr/share/gazebo/setup.sh"

# setup ros environment.
source "/opt/ros/noetic/setup.bash" > /dev/null
source "/opt/ros/humble/setup.bash" > /dev/null

# setup vrx environment
source ~/vrx_ws/devel/setup.sh
source ~/vrx_ws/install/setup.sh
echo "vrx entrypoint executed"

# TODO: optionally disable this so a gzclient can be run on the host for development.
Expand Down

0 comments on commit 437f4cd

Please sign in to comment.