roboticswithjulia / ros2_rust_workshop

Workshop to learn how to develop ROS2 applications using the Rust language
4 stars 0 forks source link

Devcontainer con user instrucciones #2

Open awesomebytes opened 3 days ago

awesomebytes commented 3 days ago

Necesitarias anyadir algo como:

ARG CONTAINER_USER="cuser"
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create a user in the container to operate as unprivileged
RUN groupadd --gid $USER_GID $CONTAINER_USER \
    && useradd --uid $USER_UID --gid $USER_GID -m $CONTAINER_USER \
    && mkdir -p /home/$CONTAINER_USER
RUN apt-get update \
    && apt-get install -y sudo \
    && rm -rf /var/lib/apt/lists/* \
    && echo $CONTAINER_USER ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$CONTAINER_USER \
    && chmod 0440 /etc/sudoers.d/$CONTAINER_USER

No es necesario pero yo suelo pasar a usar bash en el Docker/Dockerfile:

# Use to get a shell with color support and additional bashrc goodies
SHELL ["/bin/bash", "--login", "-c"]

En el devcontainer.json:

    "remoteUser": "cuser",

No es necesario pero yo suelo forzar:

    "containerEnv": {
        // Convenience, for shell colors, aliases, etc
        "SHELL": "/bin/bash"
    },

Luego el tema es instalar cargo, y cualquier cosa de usuario final, con el user hecho antes, por ejemplo, para usar uv yo tengo en Dockerfile:

# Install uv
ARG VENV_NAME=vpy3.12
USER $CONTAINER_USER
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/home/${CONTAINER_USER}/.cargo/bin:$PATH"
# Create a system venv to use from now on
RUN uv venv /home/${CONTAINER_USER}/$VENV_NAME -p 3.12
# Use the virtual environment automatically
ENV VIRTUAL_ENV=/home/${CONTAINER_USER}/$VENV_NAME
# Place entry points in the environment at the front of the path
ENV PATH="/home/${CONTAINER_USER}/$VENV_NAME/bin:$PATH"
RUN uv python install 3.12
# Tooling + necessary to run rospy
RUN uv pip install ipython rospkg empy