sea-bass / turtlebot3_behavior_demos

Example repository for autonomous behaviors using TurtleBot3, as well as Docker workflows in ROS based projects.
MIT License
270 stars 53 forks source link

Colcon build failing due to permissions #41

Closed JTomasi closed 9 months ago

JTomasi commented 9 months ago

Hello,

Thanks for detailed guide and example repo! I've created a slightly modified version of your docker setup but I've encountered a colcon build issue related to permissions that I was hoping you might have some insight to.

After successfully running docker-compose up and entering the development container, I can't seem to run colcon build. When running this, colcon build returns the following error: PermissionError: [Errno 13] Permission denied: 'log/build_2023-11-27_23-16-18'

As part of my debugging, I tried changing the permissions in the Dockerfile from 0440 to 0777 here:

RUN groupadd --gid $GID $USERNAME \
 && useradd --uid ${GID} --gid ${UID} --create-home ${USERNAME} \
 && echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \
 && chmod 0440 /etc/sudoers.d/${USERNAME} \
 && mkdir -p /home/${USERNAME} \
 && chown -R ${UID}:${GID} /home/${USERNAME}

but this did not seem to make a difference.

One solution I've found is to remove the colcon build artifacts from the volume mount in the docker-compose.yaml file:

 volumes:
      # Mount the source code
      - ./tb3_autonomy:/overlay_ws/src/tb3_autonomy:rw
      - ./tb3_worlds:/overlay_ws/src/tb3_worlds:rw
      # Mount colcon build artifacts for faster rebuilds
      - ./.colcon/build/:/overlay_ws/build/:rw
      - ./.colcon/install/:/overlay_ws/install/:rw
      - ./.colcon/log/:/overlay_ws/log/:rw

So the issue seems to stem from the creation of the .colcon folder during the docker build. Do you have any insight into how to remedy this while keeping the .colcon artifacts as bind mounts?

Thanks again!

sea-bass commented 9 months ago

I think the way things are set up, you need to have the .colcon/build, .colcon/install, and .colcon/log folders existing on your host before starting the container.

And if they do exist, ensure that they are owned by your user! For example:

sudo chown -R <username> .colcon/build .colcon/install .colcon/log

Otherwise, if these folders do not exist, Docker will create them at volume mount time as root, which leads to the above errors. I'm very familiar with those :)

There is a strategy to modify the entrypoint to chown -R user <these_folders> instead, but that involves more modifications than simply ensuring your folders exist on the host, and are owned by your user. But you can try this out if you'd like!

JTomasi commented 9 months ago

Making sure they existed before starting the container fixed it, thank you!