Skip to content

Instantly share code, notes, and snippets.

@zflat
Last active January 26, 2024 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zflat/445b2ef3427dd947e2a3d46b61420b9b to your computer and use it in GitHub Desktop.
Save zflat/445b2ef3427dd947e2a3d46b61420b9b to your computer and use it in GitHub Desktop.
devcontainer template for ros2 colcon workspace
  • Create a directory for your new workspace
    mkdir dev_ros2
    cd dev_ros2
  • Download the zip and extract inside your workspace directory as .devcontainer
    wget -qO- https://gist.github.com/zflat/445b2ef3427dd947e2a3d46b61420b9b/archive/main.tar.gz | tar -xz --transform "s/^445b2e.*main/.devcontainer/"
  • Create the workspace volume. Run from the root of your workspace:
    docker volume create "$(basename $(pwd))_colcon_ws_volume"
  • Clone repositories into the workspace
  • Run and attach to the devcontainer
    devcontainer up --workspace-folder .
    devcontainer exec --workspace-folder . bash
#!/bin/bash
mkdir -p /opt/colcon_ws/src
ln -sf $CONTAINER_WS_DIR /opt/colcon_ws/src/
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// examples at: https://github.com/devcontainers/templates
{
"name": "${localWorkspaceFolderBasename}-dev",
"runArgs": [
"--name=${localWorkspaceFolderBasename}-dev",
"--workdir=/opt/colcon_ws"
],
"build": {
"dockerfile": "Dockerfile"
},
"containerEnv": {
"CONTAINER_WS_DIR": "${containerWorkspaceFolder}"
},
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "/tmp/create_workspace.sh",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
"mounts": [
"source=${localWorkspaceFolderBasename}_colcon_ws_volume,target=/opt/colcon_ws,type=volume,consistency=cached"
]
}
FROM osrf/ros:rolling-desktop-full
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
byobu \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
COPY ./create_workspace.sh /tmp/
RUN chmod +x /tmp/create_workspace.sh
RUN echo "alias ws='cd /opt/colcon_ws && [ -e /opt/colcon_ws/install/setup.bash ] && . /opt/colcon_ws/install/setup.bash'" >> /root/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment