From a5ba1bded6bf3fd3890ab84686e364d82998fabd Mon Sep 17 00:00:00 2001 From: Franco Cipollone Date: Thu, 19 Dec 2024 17:34:06 -0300 Subject: [PATCH] Jazzy: Fix docker permissions. Signed-off-by: Franco Cipollone --- docker/build.sh | 4 +++- docker/dockerfile | 10 +++++++++- docker/run.sh | 6 ++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docker/build.sh b/docker/build.sh index b0ff04c..8d34bc1 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -61,9 +61,11 @@ OS_VERSION="noble" IMAGE_NAME=${IMAGE_NAME:-ros2_jazzy_andino_gz} DOCKERFILE_PATH=$SCRIPT_FOLDER_PATH/Dockerfile -USER=ubuntu +USERID=$(id -u) +USER=$(whoami) sudo docker build -t $IMAGE_NAME \ --file $DOCKERFILE_PATH \ + --build-arg USERID=$USERID \ --build-arg USER=$USER \ $CONTEXT_FOLDER_PATH diff --git a/docker/dockerfile b/docker/dockerfile index 81e37d0..9744bc8 100644 --- a/docker/dockerfile +++ b/docker/dockerfile @@ -1,7 +1,8 @@ FROM osrf/ros:jazzy-desktop-full # Arguments for building -ARG USER=ubuntu +ARG USERID +ARG USER # Setup environment ENV TERM=linux @@ -13,6 +14,13 @@ COPY docker/requirements.txt . RUN apt-get update && apt-get install --no-install-recommends -y $(cat requirements.txt) RUN rm requirements.txt +# Create a user with passwordless sudo +RUN adduser --uid $USERID --gecos "ekumen developer" --disabled-password $USER +RUN adduser $USER sudo +RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +RUN echo "export QT_X11_NO_MITSHM=1" >> /home/$USER/.bashrc +RUN echo "export IGN_IP=127.0.0.1" >> /home/$USER/.bashrc + ##################################### # ROS2 dependencies built from source ##################################### diff --git a/docker/run.sh b/docker/run.sh index 9ac662a..0707f84 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -82,8 +82,6 @@ done IMAGE_NAME=${IMAGE_NAME:-ros2_jazzy_andino_gz} CONTAINER_NAME=${CONTAINER_NAME:-ros2_jazzy_andino_gz_container} -USER=ubuntu - SSH_PATH=/home/$USER/.ssh WORKSPACE_SRC_CONTAINER=/home/$USER/ws/src/$REPOSITORY_FOLDER_NAME WORKSPACE_ROOT_CONTAINER=/home/$USER/ws @@ -94,8 +92,8 @@ mkdir -p ${REPOSITORY_FOLDER_PATH}/.build mkdir -p ${REPOSITORY_FOLDER_PATH}/.install # Transfer the ownership to the user -# chown -R "$USER" ${REPOSITORY_FOLDER_PATH}/.build -# chown -R "$USER" ${REPOSITORY_FOLDER_PATH}/.install +chown -R "$USER" ${REPOSITORY_FOLDER_PATH}/.build +chown -R "$USER" ${REPOSITORY_FOLDER_PATH}/.install # Check if name container is already taken. if sudo -g docker docker container ls -a | grep "${CONTAINER_NAME}$" -c &> /dev/null; then