diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index f45a47088..917a89e7c 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,29 @@ 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" +# 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 + +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" 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 >>>