Skip to content

Commit

Permalink
Fix docker creation for Ubuntu 20.04 and 22.04 (StoglRobotics#83)
Browse files Browse the repository at this point in the history
* Fix docker creation by dynamically adding ROS 1 repositories if Ubuntu 20.04 is used.
  • Loading branch information
destogl authored Nov 21, 2022
1 parent 2c4bbd5 commit 8826439
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 29 deletions.
9 changes: 1 addition & 8 deletions docs/docker/nvidia_docker/setup_nvidia_support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,7 @@ Change the Dockerfile

.. code-block:: bash
.\build_docker_image
to rebuild your container. After the rebuilt has finished you can recreate it with

.. code-block:: bash
.\create_docker_container
./recreate_docker.sh
You now should have a docker container which exposes your nvidia drivers and can switch to your workspace with ``rtw_switch_to_docker``.

Expand Down
2 changes: 1 addition & 1 deletion docs/use-cases/operating_system/create_setup_workspace.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ If you exited a container an want to reconnect as a user, you have to run the ``
Recreate a container
""""""""""""""""""""""

If you removed an image, you can recreate it by switching into the ``.rtw_docker_defines`` folder inside your workspace and then executing the ``.\build_docker_image`` command. After the container is rebuilt, you can create it with ``.\create_docker_container`` command. Thereafter, you should be able to normally start, reconnect and stop the container.
If you removed an image, you can recreate it by switching into the ``.rtw_docker_defines`` folder inside your workspace and then executing the ``./recreate_docker.sh`` command. After the process is finished you should be able to normally start, reconnect and stop the container.

.. note::
For more general questions on the usage of docker and the limitations of RosTeamWS in interacting with docker have a look at our :ref:`docker related docs<docker-overview>`.
Expand Down
13 changes: 11 additions & 2 deletions scripts/_RosTeamWs_Defines.bash
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,25 @@ function user_decision {
local decision=$1
user_answer=$2

echo -e "${TERMINAL_COLOR_USER_INPUT_DECISION}${decision}[${rtw_accepted_answers[*]}]${TERMINAL_COLOR_NC}"
echo -e "${TERMINAL_COLOR_USER_INPUT_DECISION}${decision}${TERMINAL_COLOR_NC} [${rtw_accepted_answers[*]}]"
read user_answer

while ! $(is_accepted_user_answer "$user_answer");
do
echo -e "${TERMINAL_COLOR_USER_INPUT_DECISION}${decision} Please type one of the following: [${rtw_accepted_answers[*]}]${TERMINAL_COLOR_NC}"
echo -e "${TERMINAL_COLOR_USER_INPUT_DECISION}${decision}${TERMINAL_COLOR_NC} ${TERMINAL_COLOR_USER_NOTICE}Please type one of the following:${TERMINAL_COLOR_NC} [${rtw_accepted_answers[*]}]"
read user_answer
done
}

# function which prints a notification in predefined color scheme and wait for user confirmation
# $1 - notification = The message which gets print to the commandline
function user_confirmation {
notification=$1

echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}${notification}${TERMINAL_COLOR_NC}"
read
}

function set_framework_default_paths {
FRAMEWORK_NAME="ros_team_workspace"
# readlink prints resolved symbolic links or canonical file names -> the "dir/dir_2/.." becomes "dir"
Expand Down
4 changes: 2 additions & 2 deletions scripts/docker/_RosTeamWs_Docker_Defines.bash
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ build_docker_image () {
prev_pwd=$(pwd)
cd "$(dirname "$docker_file_path")" || { echo "Could not change directory to new workspace"; return 1; }

echo "Building docker image $docker_image_tag with docker file $docker_file_path. This can take a while..."
notify_user "Building docker image $docker_image_tag with docker file $docker_file_path. This can take a while..."
sleep 1 # sleep a second, so that user can read above message
docker build \
--build-arg user=$USER \
Expand Down Expand Up @@ -89,7 +89,7 @@ create_docker_container() {
fi
# END: Needed for Nvidia support

echo "Instantiating docker image '$docker_image_tag' and mapping workspace folder to '$ws_folder'."
notify_user "Instantiating docker image '$docker_image_tag' and mapping workspace folder to '$ws_folder'."
xhost +local:docker
docker run \
--net=host \
Expand Down
26 changes: 21 additions & 5 deletions scripts/setup-ros-workspace.bash
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ setup_new_workspace () {

# TODO(destogl): This is only temporarily solution until we offer different base-workspaces support (above commented lines)
choice="0"
echo -e "${RTW_COLOR_NOTIFY_USER} The new workspace will base on currently sourced workspace or if none is sourced, '${ros_distro_base_workspace_source_path}' will be sourced."
notify_user "The new workspace will based on currently sourced workspace or if none is sourced, '${ros_distro_base_workspace_source_path}' will be sourced."

if [ -z "$choice" ]; then
print_and_exit "No workspace is chosen!" "$usage"
Expand All @@ -145,7 +145,7 @@ setup_new_workspace () {
base_ws_path=""

if [ -z "$ROS_DISTRO" ]; then
echo -e "${TERMINAL_COLOR_YELLOW}No workspace is sourced, sourcing: '${ros_distro_base_workspace_source_path}'${TERMINAL_COLOR_NC}"
notify_user "No workspace is sourced, sourcing: '${ros_distro_base_workspace_source_path}'"
source ${ros_distro_base_workspace_source_path}
base_ws_path="${ros_distro_base_workspace_source_path}"
fi
Expand All @@ -163,10 +163,9 @@ setup_new_workspace () {

# TODO: Add here output of the <current> WS
echo ""
echo -e "${TERMINAL_COLOR_USER_NOTICE}ATTENTION: Creating a new workspace in folder \"${ws_path}\" for ROS \"${ros_distro}\" (ROS$ros_version) (full path: ${new_workspace_location}) using \"${base_ws}\" (${base_ws_path}) as base workspace.${TERMINAL_COLOR_NC}"
notify_user "ATTENTION: Creating a new workspace in folder \"${ws_path}\" for ROS \"${ros_distro}\" (ROS$ros_version) (full path: ${new_workspace_location}) using \"${base_ws}\" (${base_ws_path}) as base workspace."
echo ""
echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}If correct press <ENTER>, otherwise <CTRL>+C and start the script again from the package folder and/or with correct controller name.${TERMINAL_COLOR_NC}"
read
user_confirmation "If correct press <ENTER>, otherwise <CTRL>+C and start the script again from the package folder and/or with correct controller name."

# TODO(destogl): This part with base workspaces should be updated!!! - this is obsolete logic
# Create and initialise ROS-Workspace
Expand Down Expand Up @@ -362,6 +361,22 @@ create_workspace_docker () {
if [[ "${ubuntu_version}" == *20.04* ]]; then
DOCKER_FILE="$ws_docker_folder/Dockerfile"
TMP_FILE="$ws_docker_folder/.tmp_Dockerfile"

# Add ROS 1 repositories
mv $DOCKER_FILE "$TMP_FILE"
TEST_LINE=`awk '$1 == "#" && $2 == "ROS2" && $3 == "repository" { print NR }' $TMP_FILE` # get line before `# ROS2 repository`
let CUT_LINE=$TEST_LINE-1
head -$CUT_LINE $TMP_FILE > $DOCKER_FILE

echo "# ROS repository" >> $DOCKER_FILE
echo "RUN echo \"deb [arch=\$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros/ubuntu \$(lsb_release -sc) main\" | tee /etc/apt/sources.list.d/ros.list > /dev/null" >> $DOCKER_FILE
echo "" >> $DOCKER_FILE

# Add last part
let CUT_LINE=$TEST_LINE+0
tail -n +$CUT_LINE $TMP_FILE >> $DOCKER_FILE

# Add repositories for Nala
mv $DOCKER_FILE "$TMP_FILE"
TEST_LINE=`awk '$1 == "#" && $2 == "install" && $3 == "nala" { print NR }' $TMP_FILE` # get line before `# install nala and upgrade` dependency
let CUT_LINE=$TEST_LINE-0
Expand All @@ -376,6 +391,7 @@ create_workspace_docker () {
let CUT_LINE=$TEST_LINE+2
tail -n +$CUT_LINE $TMP_FILE >> $DOCKER_FILE

# Cleanup temp files
rm $TMP_FILE
fi

Expand Down
3 changes: 0 additions & 3 deletions templates/docker/nvidia.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ RUN nala install -y curl gnupg gnupg2 lsb-release software-properties-common &&
# Add key to keyring
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

# ROS repository
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/ros.list > /dev/null

# ROS2 repository
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null

Expand Down
10 changes: 5 additions & 5 deletions templates/docker/recreate_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

build_docker_image () {
RTW_WS_build_docker_container_image () {

local docker_image_tag=DUMMY_DOCKER_IMAGE_TAG

Expand All @@ -25,7 +25,7 @@ build_docker_image () {
-t "$docker_image_tag" .
}

create_docker_container () {
RTW_WS_create_docker_container_instance () {

local docker_host_name=DUMMY_DOCKER_HOSTNAME
local docker_image_tag=DUMMY_DOCKER_IMAGE_TAG
Expand All @@ -46,7 +46,7 @@ create_docker_container () {
fi
# END: Needed for Nvidia support

echo "Instantiating docker image '$docker_image_tag' and mapping workspace folder to '$ws_folder'."
notify_user "Instantiating docker image '$docker_image_tag' and mapping workspace folder to '$ws_folder'."
xhost +local:docker
docker run \
--net=host \
Expand All @@ -64,5 +64,5 @@ create_docker_container () {
-it "$docker_image_tag" /bin/bash
}

build_docker_image
create_docker_container
RTW_WS_build_docker_container_image
RTW_WS_create_docker_container_instance
3 changes: 0 additions & 3 deletions templates/docker/standard.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ RUN nala install -y curl gnupg gnupg2 lsb-release software-properties-common &&
# Add key to keyring
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

# ROS repository
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/ros.list > /dev/null

# ROS2 repository
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null

Expand Down

0 comments on commit 8826439

Please sign in to comment.