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

chore: Add dev container #10

Merged
merged 2 commits into from
Jul 3, 2024
Merged
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
63 changes: 63 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 19 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
9 changes: 9 additions & 0 deletions .devcontainer/entrypoint
Original file line number Diff line number Diff line change
@@ -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 "$@"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
.cargo/
target/

# Colcon
build/
install/
log/

# IDE
.idea/
.vscode/
Expand Down
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`