Skip to content

Commit c180773

Browse files
committed
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
1 parent 4114582 commit c180773

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

.devcontainer/Dockerfile

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
FROM ros:iron
22

3+
ARG user=bitbots
4+
ARG uid=1000
5+
ARG gid=1000
6+
37
# Basic Utilities
48
ENV DEBIAN_FRONTEND=noninteractive
59
RUN apt-get update -y \
@@ -78,18 +82,25 @@ RUN python3 -m pip install \
7882
# Set zsh as default shell
7983
SHELL ["/bin/zsh", "-c"]
8084

81-
# Create home directory and colcon workspace
82-
RUN mkdir -p "/root/colcon_ws"
85+
# Create user bitbots with home directory and add to sudo group
86+
RUN useradd -m -U -u "$uid" -G sudo -s /bin/zsh $user \
87+
&& groupmod -g "$gid" $user \
88+
&& echo "$user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
89+
90+
USER $user
91+
92+
# Create colcon workspace
93+
RUN mkdir -p /home/$user/colcon_ws/src
8394

8495
# Install oh-my-zsh for pretty terminal
8596
RUN sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" && \
86-
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
97+
git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions"
8798

88-
# Add zshrc
89-
COPY zshrc "/root/.zshrc"
99+
# Add zshrc to bitbots home directory
100+
COPY --chown=$user:$user zshrc /home/$user/.zshrc
90101

91102
# This is required for sharing Xauthority
92103
ENV QT_X11_NO_MITSHM=1
93104

94105
# Switch to the workspace directory
95-
WORKDIR "/root/colcon_ws"
106+
WORKDIR /home/$user/colcon_ws

.devcontainer/devcontainer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
}
2121
},
2222

23-
"workspaceMount": "type=bind,source=${localWorkspaceFolder},target=/root/colcon_ws/src/bitbots_main",
24-
"workspaceFolder": "/root/colcon_ws/src/bitbots_main",
23+
"workspaceMount": "type=bind,source=${localWorkspaceFolder},target=/home/bitbots/colcon_ws/src/bitbots_main",
24+
"workspaceFolder": "/home/bitbots/colcon_ws/src/bitbots_main",
2525

2626
"mounts": [
2727
"type=bind,source=${localEnv:HOME},target=/srv/host_home,consistency=cached"

0 commit comments

Comments
 (0)