From bbea59dc4058bc4ee3c93fa9935257323225a3ae Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Thu, 22 Sep 2022 10:51:46 +0200 Subject: [PATCH] Changed default permissions to root, sshd for connectivity to container. --- .env | 2 ++ .gitignore | 3 ++- build_ros/Dockerfile | 19 +++++++++++++++++-- build_ros/entrypoint.sh | 37 +++++++++++++++++++++++++++++++------ docker-compose.yaml | 4 +++- shell.sh | 1 + 6 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 .env create mode 100755 shell.sh diff --git a/.env b/.env new file mode 100644 index 0000000..4719969 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +U_ID=1000 +G_ID=1000 diff --git a/.gitignore b/.gitignore index 83aa00b..a99f1dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -/* !/docker-compose.yaml !/build_ros !/start.sh +!/shell.sh !/.gitignore +/home diff --git a/build_ros/Dockerfile b/build_ros/Dockerfile index 498ee24..b0679a6 100755 --- a/build_ros/Dockerfile +++ b/build_ros/Dockerfile @@ -1,11 +1,26 @@ -ARG ROS=humble +ARG ROS=humble FROM osrf/ros:${ROS}-desktop -RUN apt-get update && apt-get install -y ros-galactic-ros-ign-gazebo && rm -rf /var/lib/apt/lists/* + +#SSH (First to hopefully keep keys, even on modification.) +RUN apt-get update && apt-get install -y openssh-server && rm -rf /var/lib/apt/lists/* +RUN mkdir /run/sshd +RUN ssh-keygen -A +#OpenGL RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y xserver-xorg-video-all libgl1-mesa-glx libgl1-mesa-dri libglvnd0 libgl1 libglx0 libegl1 libxext6 libx11-6 && rm -rf /var/lib/apt/lists/* +#Vulkan RUN apt-get update && apt-get install -y libvulkan1 mesa-vulkan-drivers vulkan-utils mesa-utils && rm -rf /var/lib/apt/lists/* +#Utils +RUN apt-get update && apt-get install -y git ninja-build git bash-completion && rm -rf /var/lib/apt/lists/* +#Rosdeps +RUN apt-get update && apt-get install -y git ros-galactic-ament-cmake ros-galactic-moveit ros-galactic-behaviortree-cpp-v3 ros-galactic-ros-ign-gazebo && rm -rf /var/lib/apt/lists/* ARG G_ID=1000 ARG U_ID=1000 RUN groupadd -f -g ${G_ID} ros RUN useradd -u ${U_ID} -g ${G_ID} -m ros + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +CMD ["/usr/bin/bash", "-c", "/entrypoint.sh", "${ROS_NAME}"] diff --git a/build_ros/entrypoint.sh b/build_ros/entrypoint.sh index 40b6eed..d794946 100755 --- a/build_ros/entrypoint.sh +++ b/build_ros/entrypoint.sh @@ -1,9 +1,34 @@ #!/bin/bash -groupadd -f -g $GID ros -useradd -u $UID -g $GID -m ros -usermod -aG video ros -usermod -aG render ros -chown -R $UID:$GID /home/ros +if [ ! -f /home/ros/docker_image_version ]; then + echo "0" > /home/ros/docker_image_version +fi -exec su ros -c "/ros_entrypoint.sh $@" +chsh -s /usr/bin/bash ros + +if [ "0" == "$(cat /home/ros/docker_image_version)" ]; then + echo "Performing initial setup..." + + cp /etc/skel/.* /home/ros + chown -R ros:ros /home/ros + + su ros -c "echo 'source ~/.rosrc' >> ~/.bashrc" + echo "Modified .bashrc" + su ros -c "mkdir -p /home/ros/workspace/src" + echo "Created workspace" + su ros -c "cd /home/ros/workspace; colcon build --event-handlers console_cohesion+ --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja" + echo "Built workspace" + echo "1" > /home/ros/docker_image_version +fi + +if [ ! -f /home/ros/.ssh/id_rsa ]; then + su ros -c "ssh-keygen -N '' -f /home/ros/.ssh/id_rsa" + echo "Generated SSH Keys." +fi + +echo "ros:ros" | chpasswd +su ros -c "echo 'source /opt/ros/$ROS_DISTRO/setup.bash\nsource /home/ros/workspace/install/setup.bash' > ~/.rosrc" + +echo "Ready to connect." + +/usr/sbin/sshd -p 2222 -D diff --git a/docker-compose.yaml b/docker-compose.yaml index f74c5dc..9615e9f 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,6 +2,7 @@ version: "3.2" services: ros: + hostname: ros image: ros/custom build: context: ./build_ros @@ -15,9 +16,10 @@ services: environment: - DISPLAY=$DISPLAY - XAUTHORITY=$XAUTHORITY - user: ${U_ID}:${G_ID} stdin_open: true tty: true + ports: + - "2222:2222" #group_add: # - video # - render diff --git a/shell.sh b/shell.sh new file mode 100755 index 0000000..9df4b27 --- /dev/null +++ b/shell.sh @@ -0,0 +1 @@ +sudo docker-compose exec -w /home/ros ros bash