From 4b799d9800f034d5f81d6c8bbc5a3403f5f11452 Mon Sep 17 00:00:00 2001 From: texhnolyze Date: Thu, 16 May 2024 19:07:59 +0200 Subject: [PATCH 1/3] refactor(devcontainer): use non absolute path in PROMPT starting from `~` instead of using the whole path --- .devcontainer/zshrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/zshrc b/.devcontainer/zshrc index 27e9c7767..2a59d4548 100644 --- a/.devcontainer/zshrc +++ b/.devcontainer/zshrc @@ -50,7 +50,7 @@ bindkey "^[[1;5D" backward-word # Settings for the prompt to show that we are in a docker container -export PROMPT="%K{black} 🐋 %K{blue}%F{black}%/ %f%k%F{blue}%f " # Prefix the prompt with DOCKER +export PROMPT="%K{black} 🐋 %K{blue}%F{black} %~ %f%k%F{blue}%f " # Prefix the prompt with DOCKER # >>> bit-bots initialize >>> From e6a35d7fe39eba83c08688ce236aaca4bf520c12 Mon Sep 17 00:00:00 2001 From: texhnolyze Date: Thu, 16 May 2024 19:09:18 +0200 Subject: [PATCH 2/3] feat(devcontainer): use non root user `bitbots` to prevent issues when interacting with the repository both from within the container and outside the container, due to permissions not being correct --- .devcontainer/Dockerfile | 23 +++++++++++++++++------ .devcontainer/devcontainer.json | 4 ++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index f45a47088..5aee3c9db 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,9 @@ FROM ros:iron +ARG user=bitbots +ARG uid=1000 +ARG gid=1000 + # Basic Utilities ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update -y \ @@ -78,18 +82,25 @@ RUN python3 -m pip install \ # Set zsh as default shell SHELL ["/bin/zsh", "-c"] -# Create home directory and colcon workspace -RUN mkdir -p "/root/colcon_ws" +# Create user bitbots with home directory and add to sudo group +RUN useradd -m -U -u "$uid" -G sudo -s /bin/zsh $user \ + && groupmod -g "$gid" $user \ + && echo "$user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +USER $user + +# Create colcon workspace +RUN mkdir -p /home/$user/colcon_ws/src # Install oh-my-zsh for pretty terminal RUN sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" && \ - git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions + git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" -# Add zshrc -COPY zshrc "/root/.zshrc" +# Add zshrc to bitbots home directory +COPY --chown=$user:$user zshrc /home/$user/.zshrc # This is required for sharing Xauthority ENV QT_X11_NO_MITSHM=1 # Switch to the workspace directory -WORKDIR "/root/colcon_ws" +WORKDIR /home/$user/colcon_ws diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d7c87f452..fe8c55aa6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,8 +20,8 @@ } }, - "workspaceMount": "type=bind,source=${localWorkspaceFolder},target=/root/colcon_ws/src/bitbots_main", - "workspaceFolder": "/root/colcon_ws/src/bitbots_main", + "workspaceMount": "type=bind,source=${localWorkspaceFolder},target=/home/bitbots/colcon_ws/src/bitbots_main", + "workspaceFolder": "/home/bitbots/colcon_ws/src/bitbots_main", "mounts": [ "type=bind,source=${localEnv:HOME},target=/srv/host_home,consistency=cached" From a6251c0670ab5c947eba64731d8b17f964e810aa Mon Sep 17 00:00:00 2001 From: texhnolyze Date: Thu, 20 Jun 2024 18:13:18 +0200 Subject: [PATCH 3/3] fix(devcontainer): delete `users` group from container in `Dockerfile`, because the `updateRemoteUserUID` setting of the devcontainer does not change the `GID` of the `containerUser` dynamically to the one of the host user if the group exists in the container already microsoft/vscode-remote-release#2402. In our case the `containerUser` is set to `bitbots`, because it automatically uses the last `USER` instruction from the `Dockerfile` and the `remoteUser` inherits from `containerUser`. For reference see: microsoft/vscode-remote-release#1155 --- .devcontainer/Dockerfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 5aee3c9db..917a89e7c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -82,8 +82,12 @@ RUN python3 -m pip install \ # Set zsh as default shell SHELL ["/bin/zsh", "-c"] -# Create user bitbots with home directory and add to sudo group -RUN useradd -m -U -u "$uid" -G sudo -s /bin/zsh $user \ +# Remove the users group, because when it exists on the host system +# the devcontainer will not dynamically update the containerUser GID, +# when the host user is part of the users group. +# Then create a bitbots user with home directory and add allow it to use sudo +RUN groupdel users \ + && useradd -m -U -u "$uid" -G sudo -s /bin/zsh $user \ && groupmod -g "$gid" $user \ && echo "$user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers