diff --git a/.devcontainer.json b/.devcontainer.json index 994e6cf..c3a5a4c 100644 --- a/.devcontainer.json +++ b/.devcontainer.json @@ -11,6 +11,7 @@ "--ipc=host", "--privileged" ], + "containerUser": "cev", "containerEnv": { "DISPLAY": "${localEnv:DISPLAY}" }, @@ -20,10 +21,8 @@ "customizations": { "vscode": { "extensions": [ - "ms-iot.vscode-ros", - "ms-vscode.cpptools-extension-pack", "ms-python.black-formatter", - "xaver.clang-format" + "llvm-vs-code-extensions.vscode-clangd" ], "settings": { "terminal.integrated.defaultProfile.linux": "bash", @@ -33,7 +32,7 @@ } }, "[cpp]": { - "editor.defaultFormatter": "xaver.clang-format" + "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd" }, "[python]": { "diffEditor.ignoreTrimWhitespace": false, diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index c3ffaa4..534edf9 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -7,17 +7,28 @@ on: branches: [ "main" ] jobs: - - build: - + build-deploy: runs-on: ubuntu-22.04 - steps: - name: Fetch recursively uses: actions/checkout@v4 with: submodules: recursive fetch-depth: 0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build the Docker image + run: docker build . --file Dockerfile.deploy --tag rc-brain-deploy:$(date +%s) + build-dev: + runs-on: ubuntu-22.04 + steps: + - name: Fetch recursively + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Build the Docker image - run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) + run: docker build . --file Dockerfile.dev --tag rc-brain-dev:$(date +%s) diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 09c2826..0000000 --- a/Dockerfile +++ /dev/null @@ -1,56 +0,0 @@ -# syntax=docker/dockerfile:1.7-labs -FROM ros:humble - -SHELL ["/bin/bash", "-c"] - -# Arguments -ARG FOLDER_NAME=rc-brain -ARG WORKSPACE_DIR=/home/cev - -# Set working directory -WORKDIR $WORKSPACE_DIR - -# Source ROS2 environment automatically in every shell -RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> ~/.bashrc -RUN echo "source $WORKSPACE_DIR/install/setup.bash" >> ~/.bashrc - -# Install dependencies -RUN apt-get update && apt-get install -y \ - curl \ - python3-colcon-common-extensions \ - ros-$ROS_DISTRO-ros-base \ - && apt-get clean && rm -rf /var/lib/apt/lists/* - -# Install clang-format -RUN curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc && \ - echo $'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main\n' \ - $'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main\n' \ - $'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main\n' \ - | tee -a /etc/apt/sources.list && \ - apt-get update && apt-get install -y clang-format clang-format-19 \ - && apt-get clean && rm -rf /var/lib/apt/lists/* - -# Fix libc-bin issue -RUN rm /var/lib/dpkg/info/libc-bin.* || true && apt-get update && apt-get install -y libc-bin - -# Initialize rosdep -RUN rosdep update --rosdistro $ROS_DISTRO - -# Create workspace directory -RUN mkdir -p src/$FOLDER_NAME - -# Copy the full package source code -COPY --parents ./* src/$FOLDER_NAME/ -RUN chmod +x src/$FOLDER_NAME/install.sh && src/$FOLDER_NAME/install.sh - -# Install package dependencies -RUN source /opt/ros/$ROS_DISTRO/setup.bash && rosdep install --from-paths src -r -y - -# Build the ROS2 workspace -RUN source /opt/ros/$ROS_DISTRO/setup.bash && colcon build --symlink-install - -# Set up entrypoint -COPY entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/Dockerfile.deploy b/Dockerfile.deploy index 03d49f2..0b8f613 100644 --- a/Dockerfile.deploy +++ b/Dockerfile.deploy @@ -3,6 +3,17 @@ FROM ros:humble SHELL ["/bin/bash", "-c"] +# Set up CEV user +RUN useradd -m -s /bin/bash cev +RUN usermod -aG sudo cev +# Grant passwordless sudo access to the 'sudo' group +RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +USER cev + +# Docker doesn't do this by default +RUN sudo chown -R cev /home/cev + + ARG FOLDER_NAME=rc-brain ARG WORKSPACE_DIR=/home/cev WORKDIR $WORKSPACE_DIR @@ -12,36 +23,31 @@ RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> ~/.bashrc RUN echo "source $WORKSPACE_DIR/install/setup.bash" >> ~/.bashrc # Init rosdep and update package index -# for some reason we need to do this -RUN rm /var/lib/dpkg/info/libc-bin.* -RUN apt-get clean -RUN apt-get update -RUN apt-get install libc-bin +RUN sudo apt-get update RUN rosdep update --rosdistro $ROS_DISTRO -RUN mkdir -p src/$FOLDER_NAME - # Install and build build-from-source packages # We do this as a separate step from the stuff for our code, since that changes more frequently -RUN cd src && \ - git clone https://github.com/Slamtec/sllidar_ros2.git && \ - cd sllidar_ros2 && \ - git checkout 3430009 +COPY --chown=cev --parents external/**/package.xml src/$FOLDER_NAME/ RUN source /opt/ros/$ROS_DISTRO/setup.bash && rosdep install --from-paths src -r -y -RUN source /opt/ros/$ROS_DISTRO/setup.bash && colcon build -# Install self dependencies with rosdep -COPY --parents ./*/package.xml src/$FOLDER_NAME +# Run install_extra.sh, which installs additional dependencies +COPY --chown=cev scripts/install_extra.sh src/$FOLDER_NAME/scripts/ +RUN sudo src/$FOLDER_NAME/scripts/install_extra.sh + +# Finally build external packages +COPY --chown=cev external src/$FOLDER_NAME/external/ +RUN source /opt/ros/$ROS_DISTRO/setup.bash && colcon build --symlink-install + +# Install all other dependencies +COPY --chown=cev --parents **/package.xml src/$FOLDER_NAME/ RUN source /opt/ros/$ROS_DISTRO/setup.bash && rosdep install --from-paths src -r -y # Clean up apt cache to make container smaller -RUN apt-get clean +RUN sudo apt-get clean # Build -COPY . src/$FOLDER_NAME -RUN source /opt/ros/$ROS_DISTRO/setup.bash && colcon build +COPY --chown=cev . src/$FOLDER_NAME +RUN source /opt/ros/$ROS_DISTRO/setup.bash && colcon build --symlink-install -# Copy entrypoint script -COPY entrypoint.sh entrypoint.sh -RUN chmod +x entrypoint.sh -ENTRYPOINT ["/bin/bash", "/home/cev/entrypoint.sh"] +ENTRYPOINT ["/bin/bash", "/home/cev/src/rc-brain/scripts/deployed_entrypoint.sh"] diff --git a/Dockerfile.dev b/Dockerfile.dev index 795e722..833878c 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -3,44 +3,44 @@ FROM ros:humble SHELL ["/bin/bash", "-c"] +# Set up CEV user +RUN useradd -m -s /bin/bash cev +RUN usermod -aG sudo cev +# Grant passwordless sudo access to the 'sudo' group +RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +USER cev + ARG FOLDER_NAME=rc-brain ARG WORKSPACE_DIR=/home/cev WORKDIR $WORKSPACE_DIR +# Docker doesn't do this by default +RUN sudo chown -R cev /home/cev + # Source the ROS2 environment automatically when a new shell is created RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> ~/.bashrc RUN echo "source $WORKSPACE_DIR/install/setup.bash" >> ~/.bashrc # Install dev tools -RUN apt-get update -RUN apt-get install -y curl -RUN curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc -RUN cat /etc/apt/trusted.gpg.d/apt.llvm.org.asc -RUN echo $'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main\n' \ - $'deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy main\n' \ - $'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main\n' \ - $'deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main\n' \ - $'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main\n' \ - $'deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main\n' \ - | tee -a /etc/apt/sources.list -RUN apt-get update -RUN apt-get install -y clang-format clang-format-19 +RUN sudo apt-get update +# Tools required to run clang install +RUN sudo apt-get install -y \ + curl \ + lsb-release \ + software-properties-common \ + gnupg +RUN curl -fsSL https://apt.llvm.org/llvm.sh | sudo bash -s -- 19 +RUN sudo apt-get install -y clangd-19 +RUN sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-19 100 # Init rosdep and update package index -# for some reason we need to do this -RUN rm /var/lib/dpkg/info/libc-bin.* -RUN apt-get clean -RUN apt-get update -RUN apt-get install -y libc-bin RUN rosdep update --rosdistro $ROS_DISTRO -RUN mkdir -p src/$FOLDER_NAME - -# Copy install.sh -COPY --parents ./install.sh src/$FOLDER_NAME - -# Run install.sh -RUN src/$FOLDER_NAME/install.sh +# Run install_extra.sh, which installs additional dependencies +COPY --chown=cev scripts/install_extra.sh src/$FOLDER_NAME/scripts/ +RUN sudo src/$FOLDER_NAME/scripts/install_extra.sh -COPY --parents ./*/package.xml src/$FOLDER_NAME +# Install own dependencies +RUN mkdir -p src/$FOLDER_NAME +COPY --chown=cev --parents **/package.xml src/$FOLDER_NAME/ RUN source /opt/ros/$ROS_DISTRO/setup.bash && rosdep install --from-paths src -r -y diff --git a/README.md b/README.md index 4fc738c..740fe91 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,9 @@ # rc-brain One repo to rule them all -## Installation +## Installation (local) `git clone --recurse-submodules https://github.com/cornellev/rc-brain.git` -`cd rc-brain && sudo ./install.sh` - -## Docker -`docker build -t cev-rc-autonomy .` -Then run either -`docker run --rm ros2-autonomy launch` -or -`docker run --rm ros2-autonomy teleop` +`cd rc-brain && sudo ./scripts/install_extra.sh` ## Development @@ -21,12 +14,25 @@ Run `./scripts/deploy/arduino_deploy.sh` to compile and flash code to the arduin #### Formatting If you're not using the DevContainer, please make sure to install `clang-format`, ideally version 19! This will help keep the formatting of our C++ code formatted consistently. Python code is formatted by `black`. The DevContainer will install the `Black` extension for you, which ships with `black`, but otherwise you'll need to install it in VSCode or whatever other IDE you're using. +### Docker (DevContainer) +Everything should pretty much work out of the box, except... +> [!WARNING] +> You must have the Docker buildx plugin installed to build the image correctly. You may get very confusing failures! +> On Ubuntu, you can install the `docker-buildx-plugin` package. + ### Deployment #### Regular deployment If you're just developing, building Docker images will probably take too long. You can deploy normally just by running `scripts/deploy.sh`. It will drop you into an interactive session at the end so you can launch whatever you want to. #### Docker deployment +Use `docker build . --file Dockerfile.deploy -t rc-brain-deploy:latest` to build the deploy container. +Then run either `docker run --rm rc-brain-deploy launch` or `docker run --rm rc-brain-deploy teleop` to launch. + +> [!WARNING] +> You must have the Docker buildx plugin installed to build the image correctly. You may get very confusing failures! +> On Ubuntu, you can install the `docker-buildx-plugin` package. + Our Docker deployment pipeline works by pushing Docker images to a local registry and pulling them down on the mini cars. This avoids both long build times on the mini cars and the long time it takes to transfer whole images (as we can take advantage of Docker's cache). You'll have to do a bit of setup to get your computer to use the local registry. Note that you must be connected to `cev-router`. diff --git a/cev/cev_planner_ros2 b/cev/cev_planner_ros2 index 098009a..090d71d 160000 --- a/cev/cev_planner_ros2 +++ b/cev/cev_planner_ros2 @@ -1 +1 @@ -Subproject commit 098009a81c3fcbf9815d64897482e08933ad1c34 +Subproject commit 090d71db71894ccb9ab6d4725facf5ac830880f1 diff --git a/install.sh b/install.sh deleted file mode 100755 index 757e3eb..0000000 --- a/install.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -apt install -y \ - libeigen3-dev \ - libnlopt-dev \ - libnlopt-cxx-dev \ - libopencv-dev \ - libyaml-cpp-dev \ - libqt5serialport5-dev \ - libsuitesparse-dev \ - libceres-dev \ - ros-humble-slam-toolbox diff --git a/entrypoint.sh b/scripts/deployed_entrypoint.sh similarity index 100% rename from entrypoint.sh rename to scripts/deployed_entrypoint.sh diff --git a/scripts/install_extra.sh b/scripts/install_extra.sh new file mode 100755 index 0000000..6a58aec --- /dev/null +++ b/scripts/install_extra.sh @@ -0,0 +1,11 @@ +#!/bin/bash +apt-get install -y \ + libeigen3-dev \ + libnlopt-dev \ + libnlopt-cxx-dev \ + libopencv-dev \ + libyaml-cpp-dev \ + libqt5serialport5-dev \ + libsuitesparse-dev \ + libceres-dev \ + ros-humble-slam-toolbox