Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non root devcontainer #458

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -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 >>>

Expand Down
Loading