diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..50cc210 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,63 @@ +ARG ROS_DISTRO=humble +FROM ros:$ROS_DISTRO AS base +ARG DEBIAN_FRONTEND=noninteractive + +# Install dependencies +RUN apt-get update && apt-get install -y \ + curl \ + git \ + libclang-dev \ + tmux \ + htop \ + vim \ + python3-pip \ + python3-vcstool \ + bash-completion + +ARG USERNAME=developer +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Create the user +RUN groupadd --gid "$USER_GID" "$USERNAME" \ + && useradd --uid "$USER_UID" --gid "$USER_GID" -m "$USERNAME" \ + # Add sudo support + && apt-get update \ + && apt-get install -y sudo \ + && echo "$USERNAME" ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/"$USERNAME" \ + && chmod 0440 /etc/sudoers.d/"$USERNAME" + +USER $USERNAME + +# Install Rust and the cargo-ament-build plugin +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain 1.74.0 -y +ENV PATH=/home/$USERNAME/.cargo/bin:$PATH +RUN cargo install cargo-ament-build +# Install autocompletion for rustup and cargo +RUN mkdir -p ~/.local/share/bash-completion/completions +RUN rustup completions bash >> ~/.local/share/bash-completion/completions/rustup +RUN rustup completions bash cargo >> ~/.local/share/bash-completion/completions/cargo + +# Install the colcon-cargo and colcon-ros-cargo plugins +RUN pip install git+https://github.com/colcon/colcon-cargo.git git+https://github.com/colcon/colcon-ros-cargo.git + +# Install ros2_rust and its dependencies +RUN mkdir -p /home/"$USERNAME"/ros_deps/src +WORKDIR /home/$USERNAME/ros_deps +RUN git clone https://github.com/ros2-rust/ros2_rust.git src/ros2_rust +RUN vcs import src < src/ros2_rust/ros2_rust_humble.repos +RUN . /opt/ros/humble/setup.sh && colcon build + +RUN echo "source /opt/ros/humble/setup.sh" >> /home/"$USERNAME"/.bashrc +RUN echo "source ~/ros_deps/install/setup.sh" >> /home/"$USERNAME"/.bashrc + +ENV CARGO_TERM_COLOR=always +ENV SHELL /bin/bash + +RUN mkdir -p /home/"$USERNAME"/workspace +WORKDIR /home/$USERNAME/workspace + +COPY --chmod=777 .devcontainer/entrypoint /usr/local/bin/ + +ENTRYPOINT ["bash", "entrypoint"] +CMD ["/bin/bash"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..5fb5357 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,19 @@ +{ + "name": "ROS2 Rust Dev Container", + "remoteUser": "developer", + "build": { + "context": "..", + "dockerfile": "Dockerfile" + }, + "workspaceMount": "source=${localWorkspaceFolder},target=/home/developer/workspace,type=bind", + "workspaceFolder": "/home/developer/workspace", + "overrideCommand": true, + "postStartCommand": "entrypoint", + "customizations": { + "vscode": { + "extensions": [ + "rust-lang.rust-analyzer" + ] + } + } +} diff --git a/.devcontainer/entrypoint b/.devcontainer/entrypoint new file mode 100755 index 0000000..fc613d2 --- /dev/null +++ b/.devcontainer/entrypoint @@ -0,0 +1,9 @@ +#!/bin/bash + +# Build the package mounted in the container +echo "Building workspace with colcon" +. /opt/ros/humble/setup.sh && . ~/ros_deps/install/setup.sh && colcon build +echo "source ~/workspace/install/setup.sh" >> ~/.bashrc + +# Run the CMD (either the default from the Dockerfile or the one provided as docker run argument) +exec "$@" diff --git a/README.md b/README.md index 42b2f63..ef2260d 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,34 @@ Enables `voraus.core` integration within the ROS framework. -## Format the code +## Development + +This repository provides a dev container to streamline the development process. +It offers an environment where all necessary development dependencies are installed and ready-to-use. +If you are using VSCode, the `Dev Containers` extension might be worth a shot. Other editors also have dev container +integrations (NeoVim, IntelliJ, ...). +However, it is still possible to use the dev container using plain docker commands. + +### Build the container + +`docker build -f .devcontainer/Dockerfile -t voraus-ros-bridge-dev .` + +### Run the container + +`docker run --rm -it --volume $(pwd):/home/developer/workspace voraus-ros-bridge-dev` + +### Format the code Run `cargo fmt` -## Analyze the code +### Analyze the code Run `cargo clippy` -## Test the crate +### Test the crate Run `cargo test` -## Build the crate +### Build the crate Run `cargo build`