├── .github ├── dependabot.yml └── workflows │ ├── test-noetic.yml │ ├── test-melodic.yml │ ├── deploy-noetic.yml │ ├── deploy-melodic.yml │ └── update-trivy-cache.yaml ├── README.md ├── LICENSE ├── run.sh ├── kinetic ├── Dockerfile └── ros_entrypoint.sh ├── melodic ├── Dockerfile └── ros_entrypoint.sh └── noetic ├── Dockerfile └── ros_entrypoint.sh /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Maintain dependencies for GitHub Actions 4 | - package-ecosystem: "github-actions" 5 | directory: "/" 6 | schedule: 7 | interval: "daily" 8 | - package-ecosystem: "docker" 9 | directory: "/melodic" 10 | schedule: 11 | interval: "daily" 12 | - package-ecosystem: "docker" 13 | directory: "/noetic" 14 | schedule: 15 | interval: "daily" 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-ros 2 | 3 | Dockerfiles of ROS to use with osrf/rocker 4 | 5 | ## Usage (with osrf/rocker) 6 | 7 | Noetic (without NVIDIA GPU) 8 | 9 | ``` 10 | rocker --x11 --user --network=host --privileged --volume ~/catkin_ws -- tiryoh/ros:noetic 11 | ``` 12 | 13 | 14 | Noetic (with NVIDIA GPU) 15 | 16 | ``` 17 | rocker --x11 --nvidia --user --network=host --privileged --volume ~/catkin_ws -- tiryoh/ros:noetic 18 | ``` 19 | 20 | ## Usage (without osrf/rocker) 21 | 22 | ``` 23 | ROS_DISTRO=noetic ./run.sh 24 | ``` 25 | -------------------------------------------------------------------------------- /.github/workflows/test-noetic.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test (Noetic) 2 | on: 3 | pull_request: 4 | branches: 5 | - main 6 | paths: 7 | - "noetic/**" 8 | - ".github/workflows/test-noetic.yml" 9 | schedule: 10 | - cron: "0 2 * * 0" # Weekly on Sundays at 02:00 11 | workflow_dispatch: 12 | 13 | env: 14 | DOCKER_USERNAME: tiryoh 15 | DOCKER_IMAGENAME: ros 16 | 17 | jobs: 18 | build: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | arch: [arm64, amd64] 23 | runs-on: ubuntu-latest 24 | timeout-minutes: 120 25 | steps: 26 | - uses: actions/checkout@v4 27 | with: 28 | fetch-depth: 0 29 | submodules: true 30 | - uses: Tiryoh/docker-ros2-desktop-vnc/.github/actions/test@master 31 | with: 32 | ros-distro: noetic 33 | arch: ${{ matrix.arch }} 34 | -------------------------------------------------------------------------------- /.github/workflows/test-melodic.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test (Melodic) 2 | on: 3 | pull_request: 4 | branches: 5 | - main 6 | paths: 7 | - "melodic/**" 8 | - ".github/workflows/test-melodic.yml" 9 | schedule: 10 | - cron: "0 2 * * 0" # Weekly on Sundays at 02:00 11 | workflow_dispatch: 12 | 13 | env: 14 | DOCKER_USERNAME: tiryoh 15 | DOCKER_IMAGENAME: ros 16 | 17 | jobs: 18 | build: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | arch: [arm64, amd64] 23 | runs-on: ubuntu-latest 24 | timeout-minutes: 120 25 | steps: 26 | - uses: actions/checkout@v4 27 | with: 28 | fetch-depth: 0 29 | submodules: true 30 | - uses: Tiryoh/docker-ros2-desktop-vnc/.github/actions/test@master 31 | with: 32 | ros-distro: melodic 33 | arch: ${{ matrix.arch }} 34 | -------------------------------------------------------------------------------- /.github/workflows/deploy-noetic.yml: -------------------------------------------------------------------------------- 1 | name: Publish to Registry (Noetic) 2 | on: 3 | push: 4 | branches: 5 | - main 6 | paths: 7 | - "noetic/**" 8 | - ".github/workflows/deploy-noetic.yml" 9 | schedule: 10 | - cron: "7 4 * * 0" # Weekly on Sundays at 13:07 (JST) 11 | workflow_dispatch: 12 | 13 | env: 14 | DOCKER_USERNAME: tiryoh 15 | DOCKER_IMAGENAME: ros 16 | GIT_CONFIG_USER: Tiryoh@GitHubActions 17 | GIT_CONFIG_EMAIL: tiryoh@gmail.com 18 | 19 | jobs: 20 | build-and-deploy: 21 | runs-on: ubuntu-latest 22 | timeout-minutes: 120 23 | steps: 24 | - uses: actions/checkout@v4 25 | with: 26 | fetch-depth: 0 27 | submodules: true 28 | - uses: Tiryoh/docker-ros2-desktop-vnc/.github/actions/deploy@master 29 | with: 30 | ros-distro: noetic 31 | latest: false 32 | gha-job-name: build-and-deploy 33 | dockerhub-token: ${{ secrets.DOCKERHUB_TOKEN }} 34 | github-token: ${{ secrets.GITHUB_TOKEN }} 35 | -------------------------------------------------------------------------------- /.github/workflows/deploy-melodic.yml: -------------------------------------------------------------------------------- 1 | name: Publish to Registry (Melodic) 2 | on: 3 | push: 4 | branches: 5 | - main 6 | paths: 7 | - "melodic/**" 8 | - ".github/workflows/deploy-melodic.yml" 9 | schedule: 10 | - cron: "7 4 * * 0" # Weekly on Sundays at 13:07 (JST) 11 | workflow_dispatch: 12 | 13 | env: 14 | DOCKER_USERNAME: tiryoh 15 | DOCKER_IMAGENAME: ros 16 | GIT_CONFIG_USER: Tiryoh@GitHubActions 17 | GIT_CONFIG_EMAIL: tiryoh@gmail.com 18 | 19 | jobs: 20 | build-and-deploy: 21 | runs-on: ubuntu-latest 22 | timeout-minutes: 120 23 | steps: 24 | - uses: actions/checkout@v4 25 | with: 26 | fetch-depth: 0 27 | submodules: true 28 | - uses: Tiryoh/docker-ros2-desktop-vnc/.github/actions/deploy@master 29 | with: 30 | ros-distro: melodic 31 | latest: false 32 | gha-job-name: build-and-deploy 33 | dockerhub-token: ${{ secrets.DOCKERHUB_TOKEN }} 34 | github-token: ${{ secrets.GITHUB_TOKEN }} 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-2024 Daisuke Sato 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | ROS_DISTRO=${ROS_DISTRO:-noetic} 5 | DOCKER_IMAGE_NAME="tiryoh/ros:${ROS_DISTRO}" 6 | DEFAULT_SHELL=bash 7 | DEFAULT_USER=ubuntu 8 | DEFAULT_SHELL="/bin/bash" 9 | # DEFAULT_SHELL="/usr/bin/zsh" 10 | 11 | # ディレクトリへの絶対パスが異なる場合は別の名前でコンテナを立ち上げる(共有PCや異なるROSDistroでの利用を想定) 12 | command -v crc32 >/dev/null || { echo ERROR: crc32 command not found. Try "sudo apt-get update && sudo apt-get install -y libarchive-zip-perl"; exit 1; } 13 | CONTAINER_NAME="ros_${ROS_DISTRO}_$(crc32 <(echo "${WS_ROOT_DIR}"))" 14 | 15 | # コンテナがすでに起動しているかどうか確認 16 | if docker ps -a | grep -q "${CONTAINER_NAME}"; then 17 | echo Found container: "${CONTAINER_NAME}" 18 | # 引数が何もなければshellをインタラクティブモードで起動する 19 | if [ "$#" == 0 ]; then 20 | docker exec -it "${CONTAINER_NAME}" "${DEFAULT_SHELL}" 21 | else 22 | docker exec -it "${CONTAINER_NAME}" "$@" 23 | fi 24 | 25 | else 26 | if [ "$#" == 0 ]; then 27 | CMD="${DEFAULT_SHELL}" 28 | else 29 | CMD="$@" 30 | fi 31 | echo Starting container: "${CONTAINER_NAME}" 32 | # コンテナが起動していなければ、新規に立ち上げる 33 | docker run --rm -it \ 34 | --privileged \ 35 | --ipc=host \ 36 | --net=host \ 37 | --name "${CONTAINER_NAME}" \ 38 | -e CONTAINER_NAME="${CONTAINER_NAME}" \ 39 | -e DISPLAY \ 40 | -e TERM=xterm-256color \ 41 | -e DISPLAY \ 42 | -e DEFAULT_SHELL \ 43 | -e DEFAULT_USER \ 44 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 45 | -v /etc/localtime:/etc/localtime:ro \ 46 | -v /etc/timezone:/etc/timezone:ro \ 47 | -v "${HOME}/.local/share/fonts:/home/${USER}/.local/share/fonts" \ 48 | -v "${HOME}/catkin_ws/src:/ws" \ 49 | "${DOCKER_IMAGE_NAME}" \ 50 | "${CMD}" 51 | fi 52 | -------------------------------------------------------------------------------- /.github/workflows/update-trivy-cache.yaml: -------------------------------------------------------------------------------- 1 | # Note: This workflow only updates the cache. You should create a separate workflow for your actual Trivy scans. 2 | # In your scan workflow, set TRIVY_SKIP_DB_UPDATE=true and TRIVY_SKIP_JAVA_DB_UPDATE=true. 3 | name: Update Trivy Cache 4 | 5 | on: 6 | schedule: 7 | - cron: '30 1 * * *' # Run daily at midnight UTC 8 | workflow_dispatch: # Allow manual triggering 9 | 10 | jobs: 11 | update-trivy-db: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Setup oras 15 | uses: oras-project/setup-oras@v1 16 | 17 | - name: Get current date 18 | id: date 19 | run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT 20 | 21 | - name: Download and extract the vulnerability DB 22 | run: | 23 | mkdir -p "$GITHUB_WORKSPACE/.cache/trivy/db" 24 | if ! (oras pull ghcr.io/aquasecurity/trivy-db:2 || oras pull ghcr.io/tiryoh/aquasecurity/trivy-db:2); then 25 | echo "Failed to pull database" >&2 26 | exit 1 27 | fi 28 | if ! tar -xzf db.tar.gz -C "$GITHUB_WORKSPACE/.cache/trivy/db"; then 29 | echo "Failed to extract database" >&2 30 | exit 1 31 | fi 32 | rm db.tar.gz 33 | - name: Download and extract the Java DB 34 | run: | 35 | mkdir -p "$GITHUB_WORKSPACE/.cache/trivy/java-db" 36 | if ! (oras pull ghcr.io/aquasecurity/trivy-java-db:1 || oras pull ghcr.io/tiryoh/aquasecurity/trivy-java-db:1); then 37 | echo "Failed to pull Java database" >&2 38 | exit 1 39 | fi 40 | if ! tar -xzf javadb.tar.gz -C "$GITHUB_WORKSPACE/.cache/trivy/java-db"; then 41 | echo "Failed to extract Java database" >&2 42 | exit 1 43 | fi 44 | rm javadb.tar.gz 45 | - name: Cache DBs 46 | uses: actions/cache/save@v4 47 | with: 48 | path: ${{ github.workspace }}/.cache/trivy 49 | key: cache-trivy-${{ steps.date.outputs.date }} 50 | -------------------------------------------------------------------------------- /kinetic/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial-20210804 AS builder 2 | RUN apt-get update 3 | RUN apt-get install -y curl 4 | RUN apt-get install -y --no-install-recommends gcc libc-dev 5 | RUN curl -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa/su-exec/master/su-exec.c 6 | RUN gcc -Wall /usr/local/bin/su-exec.c -o/usr/local/bin/su-exec 7 | RUN chown root:root /usr/local/bin/su-exec 8 | RUN chmod 0755 /usr/local/bin/su-exec 9 | 10 | FROM ubuntu:xenial-20210804 11 | LABEL maintainer="Daisuke Sato " 12 | 13 | COPY --from=builder /usr/local/bin/su-exec /sbin/ 14 | RUN apt-get update -q && \ 15 | apt-get upgrade -yq && \ 16 | DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends keyboard-configuration language-pack-en && \ 17 | DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends wget curl git build-essential ca-certificates tzdata tmux gnupg2 \ 18 | vim sudo lsb-release locales bash-completion zsh iproute2 iputils-ping net-tools dnsutils terminator && \ 19 | rm -rf /var/lib/apt/lists/* 20 | ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 21 | RUN locale-gen en_US.UTF-8 22 | RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu xenial main" > /etc/apt/sources.list.d/ros-latest.list' 23 | RUN curl -k https://raw.githubusercontent.com/ros/rosdistro/master/ros.key | sudo apt-key add - 24 | RUN apt-get update -q && \ 25 | apt-get install -y --no-install-recommends ros-kinetic-desktop-full python-rosdep &&\ 26 | apt-get install -y --no-install-recommends python-rosinstall python-rosinstall-generator python-wstool build-essential python-catkin-tools python3-vcstool &&\ 27 | apt-get install -y --no-install-recommends ros-kinetic-teleop-twist-keyboard &&\ 28 | rm -rf /var/lib/apt/lists/* 29 | RUN rosdep init && rosdep update --include-eol-distros 30 | RUN echo -e "\n\ 31 | echo 'Sourcing ROS 1 packages...'\n\ 32 | source /opt/ros/\${ROS_DISTRO}/setup.bash\n\ 33 | if [ -e \${HOME}/catkin_ws/devel/setup.bash ]; then\n\ 34 | source \${HOME}/catkin_ws/devel/setup.bash\n\ 35 | fi\n\ 36 | export PS1=\"(\$CONTAINER_NAME)\n\$PS1\"\n\ 37 | " >> $HOME/.bashrc 38 | COPY ./ros_entrypoint.sh / 39 | ENTRYPOINT ["/ros_entrypoint.sh"] 40 | CMD ["/bin/bash"] 41 | -------------------------------------------------------------------------------- /melodic/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:bionic-20230530 AS builder 2 | RUN apt-get update 3 | RUN apt-get install -y curl 4 | RUN apt-get install -y --no-install-recommends gcc libc-dev 5 | RUN curl -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa/su-exec/master/su-exec.c 6 | RUN gcc -Wall /usr/local/bin/su-exec.c -o/usr/local/bin/su-exec 7 | RUN chown root:root /usr/local/bin/su-exec 8 | RUN chmod 0755 /usr/local/bin/su-exec 9 | 10 | FROM ubuntu:bionic-20230530 11 | LABEL maintainer="Daisuke Sato " 12 | 13 | COPY --from=builder /usr/local/bin/su-exec /sbin/ 14 | RUN apt-get update -q && \ 15 | apt-get upgrade -yq && \ 16 | DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends keyboard-configuration language-pack-en && \ 17 | DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends wget curl git build-essential ca-certificates tzdata tmux gnupg2 \ 18 | vim sudo lsb-release locales bash-completion zsh iproute2 iputils-ping net-tools dnsutils terminator && \ 19 | rm -rf /var/lib/apt/lists/* 20 | ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 21 | RUN locale-gen en_US.UTF-8 22 | RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu bionic main" > /etc/apt/sources.list.d/ros-latest.list' 23 | RUN curl -k https://raw.githubusercontent.com/ros/rosdistro/master/ros.key | sudo apt-key add - 24 | RUN apt-get update -q && \ 25 | apt-get install -y --no-install-recommends ros-melodic-desktop-full python-rosdep &&\ 26 | apt-get install -y --no-install-recommends python-rosinstall python-rosinstall-generator python-wstool python-catkin-tools python3-vcstool &&\ 27 | apt-get install -y --no-install-recommends ros-melodic-teleop-twist-keyboard &&\ 28 | rm -rf /var/lib/apt/lists/* 29 | RUN apt-get update -q && \ 30 | apt-get install -y --no-install-recommends python-pip && \ 31 | rm -rf /var/lib/apt/lists/* && \ 32 | pip install --no-cache importlib_metadata 33 | RUN rosdep init && rosdep update --include-eol-distros 34 | RUN echo -e "\n\ 35 | echo 'Sourcing ROS 1 packages...'\n\ 36 | source /opt/ros/\${ROS_DISTRO}/setup.bash\n\ 37 | if [ -e \${HOME}/catkin_ws/devel/setup.bash ]; then\n\ 38 | source \${HOME}/catkin_ws/devel/setup.bash\n\ 39 | fi\n\ 40 | export PS1=\"(\$CONTAINER_NAME)\n\$PS1\"\n\ 41 | " >> $HOME/.bashrc 42 | COPY ./ros_entrypoint.sh / 43 | ENTRYPOINT ["/ros_entrypoint.sh"] 44 | CMD ["/bin/bash"] 45 | -------------------------------------------------------------------------------- /noetic/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:focal-20241011 AS builder 2 | RUN apt-get update 3 | RUN apt-get install -y curl 4 | RUN apt-get install -y --no-install-recommends gcc libc-dev 5 | RUN curl -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa/su-exec/master/su-exec.c 6 | RUN gcc -Wall /usr/local/bin/su-exec.c -o/usr/local/bin/su-exec 7 | RUN chown root:root /usr/local/bin/su-exec 8 | RUN chmod 0755 /usr/local/bin/su-exec 9 | 10 | FROM ubuntu:focal-20241011 11 | LABEL maintainer="Daisuke Sato " 12 | 13 | COPY --from=builder /usr/local/bin/su-exec /sbin/ 14 | RUN apt-get update -q && \ 15 | apt-get upgrade -yq && \ 16 | DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends keyboard-configuration language-pack-en && \ 17 | DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends wget curl git build-essential ca-certificates tzdata tmux gnupg2 \ 18 | vim sudo lsb-release locales bash-completion zsh iproute2 iputils-ping net-tools dnsutils terminator && \ 19 | rm -rf /var/lib/apt/lists/* 20 | ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 21 | RUN locale-gen en_US.UTF-8 22 | RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu focal main" > /etc/apt/sources.list.d/ros-latest.list' 23 | RUN curl -k https://raw.githubusercontent.com/ros/rosdistro/master/ros.key | sudo apt-key add - 24 | RUN apt-get update -q && \ 25 | apt-get install -y --no-install-recommends ros-noetic-desktop-full python3-rosdep &&\ 26 | apt-get install -y --no-install-recommends python3-rosinstall python3-rosinstall-generator python3-wstool python3-catkin-tools python3-osrf-pycommon python3-vcstool &&\ 27 | apt-get install -y --no-install-recommends ros-noetic-teleop-twist-keyboard &&\ 28 | rm -rf /var/lib/apt/lists/* 29 | RUN rosdep init && rosdep update --include-eol-distros 30 | # install the latest intel media driver to use GPU 31 | # Avoid libGL error: failed to create dri screen 32 | # https://bugs.launchpad.net/ubuntu/+source/intel-media-driver/+bug/2004237 33 | RUN apt-get update && \ 34 | apt-get install -y software-properties-common && \ 35 | add-apt-repository ppa:kisak/kisak-mesa && \ 36 | apt-get update && \ 37 | apt-get upgrade -y && \ 38 | apt-get install -y libegl-mesa0 && \ 39 | rm -rf /var/lib/apt/lists/* 40 | RUN echo -e "\n\ 41 | echo 'Sourcing ROS 1 packages...'\n\ 42 | source /opt/ros/\${ROS_DISTRO}/setup.bash\n\ 43 | if [ -e \${HOME}/catkin_ws/devel/setup.bash ]; then\n\ 44 | source \${HOME}/catkin_ws/devel/setup.bash\n\ 45 | fi\n\ 46 | export PS1=\"(\$CONTAINER_NAME)\n\$PS1\"\n\ 47 | " >> $HOME/.bashrc 48 | COPY ./ros_entrypoint.sh / 49 | ENTRYPOINT ["/ros_entrypoint.sh"] 50 | CMD ["/bin/bash"] 51 | -------------------------------------------------------------------------------- /kinetic/ros_entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | DEFAULT_USER=${DEFAULT_USER:-'ubuntu'} 5 | DEFAULT_USER_UID=${USER_UID:-'1000'} 6 | DEFAULT_USER_GID=${USER_GID:-'1000'} 7 | NOPASSWD=${NOPASSWD:-''} # set 'NOPASSWD:' to disable asking sudo password 8 | BUILD_TOOL=${BUILD_TOOL:-'catkin-tools'} 9 | 10 | # override if $USER env exists 11 | if [[ ! -z "$USER" ]]; then 12 | DEFAULT_USER=$USER 13 | fi 14 | 15 | if [[ $(id -u) -eq 0 ]]; then 16 | EXEC="exec /sbin/su-exec ${DEFAULT_USER}" 17 | 18 | # if the user does not exist, create user 19 | if [[ $(id -u ${DEFAULT_USER} 2> /dev/null) != ${DEFAULT_USER_UID} ]]; then 20 | echo creating user ${DEFAULT_USER} 21 | groupadd -g "${DEFAULT_USER_GID}" "${DEFAULT_USER}" 22 | useradd --create-home --home-dir /home/${DEFAULT_USER} --uid ${DEFAULT_USER_UID} --shell /bin/bash \ 23 | --gid ${DEFAULT_USER_GID} --groups sudo ${DEFAULT_USER} 24 | echo "${DEFAULT_USER}:${DEFAULT_USER}" | chpasswd && \ 25 | echo "${DEFAULT_USER} ALL=(ALL) ${NOPASSWD}ALL" >> /etc/sudoers 26 | touch /home/${DEFAULT_USER}/.sudo_as_admin_successful 27 | fi 28 | 29 | # mount develop workspace 30 | if [ -e /ws ]; then 31 | mkdir -p /home/${DEFAULT_USER}/catkin_ws 32 | ln -s /ws /home/${DEFAULT_USER}/catkin_ws/src 33 | fi 34 | 35 | # setup ros environment 36 | if [[ "$BUILD_TOOL" == "catkin_make" ]]; then 37 | touch /home/${DEFAULT_USER}/.bash_aliases 38 | echo "function catkin_make(){(cd ~/catkin_ws && command catkin_make \$@) && source ~/catkin_ws/devel/setup.bash;}" >> /home/${DEFAULT_USER}/.bash_aliases 39 | mkdir -p /home/${DEFAULT_USER}/catkin_ws/src \ 40 | && /bin/bash -c ". /opt/ros/noetic/setup.bash; catkin_init_workspace /home/${DEFAULT_USER}/catkin_ws/src" > /dev/null 41 | echo 'source /opt/ros/noetic/setup.bash' >> /home/${DEFAULT_USER}/.bashrc 42 | fi 43 | if [[ "$BUILD_TOOL" == "catkin-tools" ]]; then 44 | mkdir -p /home/${DEFAULT_USER}/catkin_ws/src \ 45 | && /bin/bash -c "cd /home/${DEFAULT_USER}/catkin_ws;. /opt/ros/noetic/setup.bash; catkin init" > /dev/null 46 | echo 'source /opt/ros/noetic/setup.bash' >> /home/${DEFAULT_USER}/.bashrc 47 | echo 'source `catkin locate --shell-verbs`' >> /home/${DEFAULT_USER}/.bashrc 48 | fi 49 | 50 | if [ ! -e /home/${DEFAULT_USER}/.config/terminator/config ]; then 51 | # Avoid org.freedesktop.DBus.Error.Spawn.ExecFailed 52 | # https://forums.bunsenlabs.org/viewtopic.php?pid=59732#p59732 53 | mkdir -p /home/${DEFAULT_USER}/.config/terminator 54 | echo '[global_config]' | tee -a /home/${DEFAULT_USER}/.config/terminator/config > /dev/null 55 | echo ' dbus = "False"' | tee -a /home/${DEFAULT_USER}/.config/terminator/config > /dev/null 56 | fi 57 | 58 | chown -R ${DEFAULT_USER}:${DEFAULT_USER} /home/${DEFAULT_USER} 59 | 60 | DEFAULT_USER_UID="$(${EXEC} id -u)" 61 | DEFAULT_USER_GID="$(${EXEC} id -g)" 62 | HOME="/home/${DEFAULT_USER}" 63 | else # use existing user 64 | EXEC="exec" 65 | DEFAULT_USER="$(whoami)" 66 | DEFAULT_USER_UID="$(id -u)" 67 | DEFAULT_USER_GID="$(id -g)" 68 | fi 69 | 70 | echo "Launched container with user: ${DEFAULT_USER}, uid: ${DEFAULT_USER_UID}, gid: ${DEFAULT_USER_GID}" 71 | 72 | cd ${HOME} 73 | 74 | if which "$1" > /dev/null 2>&1 ; then 75 | ${EXEC} "$@" 76 | else 77 | echo $@ | ${EXEC} ${SHELL} -li 78 | fi 79 | -------------------------------------------------------------------------------- /melodic/ros_entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | DEFAULT_USER=${DEFAULT_USER:-'ubuntu'} 5 | DEFAULT_USER_UID=${USER_UID:-'1000'} 6 | DEFAULT_USER_GID=${USER_GID:-'1000'} 7 | NOPASSWD=${NOPASSWD:-''} # set 'NOPASSWD:' to disable asking sudo password 8 | BUILD_TOOL=${BUILD_TOOL:-'catkin-tools'} 9 | SHELL=${DEFAULT_SHELL:-$SHELL} 10 | 11 | # override if $USER env exists 12 | if [[ ! -z "$USER" ]]; then 13 | DEFAULT_USER=$USER 14 | fi 15 | 16 | if [[ $(id -u) -eq 0 ]]; then 17 | EXEC="exec /sbin/su-exec ${DEFAULT_USER}" 18 | 19 | # if the user does not exist, create user 20 | if [[ $(id -u ${DEFAULT_USER} 2> /dev/null) != ${DEFAULT_USER_UID} ]]; then 21 | echo creating user ${DEFAULT_USER} 22 | groupadd -g "${DEFAULT_USER_GID}" "${DEFAULT_USER}" 23 | useradd --create-home --home-dir /home/${DEFAULT_USER} --uid ${DEFAULT_USER_UID} --shell /bin/bash \ 24 | --gid ${DEFAULT_USER_GID} --groups sudo ${DEFAULT_USER} 25 | echo "${DEFAULT_USER}:${DEFAULT_USER}" | chpasswd && \ 26 | echo "${DEFAULT_USER} ALL=(ALL) ${NOPASSWD}ALL" >> /etc/sudoers 27 | touch /home/${DEFAULT_USER}/.sudo_as_admin_successful 28 | fi 29 | 30 | # mount develop workspace 31 | if [ -e /ws ]; then 32 | mkdir -p /home/${DEFAULT_USER}/catkin_ws 33 | ln -s /ws /home/${DEFAULT_USER}/catkin_ws/src 34 | fi 35 | 36 | # setup ros environment 37 | if [[ "$BUILD_TOOL" == "catkin_make" ]]; then 38 | touch /home/${DEFAULT_USER}/.bash_aliases 39 | echo "function catkin_make(){(cd ~/catkin_ws && command catkin_make \$@) && source ~/catkin_ws/devel/setup.bash;}" >> /home/${DEFAULT_USER}/.bash_aliases 40 | mkdir -p /home/${DEFAULT_USER}/catkin_ws/src \ 41 | && /bin/bash -c ". /opt/ros/noetic/setup.bash; catkin_init_workspace /home/${DEFAULT_USER}/catkin_ws/src" > /dev/null 42 | echo 'source /opt/ros/noetic/setup.bash' >> /home/${DEFAULT_USER}/.bashrc 43 | fi 44 | if [[ "$BUILD_TOOL" == "catkin-tools" ]]; then 45 | mkdir -p /home/${DEFAULT_USER}/catkin_ws/src \ 46 | && /bin/bash -c "cd /home/${DEFAULT_USER}/catkin_ws;. /opt/ros/noetic/setup.bash; catkin init" > /dev/null 47 | echo 'source /opt/ros/noetic/setup.bash' >> /home/${DEFAULT_USER}/.bashrc 48 | echo 'source `catkin locate --shell-verbs`' >> /home/${DEFAULT_USER}/.bashrc 49 | fi 50 | 51 | if [ ! -e /home/${DEFAULT_USER}/.config/terminator/config ]; then 52 | # Avoid org.freedesktop.DBus.Error.Spawn.ExecFailed 53 | # https://forums.bunsenlabs.org/viewtopic.php?pid=59732#p59732 54 | mkdir -p /home/${DEFAULT_USER}/.config/terminator 55 | echo '[global_config]' | tee -a /home/${DEFAULT_USER}/.config/terminator/config > /dev/null 56 | echo ' dbus = "False"' | tee -a /home/${DEFAULT_USER}/.config/terminator/config > /dev/null 57 | fi 58 | 59 | chown -R ${DEFAULT_USER}:${DEFAULT_USER} /home/${DEFAULT_USER} 60 | 61 | DEFAULT_USER_UID="$(${EXEC} id -u)" 62 | DEFAULT_USER_GID="$(${EXEC} id -g)" 63 | HOME="/home/${DEFAULT_USER}" 64 | else # use existing user 65 | EXEC="exec" 66 | DEFAULT_USER="$(whoami)" 67 | DEFAULT_USER_UID="$(id -u)" 68 | DEFAULT_USER_GID="$(id -g)" 69 | if [[ ! -e /home/${DEFAULT_USER}/.bashrc ]]; then 70 | cp /etc/skel/.* /home/$DEFAULT_USER/ 71 | fi 72 | fi 73 | 74 | echo "Launched container with user: ${DEFAULT_USER}, uid: ${DEFAULT_USER_UID}, gid: ${DEFAULT_USER_GID}" 75 | 76 | cd ${HOME} 77 | 78 | if which "$1" > /dev/null 2>&1 ; then 79 | ${EXEC} "$@" 80 | else 81 | echo $@ | ${EXEC} ${SHELL} -li 82 | fi 83 | -------------------------------------------------------------------------------- /noetic/ros_entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | DEFAULT_USER=${DEFAULT_USER:-'ubuntu'} 5 | DEFAULT_USER_UID=${USER_UID:-'1000'} 6 | DEFAULT_USER_GID=${USER_GID:-'1000'} 7 | NOPASSWD=${NOPASSWD:-''} # set 'NOPASSWD:' to disable asking sudo password 8 | BUILD_TOOL=${BUILD_TOOL:-'catkin-tools'} 9 | SHELL=${DEFAULT_SHELL:-$SHELL} 10 | 11 | # override if $USER env exists 12 | if [[ ! -z "$USER" ]]; then 13 | DEFAULT_USER=$USER 14 | fi 15 | 16 | if [[ $(id -u) -eq 0 ]]; then 17 | EXEC="exec /sbin/su-exec ${DEFAULT_USER}" 18 | 19 | # if the user does not exist, create user 20 | if [[ $(id -u ${DEFAULT_USER} 2> /dev/null) != ${DEFAULT_USER_UID} ]]; then 21 | echo creating user ${DEFAULT_USER} 22 | groupadd -g "${DEFAULT_USER_GID}" "${DEFAULT_USER}" 23 | useradd --create-home --home-dir /home/${DEFAULT_USER} --uid ${DEFAULT_USER_UID} --shell /bin/bash \ 24 | --gid ${DEFAULT_USER_GID} --groups sudo ${DEFAULT_USER} 25 | echo "${DEFAULT_USER}:${DEFAULT_USER}" | chpasswd && \ 26 | echo "${DEFAULT_USER} ALL=(ALL) ${NOPASSWD}ALL" >> /etc/sudoers 27 | touch /home/${DEFAULT_USER}/.sudo_as_admin_successful 28 | fi 29 | 30 | # mount develop workspace 31 | if [ -e /ws ]; then 32 | mkdir -p /home/${DEFAULT_USER}/catkin_ws 33 | ln -s /ws /home/${DEFAULT_USER}/catkin_ws/src 34 | fi 35 | 36 | # setup ros environment 37 | if [[ "$BUILD_TOOL" == "catkin_make" ]]; then 38 | touch /home/${DEFAULT_USER}/.bash_aliases 39 | echo "function catkin_make(){(cd ~/catkin_ws && command catkin_make \$@) && source ~/catkin_ws/devel/setup.bash;}" >> /home/${DEFAULT_USER}/.bash_aliases 40 | mkdir -p /home/${DEFAULT_USER}/catkin_ws/src \ 41 | && /bin/bash -c ". /opt/ros/noetic/setup.bash; catkin_init_workspace /home/${DEFAULT_USER}/catkin_ws/src" > /dev/null 42 | echo 'source /opt/ros/noetic/setup.bash' >> /home/${DEFAULT_USER}/.bashrc 43 | fi 44 | if [[ "$BUILD_TOOL" == "catkin-tools" ]]; then 45 | mkdir -p /home/${DEFAULT_USER}/catkin_ws/src \ 46 | && /bin/bash -c "cd /home/${DEFAULT_USER}/catkin_ws;. /opt/ros/noetic/setup.bash; catkin init" > /dev/null 47 | echo 'source /opt/ros/noetic/setup.bash' >> /home/${DEFAULT_USER}/.bashrc 48 | echo 'source `catkin locate --shell-verbs`' >> /home/${DEFAULT_USER}/.bashrc 49 | fi 50 | 51 | if [ ! -e /home/${DEFAULT_USER}/.config/terminator/config ]; then 52 | # Avoid org.freedesktop.DBus.Error.Spawn.ExecFailed 53 | # https://forums.bunsenlabs.org/viewtopic.php?pid=59732#p59732 54 | mkdir -p /home/${DEFAULT_USER}/.config/terminator 55 | echo '[global_config]' | tee -a /home/${DEFAULT_USER}/.config/terminator/config > /dev/null 56 | echo ' dbus = "False"' | tee -a /home/${DEFAULT_USER}/.config/terminator/config > /dev/null 57 | fi 58 | 59 | chown -R ${DEFAULT_USER}:${DEFAULT_USER} /home/${DEFAULT_USER} 60 | 61 | DEFAULT_USER_UID="$(${EXEC} id -u)" 62 | DEFAULT_USER_GID="$(${EXEC} id -g)" 63 | HOME="/home/${DEFAULT_USER}" 64 | else # use existing user 65 | EXEC="exec" 66 | DEFAULT_USER="$(whoami)" 67 | DEFAULT_USER_UID="$(id -u)" 68 | DEFAULT_USER_GID="$(id -g)" 69 | if [[ ! -e /home/${DEFAULT_USER}/.bashrc ]]; then 70 | cp /etc/skel/.* /home/$DEFAULT_USER/ 71 | fi 72 | fi 73 | 74 | echo "Launched container with user: ${DEFAULT_USER}, uid: ${DEFAULT_USER_UID}, gid: ${DEFAULT_USER_GID}" 75 | 76 | cd ${HOME} 77 | 78 | if which "$1" > /dev/null 2>&1 ; then 79 | ${EXEC} "$@" 80 | else 81 | echo $@ | ${EXEC} ${SHELL} -li 82 | fi 83 | --------------------------------------------------------------------------------