From 7bf287e3fa6d532304f90f307ae4d3e6549df905 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 01:27:24 +0800 Subject: [PATCH 01/24] refactor: Change default branch from `master` to `main` and add tests Ref: https://github.com/j3soon/ros2-essentials/pull/44#pullrequestreview-2251404984 --- .github/workflows/build-cartographer-ws.yaml | 2 +- .github/workflows/build-husky-ws.yaml | 2 +- .github/workflows/build-kobuki-ws.yaml | 2 +- .github/workflows/build-orbslam3-ws.yaml | 2 +- .github/workflows/build-ros1-bridge-ws.yaml | 2 +- .github/workflows/build-rtabmap-ws.yaml | 2 +- .github/workflows/build-template-ws.yaml | 2 +- .github/workflows/build-vlp-ws.yaml | 2 +- husky_ws/README.md | 2 +- tests/lint_filenames.py | 16 +++++++++++++--- 10 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-cartographer-ws.yaml b/.github/workflows/build-cartographer-ws.yaml index 2c91b739..6bc892e8 100644 --- a/.github/workflows/build-cartographer-ws.yaml +++ b/.github/workflows/build-cartographer-ws.yaml @@ -3,7 +3,7 @@ name: Build Docker Image for cartographer-ws on: push: branches: - - "master" + - "main" paths: - .github/workflows/build-cartographer-ws.yaml - cartographer_ws/docker/Dockerfile diff --git a/.github/workflows/build-husky-ws.yaml b/.github/workflows/build-husky-ws.yaml index 1b04d77c..620be474 100644 --- a/.github/workflows/build-husky-ws.yaml +++ b/.github/workflows/build-husky-ws.yaml @@ -3,7 +3,7 @@ name: Build Docker Image for husky-ws on: push: branches: - - "master" + - "main" paths: - .github/workflows/build-husky-ws.yaml - husky_ws/docker/Dockerfile diff --git a/.github/workflows/build-kobuki-ws.yaml b/.github/workflows/build-kobuki-ws.yaml index 02843463..7449e031 100644 --- a/.github/workflows/build-kobuki-ws.yaml +++ b/.github/workflows/build-kobuki-ws.yaml @@ -3,7 +3,7 @@ name: Build Docker Image for kobuki-ws on: push: branches: - - "master" + - "main" paths: - .github/workflows/build-kobuki-ws.yaml - kobuki_ws/docker/Dockerfile diff --git a/.github/workflows/build-orbslam3-ws.yaml b/.github/workflows/build-orbslam3-ws.yaml index e2e31ebc..76b9c405 100644 --- a/.github/workflows/build-orbslam3-ws.yaml +++ b/.github/workflows/build-orbslam3-ws.yaml @@ -3,7 +3,7 @@ name: Build Docker Image for orbslam3-ws on: push: branches: - - "master" + - "main" paths: - .github/workflows/build-orbslam3-ws.yaml - orbslam3_ws/docker/Dockerfile diff --git a/.github/workflows/build-ros1-bridge-ws.yaml b/.github/workflows/build-ros1-bridge-ws.yaml index 598a0088..97b5f676 100644 --- a/.github/workflows/build-ros1-bridge-ws.yaml +++ b/.github/workflows/build-ros1-bridge-ws.yaml @@ -3,7 +3,7 @@ name: Build Docker Image for ros1-bridge-ws on: push: branches: - - "master" + - "main" paths: - .github/workflows/build-ros1-bridge-ws.yaml - ros1_bridge_ws/docker/Dockerfile diff --git a/.github/workflows/build-rtabmap-ws.yaml b/.github/workflows/build-rtabmap-ws.yaml index 21dd74e4..48295687 100644 --- a/.github/workflows/build-rtabmap-ws.yaml +++ b/.github/workflows/build-rtabmap-ws.yaml @@ -3,7 +3,7 @@ name: Build Docker Image for rtabmap-ws on: push: branches: - - "master" + - "main" paths: - .github/workflows/build-rtabmap-ws.yaml - rtabmap_ws/docker/Dockerfile diff --git a/.github/workflows/build-template-ws.yaml b/.github/workflows/build-template-ws.yaml index 159d4eed..9a303fce 100644 --- a/.github/workflows/build-template-ws.yaml +++ b/.github/workflows/build-template-ws.yaml @@ -3,7 +3,7 @@ name: Build Docker Image for template-ws on: push: branches: - - "master" + - "main" paths: - .github/workflows/build-template-ws.yaml - template_ws/docker/Dockerfile diff --git a/.github/workflows/build-vlp-ws.yaml b/.github/workflows/build-vlp-ws.yaml index 33aeef7d..f09f4940 100644 --- a/.github/workflows/build-vlp-ws.yaml +++ b/.github/workflows/build-vlp-ws.yaml @@ -3,7 +3,7 @@ name: Build Docker Image for vlp-ws on: push: branches: - - "master" + - "main" paths: - .github/workflows/build-vlp-ws.yaml - vlp_ws/docker/Dockerfile diff --git a/husky_ws/README.md b/husky_ws/README.md index 321dab3e..987d0db7 100644 --- a/husky_ws/README.md +++ b/husky_ws/README.md @@ -115,4 +115,4 @@ To maintain reproducibility, we have frozen the following packages at specific c * [clearpathrobotics/clearpath_computer_installer](https://github.com/clearpathrobotics/clearpath_computer_installer) (at commit 7e7f415) is released under the [BSD-3-Clause License](https://github.com/clearpathrobotics/clearpath_computer_installer/blob/main/LICENSE). * [clearpathrobotics/clearpath_robot/clearpath_robot/debian/udev](https://github.com/clearpathrobotics/clearpath_robot/blob/17d55f1b27d3fe19fb82e7df64dca96dbd345837/clearpath_robot/debian/udev) (at commit 17d55f1) is released under the [BSD 3-Clause License](https://github.com/clearpathrobotics/clearpath_robot/blob/17d55f1b27d3fe19fb82e7df64dca96dbd345837/LICENSE). -Further changes based on the packages above are release under the [Apache-2.0 License](https://github.com/j3soon/ros2-essentials/blob/master/LICENSE), as stated in the repository. +Further changes based on the packages above are release under the [Apache-2.0 License](https://github.com/j3soon/ros2-essentials/blob/main/LICENSE), as stated in the repository. diff --git a/tests/lint_filenames.py b/tests/lint_filenames.py index 8a12d45e..dbec8cf5 100644 --- a/tests/lint_filenames.py +++ b/tests/lint_filenames.py @@ -1,6 +1,9 @@ import os import glob +current_dir = os.path.dirname(os.path.realpath(__file__)) +repo_dir = os.path.realpath(f"{current_dir}/..") + # Check if all default files exist DEFAULT_FILES = [ ".gitignore", @@ -11,8 +14,6 @@ "docker/Dockerfile", ".devcontainer/devcontainer.json", ] -current_dir = os.path.dirname(os.path.realpath(__file__)) -repo_dir = os.path.realpath(f"{current_dir}/..") for filename in DEFAULT_FILES: print(f"Checking existence of: '{filename}'...") for workspace_path in glob.glob(f"{repo_dir}/*_ws"): @@ -31,6 +32,15 @@ content = f.read() if "version:" in content: # Ref: https://docs.docker.com/compose/compose-file/04-version-and-name/#version-top-level-element-optional - raise ValueError(f"version should not exist since it's obsolete: '{filename}'") + raise ValueError(f"`version` should not exist since it's obsolete: '{filename}'") + +# Check if `master` branch is accidentally used +for filename in glob.glob(f"{repo_dir}/.github/workflows/*.yaml", recursive=True): + print(f"Checking: '{filename[len(repo_dir)+1:]}'...") + with open(filename, "r") as f: + content = f.read() + if "master" in content: + # Ref: https://github.com/j3soon/ros2-essentials/pull/44#pullrequestreview-2251404984 + raise ValueError(f"`master` should not exist since it's obsolete: '{filename}'") print("All checks passed!") From 112fef8b01be53eade5b88d33e4e2d40c2ee2720 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 01:30:18 +0800 Subject: [PATCH 02/24] refactor: Remove obsolete files across all workspaces and add tests --- cartographer_ws/.devcontainer/postCreateCommand.sh | 6 ------ cartographer_ws/docker/cache/.gazebo/.gitkeep | 0 husky_ws/.devcontainer/postCreateCommand.sh | 6 ------ husky_ws/docker/cache/.gazebo/.gitkeep | 0 kobuki_ws/.devcontainer/postCreateCommand.sh | 6 ------ kobuki_ws/docker/cache/.gazebo/.gitkeep | 0 orbslam3_ws/.devcontainer/postCreateCommand.sh | 6 ------ rtabmap_ws/.devcontainer/postCreateCommand.sh | 6 ------ rtabmap_ws/docker/cache/.gazebo/.gitkeep | 0 tests/lint_filenames.py | 14 ++++++++++++++ vlp_ws/.devcontainer/postCreateCommand.sh | 6 ------ vlp_ws/docker/cache/.gazebo/.gitkeep | 0 12 files changed, 14 insertions(+), 36 deletions(-) delete mode 100644 cartographer_ws/.devcontainer/postCreateCommand.sh delete mode 100644 cartographer_ws/docker/cache/.gazebo/.gitkeep delete mode 100755 husky_ws/.devcontainer/postCreateCommand.sh delete mode 100644 husky_ws/docker/cache/.gazebo/.gitkeep delete mode 100755 kobuki_ws/.devcontainer/postCreateCommand.sh delete mode 100644 kobuki_ws/docker/cache/.gazebo/.gitkeep delete mode 100644 orbslam3_ws/.devcontainer/postCreateCommand.sh delete mode 100644 rtabmap_ws/.devcontainer/postCreateCommand.sh delete mode 100644 rtabmap_ws/docker/cache/.gazebo/.gitkeep delete mode 100644 vlp_ws/.devcontainer/postCreateCommand.sh delete mode 100644 vlp_ws/docker/cache/.gazebo/.gitkeep diff --git a/cartographer_ws/.devcontainer/postCreateCommand.sh b/cartographer_ws/.devcontainer/postCreateCommand.sh deleted file mode 100644 index efce9e5b..00000000 --- a/cartographer_ws/.devcontainer/postCreateCommand.sh +++ /dev/null @@ -1,6 +0,0 @@ -sudo apt-get update -sudo rosdep update -# Note: The following commands are commented out to prevent unintended install/builds. -# sudo rosdep install --from-paths src --ignore-src -y -# sudo chown -R user /home/ros2-agv-essentials/ -# colcon build \ No newline at end of file diff --git a/cartographer_ws/docker/cache/.gazebo/.gitkeep b/cartographer_ws/docker/cache/.gazebo/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/husky_ws/.devcontainer/postCreateCommand.sh b/husky_ws/.devcontainer/postCreateCommand.sh deleted file mode 100755 index a6a4f868..00000000 --- a/husky_ws/.devcontainer/postCreateCommand.sh +++ /dev/null @@ -1,6 +0,0 @@ -sudo apt-get update --fix-missing -sudo rosdep update -# Note: The following commands are commented out to prevent unintended install/builds. -# sudo rosdep install --from-paths src --ignore-src --rosdistro humble -y -# sudo chown -R user /home/ros2-agv-essentials/ -# colcon build \ No newline at end of file diff --git a/husky_ws/docker/cache/.gazebo/.gitkeep b/husky_ws/docker/cache/.gazebo/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/kobuki_ws/.devcontainer/postCreateCommand.sh b/kobuki_ws/.devcontainer/postCreateCommand.sh deleted file mode 100755 index efce9e5b..00000000 --- a/kobuki_ws/.devcontainer/postCreateCommand.sh +++ /dev/null @@ -1,6 +0,0 @@ -sudo apt-get update -sudo rosdep update -# Note: The following commands are commented out to prevent unintended install/builds. -# sudo rosdep install --from-paths src --ignore-src -y -# sudo chown -R user /home/ros2-agv-essentials/ -# colcon build \ No newline at end of file diff --git a/kobuki_ws/docker/cache/.gazebo/.gitkeep b/kobuki_ws/docker/cache/.gazebo/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/orbslam3_ws/.devcontainer/postCreateCommand.sh b/orbslam3_ws/.devcontainer/postCreateCommand.sh deleted file mode 100644 index efce9e5b..00000000 --- a/orbslam3_ws/.devcontainer/postCreateCommand.sh +++ /dev/null @@ -1,6 +0,0 @@ -sudo apt-get update -sudo rosdep update -# Note: The following commands are commented out to prevent unintended install/builds. -# sudo rosdep install --from-paths src --ignore-src -y -# sudo chown -R user /home/ros2-agv-essentials/ -# colcon build \ No newline at end of file diff --git a/rtabmap_ws/.devcontainer/postCreateCommand.sh b/rtabmap_ws/.devcontainer/postCreateCommand.sh deleted file mode 100644 index efce9e5b..00000000 --- a/rtabmap_ws/.devcontainer/postCreateCommand.sh +++ /dev/null @@ -1,6 +0,0 @@ -sudo apt-get update -sudo rosdep update -# Note: The following commands are commented out to prevent unintended install/builds. -# sudo rosdep install --from-paths src --ignore-src -y -# sudo chown -R user /home/ros2-agv-essentials/ -# colcon build \ No newline at end of file diff --git a/rtabmap_ws/docker/cache/.gazebo/.gitkeep b/rtabmap_ws/docker/cache/.gazebo/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/lint_filenames.py b/tests/lint_filenames.py index dbec8cf5..06860f84 100644 --- a/tests/lint_filenames.py +++ b/tests/lint_filenames.py @@ -34,6 +34,20 @@ # Ref: https://docs.docker.com/compose/compose-file/04-version-and-name/#version-top-level-element-optional raise ValueError(f"`version` should not exist since it's obsolete: '{filename}'") +# Check if all obsolete files do not exist +OBSOLETE_FILES = [ + "docker/cache/.gazebo/.gitkeep", + "docker/compose.yml", + "docker/docker-compose.yaml", + "docker/docker-compose.yml", + ".devcontainer/postCreateCommand.sh", +] +for filename in OBSOLETE_FILES: + print(f"Checking non-existence of: '{filename}'...") + for workspace_path in glob.glob(f"{repo_dir}/*_ws"): + if os.path.isfile(f"{workspace_path}/{filename}"): + raise ValueError(f"'{filename}' exists in: '{workspace_path}'") + # Check if `master` branch is accidentally used for filename in glob.glob(f"{repo_dir}/.github/workflows/*.yaml", recursive=True): print(f"Checking: '{filename[len(repo_dir)+1:]}'...") diff --git a/vlp_ws/.devcontainer/postCreateCommand.sh b/vlp_ws/.devcontainer/postCreateCommand.sh deleted file mode 100644 index efce9e5b..00000000 --- a/vlp_ws/.devcontainer/postCreateCommand.sh +++ /dev/null @@ -1,6 +0,0 @@ -sudo apt-get update -sudo rosdep update -# Note: The following commands are commented out to prevent unintended install/builds. -# sudo rosdep install --from-paths src --ignore-src -y -# sudo chown -R user /home/ros2-agv-essentials/ -# colcon build \ No newline at end of file diff --git a/vlp_ws/docker/cache/.gazebo/.gitkeep b/vlp_ws/docker/cache/.gazebo/.gitkeep deleted file mode 100644 index e69de29b..00000000 From 4ad113975ef303c435257edbf57a471692b9713c Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 01:36:11 +0800 Subject: [PATCH 03/24] test: Use logging instead of print --- tests/lint_filenames.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/lint_filenames.py b/tests/lint_filenames.py index 06860f84..fdbff262 100644 --- a/tests/lint_filenames.py +++ b/tests/lint_filenames.py @@ -1,10 +1,12 @@ import os import glob +import logging +logging.basicConfig(level=logging.INFO) current_dir = os.path.dirname(os.path.realpath(__file__)) repo_dir = os.path.realpath(f"{current_dir}/..") -# Check if all default files exist +logging.info("Checking if all default files exist...") DEFAULT_FILES = [ ".gitignore", "README.md", @@ -15,7 +17,7 @@ ".devcontainer/devcontainer.json", ] for filename in DEFAULT_FILES: - print(f"Checking existence of: '{filename}'...") + logging.debug(f"Checking existence of: '{filename}'...") for workspace_path in glob.glob(f"{repo_dir}/*_ws"): if not os.path.isfile(f"{workspace_path}/{filename}"): # Skip certain cases intentionally @@ -25,16 +27,16 @@ # Report error raise ValueError(f"'{filename}' does not exist in: '{workspace_path}'") -# Check compose.yaml files +logging.info("Checking `compose.yaml` files...") for filename in glob.glob(f"{repo_dir}/**/compose*.yaml", recursive=True): - print(f"Checking: '{filename[len(repo_dir)+1:]}'...") + logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") with open(filename, "r") as f: content = f.read() if "version:" in content: # Ref: https://docs.docker.com/compose/compose-file/04-version-and-name/#version-top-level-element-optional raise ValueError(f"`version` should not exist since it's obsolete: '{filename}'") -# Check if all obsolete files do not exist +logging.info("Checking if all obsolete files do not exist...") OBSOLETE_FILES = [ "docker/cache/.gazebo/.gitkeep", "docker/compose.yml", @@ -43,14 +45,14 @@ ".devcontainer/postCreateCommand.sh", ] for filename in OBSOLETE_FILES: - print(f"Checking non-existence of: '{filename}'...") + logging.debug(f"Checking non-existence of: '{filename}'...") for workspace_path in glob.glob(f"{repo_dir}/*_ws"): if os.path.isfile(f"{workspace_path}/{filename}"): raise ValueError(f"'{filename}' exists in: '{workspace_path}'") -# Check if `master` branch is accidentally used +logging.info("Checking if `master` branch is accidentally used in github workflows...") for filename in glob.glob(f"{repo_dir}/.github/workflows/*.yaml", recursive=True): - print(f"Checking: '{filename[len(repo_dir)+1:]}'...") + logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") with open(filename, "r") as f: content = f.read() if "master" in content: From a45dc7c05db896c812d815b96515e481c4feb4ac Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 01:49:54 +0800 Subject: [PATCH 04/24] test: Separate tests to different files --- .github/workflows/test-common.yaml | 4 ++-- tests/lint_compose.py | 16 ++++++++++++++++ tests/lint_filenames.py | 20 -------------------- tests/lint_workflows.py | 16 ++++++++++++++++ tests/test_all.sh | 12 ++++++++++++ 5 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 tests/lint_compose.py create mode 100644 tests/lint_workflows.py create mode 100755 tests/test_all.sh diff --git a/.github/workflows/test-common.yaml b/.github/workflows/test-common.yaml index d7f164a1..e1c1c965 100644 --- a/.github/workflows/test-common.yaml +++ b/.github/workflows/test-common.yaml @@ -15,5 +15,5 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - name: Lint filenames - run: python tests/lint_filenames.py \ No newline at end of file + - name: Run tests + run: tests/test_all.sh \ No newline at end of file diff --git a/tests/lint_compose.py b/tests/lint_compose.py new file mode 100644 index 00000000..0261be10 --- /dev/null +++ b/tests/lint_compose.py @@ -0,0 +1,16 @@ +import os +import glob +import logging + +logging.basicConfig(level=logging.INFO) +current_dir = os.path.dirname(os.path.realpath(__file__)) +repo_dir = os.path.realpath(f"{current_dir}/..") + +logging.info("Checking `compose.yaml` files...") +for filename in glob.glob(f"{repo_dir}/**/compose*.yaml", recursive=True): + logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") + with open(filename, "r") as f: + content = f.read() + if "version:" in content: + # Ref: https://docs.docker.com/compose/compose-file/04-version-and-name/#version-top-level-element-optional + raise ValueError(f"`version` should not exist since it's obsolete: '{filename}'") diff --git a/tests/lint_filenames.py b/tests/lint_filenames.py index fdbff262..219a2ea2 100644 --- a/tests/lint_filenames.py +++ b/tests/lint_filenames.py @@ -27,15 +27,6 @@ # Report error raise ValueError(f"'{filename}' does not exist in: '{workspace_path}'") -logging.info("Checking `compose.yaml` files...") -for filename in glob.glob(f"{repo_dir}/**/compose*.yaml", recursive=True): - logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") - with open(filename, "r") as f: - content = f.read() - if "version:" in content: - # Ref: https://docs.docker.com/compose/compose-file/04-version-and-name/#version-top-level-element-optional - raise ValueError(f"`version` should not exist since it's obsolete: '{filename}'") - logging.info("Checking if all obsolete files do not exist...") OBSOLETE_FILES = [ "docker/cache/.gazebo/.gitkeep", @@ -49,14 +40,3 @@ for workspace_path in glob.glob(f"{repo_dir}/*_ws"): if os.path.isfile(f"{workspace_path}/{filename}"): raise ValueError(f"'{filename}' exists in: '{workspace_path}'") - -logging.info("Checking if `master` branch is accidentally used in github workflows...") -for filename in glob.glob(f"{repo_dir}/.github/workflows/*.yaml", recursive=True): - logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") - with open(filename, "r") as f: - content = f.read() - if "master" in content: - # Ref: https://github.com/j3soon/ros2-essentials/pull/44#pullrequestreview-2251404984 - raise ValueError(f"`master` should not exist since it's obsolete: '{filename}'") - -print("All checks passed!") diff --git a/tests/lint_workflows.py b/tests/lint_workflows.py new file mode 100644 index 00000000..4e5544bc --- /dev/null +++ b/tests/lint_workflows.py @@ -0,0 +1,16 @@ +import os +import glob +import logging + +logging.basicConfig(level=logging.INFO) +current_dir = os.path.dirname(os.path.realpath(__file__)) +repo_dir = os.path.realpath(f"{current_dir}/..") + +logging.info("Checking if `master` branch is accidentally used in github workflows...") +for filename in glob.glob(f"{repo_dir}/.github/workflows/*.yaml", recursive=True): + logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") + with open(filename, "r") as f: + content = f.read() + if "master" in content: + # Ref: https://github.com/j3soon/ros2-essentials/pull/44#pullrequestreview-2251404984 + raise ValueError(f"`master` should not exist since it's obsolete: '{filename}'") diff --git a/tests/test_all.sh b/tests/test_all.sh new file mode 100755 index 00000000..2b32c34f --- /dev/null +++ b/tests/test_all.sh @@ -0,0 +1,12 @@ +#!/bin/bash -e + +# Get the directory of this script. +# Reference: https://stackoverflow.com/q/59895 +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)" +cd $SCRIPT_DIR +# Loop through all Python files in the current directory +for script in *.py; do + echo "Running $script..." + python3 "$script" +done +echo "All tests have passed." From 830f54e57ec2fea498133c134eeac86bdccb7133 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 03:12:33 +0800 Subject: [PATCH 05/24] refactor: Unify `devcontainer.json` across all workspaces and add tests --- .../.devcontainer/devcontainer.json | 17 ++++----- husky_ws/.devcontainer/devcontainer.json | 12 +++--- kobuki_ws/.devcontainer/devcontainer.json | 12 +++--- orbslam3_ws/.devcontainer/devcontainer.json | 17 ++++----- .../.devcontainer/devcontainer.json | 8 ++-- rtabmap_ws/.devcontainer/devcontainer.json | 17 ++++----- template_ws/.devcontainer/devcontainer.json | 6 +-- .../diff_base/.devcontainer/devcontainer.json | 23 ++++++++++++ tests/lint_devcontainer.py | 37 +++++++++++++++++++ vlp_ws/.devcontainer/devcontainer.json | 17 ++++----- 10 files changed, 105 insertions(+), 61 deletions(-) create mode 100644 tests/diff_base/.devcontainer/devcontainer.json create mode 100644 tests/lint_devcontainer.py diff --git a/cartographer_ws/.devcontainer/devcontainer.json b/cartographer_ws/.devcontainer/devcontainer.json index 02f47b10..ed47321a 100644 --- a/cartographer_ws/.devcontainer/devcontainer.json +++ b/cartographer_ws/.devcontainer/devcontainer.json @@ -1,12 +1,10 @@ /* Reference: https://aka.ms/devcontainer.json */ { - "name": "ROS2 and Catorgrapher Container", + "name": "Catographer", "dockerComposeFile": "../docker/compose.yaml", "service": "ros2-cartographer", - - // workspace settings - "workspaceFolder": "/home/ros2-agv-essentials/cartographer_ws", - + // Workspace settings + "workspaceFolder": "/home/ros2-essentials/cartographer_ws", // Vscode extensions "customizations": { "vscode": { @@ -16,11 +14,10 @@ "twxs.cmake", "donjayamanne.python-extension-pack", "eamodio.gitlens", + "mhutchie.git-graph", + "streetsidesoftware.code-spell-checker", "ms-iot.vscode-ros" ] } - }, - - // Lifecycle scripts - "postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/postCreateCommand.sh" -} \ No newline at end of file + } +} diff --git a/husky_ws/.devcontainer/devcontainer.json b/husky_ws/.devcontainer/devcontainer.json index 5431daa5..f2284404 100644 --- a/husky_ws/.devcontainer/devcontainer.json +++ b/husky_ws/.devcontainer/devcontainer.json @@ -1,10 +1,10 @@ -/* For reference, see https://aka.ms/devcontainer.json */ +/* Reference: https://aka.ms/devcontainer.json */ { - "name": "Husky Simulation", + "name": "Husky", "dockerComposeFile": "../docker/compose.yaml", "service": "husky-ws", // Workspace settings - "workspaceFolder": "/home/ros2-agv-essentials/husky_ws", + "workspaceFolder": "/home/ros2-essentials/husky_ws", // Vscode extensions "customizations": { "vscode": { @@ -19,7 +19,5 @@ "ms-iot.vscode-ros" ] } - }, - // Lifecycle scripts - "postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/postCreateCommand.sh" -} \ No newline at end of file + } +} diff --git a/kobuki_ws/.devcontainer/devcontainer.json b/kobuki_ws/.devcontainer/devcontainer.json index afa06486..0d2cb501 100644 --- a/kobuki_ws/.devcontainer/devcontainer.json +++ b/kobuki_ws/.devcontainer/devcontainer.json @@ -1,10 +1,10 @@ /* Reference: https://aka.ms/devcontainer.json */ { - "name": "kobuki_ws", + "name": "Kobuki", "dockerComposeFile": "../docker/compose.yaml", "service": "kobuki-ws", - // workspace settings - "workspaceFolder": "/home/ros2-agv-essentials/kobuki_ws", + // Workspace settings + "workspaceFolder": "/home/ros2-essentials/kobuki_ws", // Vscode extensions "customizations": { "vscode": { @@ -19,7 +19,5 @@ "ms-iot.vscode-ros" ] } - }, - // Lifecycle scripts - "postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/postCreateCommand.sh" -} \ No newline at end of file + } +} diff --git a/orbslam3_ws/.devcontainer/devcontainer.json b/orbslam3_ws/.devcontainer/devcontainer.json index fe8dbbfa..af5e2fd7 100644 --- a/orbslam3_ws/.devcontainer/devcontainer.json +++ b/orbslam3_ws/.devcontainer/devcontainer.json @@ -1,12 +1,10 @@ /* Reference: https://aka.ms/devcontainer.json */ { - "name": "ROS2 and ORB-SLAM3 Container", + "name": "ORB-SLAM3", "dockerComposeFile": "../docker/compose.yaml", "service": "ros2-orbslam3", - - // workspace settings - "workspaceFolder": "/home/ros2-agv-essentials/orbslam3_ws", - + // Workspace settings + "workspaceFolder": "/home/ros2-essentials/orbslam3_ws", // Vscode extensions "customizations": { "vscode": { @@ -16,11 +14,10 @@ "twxs.cmake", "donjayamanne.python-extension-pack", "eamodio.gitlens", + "mhutchie.git-graph", + "streetsidesoftware.code-spell-checker", "ms-iot.vscode-ros" ] } - }, - - // Lifecycle scripts - "postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/postCreateCommand.sh" -} \ No newline at end of file + } +} diff --git a/ros1_bridge_ws/.devcontainer/devcontainer.json b/ros1_bridge_ws/.devcontainer/devcontainer.json index 223480c7..d273ace1 100644 --- a/ros1_bridge_ws/.devcontainer/devcontainer.json +++ b/ros1_bridge_ws/.devcontainer/devcontainer.json @@ -1,12 +1,12 @@ -/* For reference, see https://aka.ms/devcontainer.json */ +/* Reference: https://aka.ms/devcontainer.json */ { - "name": "ros1-bridge", + "name": "Ros1 Bridge", "dockerComposeFile": "../docker/compose.debug.yaml", "service": "ros1-bridge-build", "runServices": [ "ros1-bridge-build" ], - // workspace settings + // Workspace settings "workspaceFolder": "/", // Vscode extensions "customizations": { @@ -23,4 +23,4 @@ ] } } -} \ No newline at end of file +} diff --git a/rtabmap_ws/.devcontainer/devcontainer.json b/rtabmap_ws/.devcontainer/devcontainer.json index 271bd372..205d640f 100644 --- a/rtabmap_ws/.devcontainer/devcontainer.json +++ b/rtabmap_ws/.devcontainer/devcontainer.json @@ -1,12 +1,10 @@ /* Reference: https://aka.ms/devcontainer.json */ { - "name": "ROS2 and RTAB-Map Container", + "name": "RTAB-Map", "dockerComposeFile": "../docker/compose.yaml", "service": "ros2-rtabmap", - - // workspace settings - "workspaceFolder": "/home/ros2-agv-essentials/rtabmap_ws", - + // Workspace settings + "workspaceFolder": "/home/ros2-essentials/rtabmap_ws", // Vscode extensions "customizations": { "vscode": { @@ -16,11 +14,10 @@ "twxs.cmake", "donjayamanne.python-extension-pack", "eamodio.gitlens", + "mhutchie.git-graph", + "streetsidesoftware.code-spell-checker", "ms-iot.vscode-ros" ] } - }, - - // Lifecycle scripts - "postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/postCreateCommand.sh" -} \ No newline at end of file + } +} diff --git a/template_ws/.devcontainer/devcontainer.json b/template_ws/.devcontainer/devcontainer.json index b7c6fef6..08abed1e 100644 --- a/template_ws/.devcontainer/devcontainer.json +++ b/template_ws/.devcontainer/devcontainer.json @@ -1,9 +1,9 @@ /* Reference: https://aka.ms/devcontainer.json */ { - "name": "template-ws", + "name": "Template", "dockerComposeFile": "../docker/compose.yaml", "service": "template-ws", - // workspace settings + // Workspace settings "workspaceFolder": "/home/ros2-essentials/template_ws", // Vscode extensions "customizations": { @@ -20,4 +20,4 @@ ] } } -} \ No newline at end of file +} diff --git a/tests/diff_base/.devcontainer/devcontainer.json b/tests/diff_base/.devcontainer/devcontainer.json new file mode 100644 index 00000000..597744fa --- /dev/null +++ b/tests/diff_base/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +/* Reference: https://aka.ms/devcontainer.json */ +{ + "name": "PLACEHOLDER", + "dockerComposeFile": "../docker/compose.yaml", + "service": "PLACEHOLDER", + // Workspace settings + "workspaceFolder": "/home/ros2-essentials/PLACEHOLDER_ws", + // Vscode extensions + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cpptools-themes", + "twxs.cmake", + "donjayamanne.python-extension-pack", + "eamodio.gitlens", + "mhutchie.git-graph", + "streetsidesoftware.code-spell-checker", + "ms-iot.vscode-ros" + ] + } + } +} diff --git a/tests/lint_devcontainer.py b/tests/lint_devcontainer.py new file mode 100644 index 00000000..d0375fa3 --- /dev/null +++ b/tests/lint_devcontainer.py @@ -0,0 +1,37 @@ +import difflib +import glob +import logging +import os +import re +from pathlib import Path + +logging.basicConfig(level=logging.INFO) +current_dir = os.path.dirname(os.path.realpath(__file__)) +repo_dir = os.path.realpath(f"{current_dir}/..") + +template_path = f"{repo_dir}/tests/diff_base/.devcontainer/devcontainer.json" +template = Path(template_path).read_text().splitlines(keepends=True) + +logging.info("Checking if `devcontainer.json` matches the template...") +for filename in glob.glob(f"{repo_dir}/**/.devcontainer/devcontainer.json", recursive=True): + # Skip certain cases intentionally + if "ros1_bridge_ws" in filename: + continue + logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") + content = Path(filename).read_text().splitlines(keepends=True) + diff = list(filter(lambda x: x.startswith('- ') or x.startswith('+ '), difflib.ndiff(template, content))) + def error(msg, i): + diff.insert(i+2, "! <<< Parsing failed before reaching here >>>\n") + logging.info('\n' + ''.join(diff)) + logging.error(msg) + raise ValueError(f"devcontainer.json does not match the template: '{filename}'") + i = 0 + while i < len(diff): + if i+1 >= len(diff): + error("Odd lines", i) + if not diff[i].startswith('- ') or not diff[i+1].startswith('+ '): + error("Expected no line deletion and addition", i) + regexp = "^" + re.escape(diff[i][1:]).replace('PLACEHOLDER', '.*') + "$" + if not re.match(regexp, diff[i+1][1:]): + error("Expected line deletion and addition to differ only in the placeholder", i) + i += 2 diff --git a/vlp_ws/.devcontainer/devcontainer.json b/vlp_ws/.devcontainer/devcontainer.json index a402fe92..2060c085 100644 --- a/vlp_ws/.devcontainer/devcontainer.json +++ b/vlp_ws/.devcontainer/devcontainer.json @@ -1,12 +1,10 @@ /* Reference: https://aka.ms/devcontainer.json */ { - "name": "ROS2 and VLP-16 Container", + "name": "VLP-16", "dockerComposeFile": "../docker/compose.yaml", "service": "vlp-ws", - - // workspace settings - "workspaceFolder": "/home/ros2-agv-essentials/vlp_ws", - + // Workspace settings + "workspaceFolder": "/home/ros2-essentials/vlp_ws", // Vscode extensions "customizations": { "vscode": { @@ -16,11 +14,10 @@ "twxs.cmake", "donjayamanne.python-extension-pack", "eamodio.gitlens", + "mhutchie.git-graph", + "streetsidesoftware.code-spell-checker", "ms-iot.vscode-ros" ] } - }, - - // Lifecycle scripts - "postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/postCreateCommand.sh" -} \ No newline at end of file + } +} From 26ef5055e42456dadc9e6e09db8d42e57c797f0e Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 03:31:36 +0800 Subject: [PATCH 06/24] test: Reformat and refactor --- tests/lint_compose.py | 14 +++++----- tests/lint_devcontainer.py | 52 ++++++++++++++++++++------------------ tests/lint_filenames.py | 2 +- tests/lint_workflows.py | 14 +++++----- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/tests/lint_compose.py b/tests/lint_compose.py index 0261be10..3255731f 100644 --- a/tests/lint_compose.py +++ b/tests/lint_compose.py @@ -1,16 +1,16 @@ -import os import glob import logging +import os +from pathlib import Path logging.basicConfig(level=logging.INFO) current_dir = os.path.dirname(os.path.realpath(__file__)) repo_dir = os.path.realpath(f"{current_dir}/..") logging.info("Checking `compose.yaml` files...") -for filename in glob.glob(f"{repo_dir}/**/compose*.yaml", recursive=True): +for filename in glob.glob(f"{repo_dir}/*_ws/docker/compose*.yaml"): logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") - with open(filename, "r") as f: - content = f.read() - if "version:" in content: - # Ref: https://docs.docker.com/compose/compose-file/04-version-and-name/#version-top-level-element-optional - raise ValueError(f"`version` should not exist since it's obsolete: '{filename}'") + content = Path(filename).read_text() + if "version:" in content: + # Ref: https://docs.docker.com/compose/compose-file/04-version-and-name/#version-top-level-element-optional + raise ValueError(f"`version` should not exist since it's obsolete: '{filename}'") diff --git a/tests/lint_devcontainer.py b/tests/lint_devcontainer.py index d0375fa3..f03f38ca 100644 --- a/tests/lint_devcontainer.py +++ b/tests/lint_devcontainer.py @@ -9,29 +9,31 @@ current_dir = os.path.dirname(os.path.realpath(__file__)) repo_dir = os.path.realpath(f"{current_dir}/..") -template_path = f"{repo_dir}/tests/diff_base/.devcontainer/devcontainer.json" -template = Path(template_path).read_text().splitlines(keepends=True) +def compare_file_with_template(filepath, ignored_workspaces=[]): + logging.info(f"Checking if '{filepath}' matches the template...") + template_path = f"{repo_dir}/tests/diff_base/{filepath}" + template = Path(template_path).read_text().splitlines(keepends=True) + for filename in glob.glob(f"{repo_dir}/*_ws/{filepath}"): + # Skip certain cases intentionally + if any(ws in filename for ws in ignored_workspaces): + continue + logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") + content = Path(filename).read_text().splitlines(keepends=True) + diff = list(filter(lambda x: x.startswith('- ') or x.startswith('+ '), difflib.ndiff(template, content))) + def error(msg, i): + diff.insert(i+2, "! <<< Parsing failed before reaching here >>>\n") + logging.info('\n' + ''.join(diff)) + logging.error(msg) + raise ValueError(f"'{filepath}' does not match the template: '{filename}'") + i = 0 + while i < len(diff): + if i+1 >= len(diff): + error("Odd lines", i) + if not diff[i].startswith('- ') or not diff[i+1].startswith('+ '): + error("Expected no line deletion and addition", i) + regexp = "^" + re.escape(diff[i][1:]).replace('PLACEHOLDER', '.*') + "$" + if not re.match(regexp, diff[i+1][1:]): + error("Expected line deletion and addition to differ only in the placeholder", i) + i += 2 -logging.info("Checking if `devcontainer.json` matches the template...") -for filename in glob.glob(f"{repo_dir}/**/.devcontainer/devcontainer.json", recursive=True): - # Skip certain cases intentionally - if "ros1_bridge_ws" in filename: - continue - logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") - content = Path(filename).read_text().splitlines(keepends=True) - diff = list(filter(lambda x: x.startswith('- ') or x.startswith('+ '), difflib.ndiff(template, content))) - def error(msg, i): - diff.insert(i+2, "! <<< Parsing failed before reaching here >>>\n") - logging.info('\n' + ''.join(diff)) - logging.error(msg) - raise ValueError(f"devcontainer.json does not match the template: '{filename}'") - i = 0 - while i < len(diff): - if i+1 >= len(diff): - error("Odd lines", i) - if not diff[i].startswith('- ') or not diff[i+1].startswith('+ '): - error("Expected no line deletion and addition", i) - regexp = "^" + re.escape(diff[i][1:]).replace('PLACEHOLDER', '.*') + "$" - if not re.match(regexp, diff[i+1][1:]): - error("Expected line deletion and addition to differ only in the placeholder", i) - i += 2 +compare_file_with_template(".devcontainer/devcontainer.json", ["ros1_bridge_ws"]) diff --git a/tests/lint_filenames.py b/tests/lint_filenames.py index 219a2ea2..d307fb29 100644 --- a/tests/lint_filenames.py +++ b/tests/lint_filenames.py @@ -1,6 +1,6 @@ -import os import glob import logging +import os logging.basicConfig(level=logging.INFO) current_dir = os.path.dirname(os.path.realpath(__file__)) diff --git a/tests/lint_workflows.py b/tests/lint_workflows.py index 4e5544bc..36a29285 100644 --- a/tests/lint_workflows.py +++ b/tests/lint_workflows.py @@ -1,16 +1,16 @@ -import os import glob import logging +import os +from pathlib import Path logging.basicConfig(level=logging.INFO) current_dir = os.path.dirname(os.path.realpath(__file__)) repo_dir = os.path.realpath(f"{current_dir}/..") logging.info("Checking if `master` branch is accidentally used in github workflows...") -for filename in glob.glob(f"{repo_dir}/.github/workflows/*.yaml", recursive=True): +for filename in glob.glob(f"{repo_dir}/.github/workflows/*.yaml"): logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") - with open(filename, "r") as f: - content = f.read() - if "master" in content: - # Ref: https://github.com/j3soon/ros2-essentials/pull/44#pullrequestreview-2251404984 - raise ValueError(f"`master` should not exist since it's obsolete: '{filename}'") + content = Path(filename).read_text() + if "master" in content: + # Ref: https://github.com/j3soon/ros2-essentials/pull/44#pullrequestreview-2251404984 + raise ValueError(f"`master` should not exist since it's obsolete: '{filename}'") From 5af5f98d852116cc42604a099b07cd59fa051710 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 04:05:07 +0800 Subject: [PATCH 07/24] refactor: Unify `.gitignore` across all workspaces and add tests --- cartographer_ws/.gitignore | 7 +++---- husky_ws/.gitignore | 7 +------ kobuki_ws/.gitignore | 7 +------ orbslam3_ws/.gitignore | 9 +++++++++ rtabmap_ws/.gitignore | 7 +++---- template_ws/.gitignore | 3 ++- tests/diff_base/.gitignore | 8 ++++++++ ...nt_devcontainer.py => lint_comp_template.py} | 12 +++++++++--- tests/lint_gitignore.py | 17 +++++++++++++++++ vlp_ws/.gitignore | 7 +++---- 10 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 tests/diff_base/.gitignore rename tests/{lint_devcontainer.py => lint_comp_template.py} (78%) create mode 100644 tests/lint_gitignore.py diff --git a/cartographer_ws/.gitignore b/cartographer_ws/.gitignore index d56eeb47..2bc3ebb3 100644 --- a/cartographer_ws/.gitignore +++ b/cartographer_ws/.gitignore @@ -1,8 +1,7 @@ +# Visual Studio Code .vscode + +# ROS2 basic directories /build /install /log -docker/cache/* -!docker/cache/.gazebo -docker/cache/.gazebo/* -!docker/cache/.gazebo/.gitkeep \ No newline at end of file diff --git a/husky_ws/.gitignore b/husky_ws/.gitignore index 6bf2ffcd..2bc3ebb3 100644 --- a/husky_ws/.gitignore +++ b/husky_ws/.gitignore @@ -1,12 +1,7 @@ +# Visual Studio Code .vscode # ROS2 basic directories /build /install /log - -# Gazebo cache -docker/cache/* -!docker/cache/.gazebo -docker/cache/.gazebo/* -!docker/cache/.gazebo/.gitkeep \ No newline at end of file diff --git a/kobuki_ws/.gitignore b/kobuki_ws/.gitignore index 6bf2ffcd..2bc3ebb3 100644 --- a/kobuki_ws/.gitignore +++ b/kobuki_ws/.gitignore @@ -1,12 +1,7 @@ +# Visual Studio Code .vscode # ROS2 basic directories /build /install /log - -# Gazebo cache -docker/cache/* -!docker/cache/.gazebo -docker/cache/.gazebo/* -!docker/cache/.gazebo/.gitkeep \ No newline at end of file diff --git a/orbslam3_ws/.gitignore b/orbslam3_ws/.gitignore index 123266bd..891f5aab 100644 --- a/orbslam3_ws/.gitignore +++ b/orbslam3_ws/.gitignore @@ -1,2 +1,11 @@ +# Visual Studio Code +.vscode + +# ROS2 basic directories +/build +/install +/log + +# ROS2 bag files V1_02_medium.bag V1_02_medium/ diff --git a/rtabmap_ws/.gitignore b/rtabmap_ws/.gitignore index f14775a5..2bc3ebb3 100644 --- a/rtabmap_ws/.gitignore +++ b/rtabmap_ws/.gitignore @@ -1,8 +1,7 @@ +# Visual Studio Code .vscode + +# ROS2 basic directories /build /install /log -docker/cache/* -!docker/cache/.gazebo -docker/cache/.gazebo/* -!docker/cache/.gazebo/.gitkeep diff --git a/template_ws/.gitignore b/template_ws/.gitignore index 171c8a96..2bc3ebb3 100644 --- a/template_ws/.gitignore +++ b/template_ws/.gitignore @@ -1,6 +1,7 @@ +# Visual Studio Code .vscode # ROS2 basic directories /build /install -/log \ No newline at end of file +/log diff --git a/tests/diff_base/.gitignore b/tests/diff_base/.gitignore new file mode 100644 index 00000000..90c2d24c --- /dev/null +++ b/tests/diff_base/.gitignore @@ -0,0 +1,8 @@ +# Visual Studio Code +.vscode + +# ROS2 basic directories +/build +/install +/log +MULTILINE_PLACEHOLDER \ No newline at end of file diff --git a/tests/lint_devcontainer.py b/tests/lint_comp_template.py similarity index 78% rename from tests/lint_devcontainer.py rename to tests/lint_comp_template.py index f03f38ca..9a2fc853 100644 --- a/tests/lint_devcontainer.py +++ b/tests/lint_comp_template.py @@ -12,7 +12,7 @@ def compare_file_with_template(filepath, ignored_workspaces=[]): logging.info(f"Checking if '{filepath}' matches the template...") template_path = f"{repo_dir}/tests/diff_base/{filepath}" - template = Path(template_path).read_text().splitlines(keepends=True) + template = Path(template_path).read_text().splitlines(keepends=True) # keepends to preserve trailing newlines for filename in glob.glob(f"{repo_dir}/*_ws/{filepath}"): # Skip certain cases intentionally if any(ws in filename for ws in ignored_workspaces): @@ -27,13 +27,19 @@ def error(msg, i): raise ValueError(f"'{filepath}' does not match the template: '{filename}'") i = 0 while i < len(diff): + if "- MULTILINE_PLACEHOLDER" in diff[i]: # don't use exact match to avoid cases without trailing newline + i += 1 + while i < len(diff) and diff[i].startswith('+ '): + i += 1 + continue if i+1 >= len(diff): error("Odd lines", i) if not diff[i].startswith('- ') or not diff[i+1].startswith('+ '): error("Expected no line deletion and addition", i) - regexp = "^" + re.escape(diff[i][1:]).replace('PLACEHOLDER', '.*') + "$" - if not re.match(regexp, diff[i+1][1:]): + regexp = "^" + re.escape(diff[i][2:]).replace('PLACEHOLDER', '.*') + "$" + if not re.match(regexp, diff[i+1][2:]): error("Expected line deletion and addition to differ only in the placeholder", i) i += 2 compare_file_with_template(".devcontainer/devcontainer.json", ["ros1_bridge_ws"]) +compare_file_with_template(".gitignore") diff --git a/tests/lint_gitignore.py b/tests/lint_gitignore.py new file mode 100644 index 00000000..da2a26c6 --- /dev/null +++ b/tests/lint_gitignore.py @@ -0,0 +1,17 @@ +import glob +import logging +import os +from pathlib import Path + +logging.basicConfig(level=logging.INFO) +current_dir = os.path.dirname(os.path.realpath(__file__)) +repo_dir = os.path.realpath(f"{current_dir}/..") + +logging.info("Checking `.gitignore` files...") +for filename in glob.glob(f"{repo_dir}/*_ws/.gitignore"): + logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") + content = Path(filename).read_text() + if "gazebo" in content: + raise ValueError(f"`gazebo` should not exist since it's obsolete: '{filename}'") + if "docker/cache" in content: + raise ValueError(f"`docker/cache` should not exist since it's obsolete: '{filename}'") diff --git a/vlp_ws/.gitignore b/vlp_ws/.gitignore index d56eeb47..2bc3ebb3 100644 --- a/vlp_ws/.gitignore +++ b/vlp_ws/.gitignore @@ -1,8 +1,7 @@ +# Visual Studio Code .vscode + +# ROS2 basic directories /build /install /log -docker/cache/* -!docker/cache/.gazebo -docker/cache/.gazebo/* -!docker/cache/.gazebo/.gitkeep \ No newline at end of file From a33579ed5631aeb60535762f9fb13d957e01e819 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 04:40:57 +0800 Subject: [PATCH 08/24] refactor: Unify `docker/.bashrc` across all workspaces and add tests --- cartographer_ws/docker/.bashrc | 28 +++++++++++++++++++++++++++- husky_ws/docker/.bashrc | 34 ++++++++++++++++++++++++++++------ kobuki_ws/docker/.bashrc | 27 ++++++++++++++++++++++++++- rtabmap_ws/docker/.bashrc | 30 ++++++++++++++++++++++++++++-- template_ws/docker/.bashrc | 1 + tests/diff_base/docker/.bashrc | 31 +++++++++++++++++++++++++++++++ tests/lint_comp_template.py | 1 + vlp_ws/docker/.bashrc | 26 ++++++++++++++++++-------- 8 files changed, 160 insertions(+), 18 deletions(-) create mode 100644 tests/diff_base/docker/.bashrc diff --git a/cartographer_ws/docker/.bashrc b/cartographer_ws/docker/.bashrc index 7c9df020..f9184745 100644 --- a/cartographer_ws/docker/.bashrc +++ b/cartographer_ws/docker/.bashrc @@ -1,5 +1,31 @@ # Source global ROS2 environment source /opt/ros/$ROS_DISTRO/setup.bash +# Optionally perform apt update if it has not been executed yet +if [ -z "$( ls -A '/var/lib/apt/lists' )" ]; then + echo "apt-get update has not been executed yet. Running sudo apt-get update..." + sudo apt-get update +fi +# Optionally perform rosdep update if it has not been executed yet +if [ ! -d $HOME/.ros/rosdep/sources.cache ]; then + echo "rosdep update has not been executed yet. Running rosdep update..." + rosdep update +fi +# Optionally build the workspace if it has not been built yet +if [ ! -f $ROS2_WS/install/setup.bash ]; then + echo "Workspace has not been built yet. Building workspace..." + cd $ROS2_WS + # Ref: https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html + rosdep install --from-paths src --ignore-src -y -r + # TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore ` to ignore x86 packages + # Ref: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html + if [ $(arch) == "aarch64" ]; then + colcon build --symlink-install + else + colcon build --symlink-install + fi + echo "Workspace built." +fi +# TODO: Source other workspace environments as underlay +MULTILINE_PLACEHOLDER # Source workspace environment -# Note: If you have not built your workspace yet, the following command will fail source $ROS2_WS/install/setup.bash diff --git a/husky_ws/docker/.bashrc b/husky_ws/docker/.bashrc index 44dfefc6..f65d6e18 100644 --- a/husky_ws/docker/.bashrc +++ b/husky_ws/docker/.bashrc @@ -1,12 +1,34 @@ # Source global ROS2 environment source /opt/ros/$ROS_DISTRO/setup.bash -# Source custom global environment +# Optionally perform apt update if it has not been executed yet +if [ -z "$( ls -A '/var/lib/apt/lists' )" ]; then + echo "apt-get update has not been executed yet. Running sudo apt-get update..." + sudo apt-get update +fi +# Optionally perform rosdep update if it has not been executed yet +if [ ! -d $HOME/.ros/rosdep/sources.cache ]; then + echo "rosdep update has not been executed yet. Running rosdep update..." + rosdep update +fi +# Optionally build the workspace if it has not been built yet +if [ ! -f $ROS2_WS/install/setup.bash ]; then + echo "Workspace has not been built yet. Building workspace..." + cd $ROS2_WS + # Ref: https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html + rosdep install --from-paths src --ignore-src -y -r + # TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore ` to ignore x86 packages + # Ref: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html + if [ $(arch) == "aarch64" ]; then + colcon build --symlink-install + else + colcon build --symlink-install + fi + echo "Workspace built." +fi +# TODO: Source other workspace environments as underlay +# Source Clearpath robot environment source ~/ros2_ws/install/local_setup.bash -# Source Clearpath environment -# Note: The setup.bash file is created by the script "/usr/sbin/clearpath-robot-generate", -# do not modify this file manually, as it will be overwritten. Try to modify the -# "/etc/clearpath/robot.yaml" file instead, and then run the script again. +# Source Clearpath default environment installed by `clearpath_computer_installer.sh` source /etc/clearpath/setup.bash # Source workspace environment -# Note: If you have not built your workspace yet, the following command will fail source $ROS2_WS/install/setup.bash diff --git a/kobuki_ws/docker/.bashrc b/kobuki_ws/docker/.bashrc index 9a063f87..ba8a33c9 100644 --- a/kobuki_ws/docker/.bashrc +++ b/kobuki_ws/docker/.bashrc @@ -1,7 +1,32 @@ # Source global ROS2 environment source /opt/ros/$ROS_DISTRO/setup.bash +# Optionally perform apt update if it has not been executed yet +if [ -z "$( ls -A '/var/lib/apt/lists' )" ]; then + echo "apt-get update has not been executed yet. Running sudo apt-get update..." + sudo apt-get update +fi +# Optionally perform rosdep update if it has not been executed yet +if [ ! -d $HOME/.ros/rosdep/sources.cache ]; then + echo "rosdep update has not been executed yet. Running rosdep update..." + rosdep update +fi +# Optionally build the workspace if it has not been built yet +if [ ! -f $ROS2_WS/install/setup.bash ]; then + echo "Workspace has not been built yet. Building workspace..." + cd $ROS2_WS + # Ref: https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html + rosdep install --from-paths src --ignore-src -y -r + # TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore ` to ignore x86 packages + # Ref: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html + if [ $(arch) == "aarch64" ]; then + colcon build --symlink-install + else + colcon build --symlink-install + fi + echo "Workspace built." +fi +# TODO: Source other workspace environments as underlay # Source kobuki driver workspace environment source ~/kobuki_driver_ws/install/local_setup.bash # Source workspace environment -# Note: If you have not built your workspace yet, the following command will fail source $ROS2_WS/install/setup.bash diff --git a/rtabmap_ws/docker/.bashrc b/rtabmap_ws/docker/.bashrc index c61ceaa5..f9184745 100644 --- a/rtabmap_ws/docker/.bashrc +++ b/rtabmap_ws/docker/.bashrc @@ -1,5 +1,31 @@ # Source global ROS2 environment source /opt/ros/$ROS_DISTRO/setup.bash +# Optionally perform apt update if it has not been executed yet +if [ -z "$( ls -A '/var/lib/apt/lists' )" ]; then + echo "apt-get update has not been executed yet. Running sudo apt-get update..." + sudo apt-get update +fi +# Optionally perform rosdep update if it has not been executed yet +if [ ! -d $HOME/.ros/rosdep/sources.cache ]; then + echo "rosdep update has not been executed yet. Running rosdep update..." + rosdep update +fi +# Optionally build the workspace if it has not been built yet +if [ ! -f $ROS2_WS/install/setup.bash ]; then + echo "Workspace has not been built yet. Building workspace..." + cd $ROS2_WS + # Ref: https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html + rosdep install --from-paths src --ignore-src -y -r + # TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore ` to ignore x86 packages + # Ref: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html + if [ $(arch) == "aarch64" ]; then + colcon build --symlink-install + else + colcon build --symlink-install + fi + echo "Workspace built." +fi +# TODO: Source other workspace environments as underlay +MULTILINE_PLACEHOLDER # Source workspace environment -# Note: If you have not built your workspace yet, the following command will fail -source $ROS2_WS/install/setup.bash \ No newline at end of file +source $ROS2_WS/install/setup.bash diff --git a/template_ws/docker/.bashrc b/template_ws/docker/.bashrc index 2fb551f1..ed090d4a 100644 --- a/template_ws/docker/.bashrc +++ b/template_ws/docker/.bashrc @@ -25,5 +25,6 @@ if [ ! -f $ROS2_WS/install/setup.bash ]; then fi echo "Workspace built." fi +# TODO: Source other workspace environments as underlay # Source workspace environment source $ROS2_WS/install/setup.bash diff --git a/tests/diff_base/docker/.bashrc b/tests/diff_base/docker/.bashrc new file mode 100644 index 00000000..9938f36d --- /dev/null +++ b/tests/diff_base/docker/.bashrc @@ -0,0 +1,31 @@ +# Source global ROS2 environment +source /opt/ros/$ROS_DISTRO/setup.bash +# Optionally perform apt update if it has not been executed yet +if [ -z "$( ls -A '/var/lib/apt/lists' )" ]; then + echo "apt-get update has not been executed yet. Running sudo apt-get update..." + sudo apt-get update +fi +# Optionally perform rosdep update if it has not been executed yet +if [ ! -d $HOME/.ros/rosdep/sources.cache ]; then + echo "rosdep update has not been executed yet. Running rosdep update..." + rosdep update +fi +# Optionally build the workspace if it has not been built yet +if [ ! -f $ROS2_WS/install/setup.bash ]; then + echo "Workspace has not been built yet. Building workspace..." + cd $ROS2_WS + # Ref: https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html + rosdep install --from-paths src --ignore-src -y -r + # TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore ` to ignore x86 packages + # Ref: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html + if [ $(arch) == "aarch64" ]; then + colcon build --symlink-installPLACEHOLDER + else + colcon build --symlink-install + fi + echo "Workspace built." +fi +# TODO: Source other workspace environments as underlay +MULTILINE_PLACEHOLDER +# Source workspace environment +source $ROS2_WS/install/setup.bash diff --git a/tests/lint_comp_template.py b/tests/lint_comp_template.py index 9a2fc853..d8b57e42 100644 --- a/tests/lint_comp_template.py +++ b/tests/lint_comp_template.py @@ -43,3 +43,4 @@ def error(msg, i): compare_file_with_template(".devcontainer/devcontainer.json", ["ros1_bridge_ws"]) compare_file_with_template(".gitignore") +compare_file_with_template("docker/.bashrc") diff --git a/vlp_ws/docker/.bashrc b/vlp_ws/docker/.bashrc index c1169b05..e0db1d55 100644 --- a/vlp_ws/docker/.bashrc +++ b/vlp_ws/docker/.bashrc @@ -1,21 +1,31 @@ # Source global ROS2 environment source /opt/ros/$ROS_DISTRO/setup.bash -# Source workspace environment - -# Check if the workspace has been built by check install/setup.bash +# Optionally perform apt update if it has not been executed yet +if [ -z "$( ls -A '/var/lib/apt/lists' )" ]; then + echo "apt-get update has not been executed yet. Running sudo apt-get update..." + sudo apt-get update +fi +# Optionally perform rosdep update if it has not been executed yet +if [ ! -d $HOME/.ros/rosdep/sources.cache ]; then + echo "rosdep update has not been executed yet. Running rosdep update..." + rosdep update +fi +# Optionally build the workspace if it has not been built yet if [ ! -f $ROS2_WS/install/setup.bash ]; then echo "Workspace has not been built yet. Building workspace..." cd $ROS2_WS - - # If command "arch" is "aarch64", don't build velodyne_gazebo_plugins + # Ref: https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html + rosdep install --from-paths src --ignore-src -y -r + # TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore ` to ignore x86 packages + # Ref: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html if [ $(arch) == "aarch64" ]; then colcon build --symlink-install --packages-ignore velodyne_gazebo_plugins else colcon build --symlink-install fi - echo "Workspace built." fi - -# Note: If you have not built your workspace yet, the following command will fail +# TODO: Source other workspace environments as underlay +MULTILINE_PLACEHOLDER +# Source workspace environment source $ROS2_WS/install/setup.bash From 18bd8ab2f56fa2fd19ffd5af0fb3afe42cc8b785 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 04:49:51 +0800 Subject: [PATCH 09/24] test: Add tests for `dockerignore` --- tests/diff_base/docker/.dockerignore | 3 +++ tests/lint_comp_template.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/diff_base/docker/.dockerignore diff --git a/tests/diff_base/docker/.dockerignore b/tests/diff_base/docker/.dockerignore new file mode 100644 index 00000000..fe415ff7 --- /dev/null +++ b/tests/diff_base/docker/.dockerignore @@ -0,0 +1,3 @@ +* +!.bashrc +MULTILINE_PLACEHOLDER \ No newline at end of file diff --git a/tests/lint_comp_template.py b/tests/lint_comp_template.py index d8b57e42..0d1b8da2 100644 --- a/tests/lint_comp_template.py +++ b/tests/lint_comp_template.py @@ -41,6 +41,7 @@ def error(msg, i): error("Expected line deletion and addition to differ only in the placeholder", i) i += 2 -compare_file_with_template(".devcontainer/devcontainer.json", ["ros1_bridge_ws"]) +compare_file_with_template(".devcontainer/devcontainer.json", ignored_workspaces=["ros1_bridge_ws"]) compare_file_with_template(".gitignore") compare_file_with_template("docker/.bashrc") +compare_file_with_template("docker/.dockerignore", ignored_workspaces=["ros1_bridge_ws", "orbslam3_ws"]) From 6a9153027f234027f5f0dbf28a0a448a46abfe27 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 05:02:54 +0800 Subject: [PATCH 10/24] refactor: Unify docker compose service name --- cartographer_ws/.devcontainer/devcontainer.json | 2 +- cartographer_ws/docker/compose.yaml | 2 +- orbslam3_ws/.devcontainer/devcontainer.json | 2 +- orbslam3_ws/docker/compose.yaml | 2 +- rtabmap_ws/.devcontainer/devcontainer.json | 2 +- tests/diff_base/.devcontainer/devcontainer.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cartographer_ws/.devcontainer/devcontainer.json b/cartographer_ws/.devcontainer/devcontainer.json index ed47321a..6ab46b9c 100644 --- a/cartographer_ws/.devcontainer/devcontainer.json +++ b/cartographer_ws/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ { "name": "Catographer", "dockerComposeFile": "../docker/compose.yaml", - "service": "ros2-cartographer", + "service": "cartographer-ws", // Workspace settings "workspaceFolder": "/home/ros2-essentials/cartographer_ws", // Vscode extensions diff --git a/cartographer_ws/docker/compose.yaml b/cartographer_ws/docker/compose.yaml index 8bc01aa9..9a361834 100644 --- a/cartographer_ws/docker/compose.yaml +++ b/cartographer_ws/docker/compose.yaml @@ -1,5 +1,5 @@ services: - ros2-cartographer: + cartographer-ws: build: . image: j3soon/ros2-cartographer-ws container_name: ros2-cartographer-ws diff --git a/orbslam3_ws/.devcontainer/devcontainer.json b/orbslam3_ws/.devcontainer/devcontainer.json index af5e2fd7..2751f884 100644 --- a/orbslam3_ws/.devcontainer/devcontainer.json +++ b/orbslam3_ws/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ { "name": "ORB-SLAM3", "dockerComposeFile": "../docker/compose.yaml", - "service": "ros2-orbslam3", + "service": "orbslam3-ws", // Workspace settings "workspaceFolder": "/home/ros2-essentials/orbslam3_ws", // Vscode extensions diff --git a/orbslam3_ws/docker/compose.yaml b/orbslam3_ws/docker/compose.yaml index 48dab944..9bad1b1f 100644 --- a/orbslam3_ws/docker/compose.yaml +++ b/orbslam3_ws/docker/compose.yaml @@ -1,6 +1,6 @@ services: # Container-1 - ros2-orbslam3: + orbslam3-ws: # Build or Reference the image build: . image: j3soon/ros2-orbslam3-ws diff --git a/rtabmap_ws/.devcontainer/devcontainer.json b/rtabmap_ws/.devcontainer/devcontainer.json index 205d640f..2c486931 100644 --- a/rtabmap_ws/.devcontainer/devcontainer.json +++ b/rtabmap_ws/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ { "name": "RTAB-Map", "dockerComposeFile": "../docker/compose.yaml", - "service": "ros2-rtabmap", + "service": "rtabmap-ws", // Workspace settings "workspaceFolder": "/home/ros2-essentials/rtabmap_ws", // Vscode extensions diff --git a/tests/diff_base/.devcontainer/devcontainer.json b/tests/diff_base/.devcontainer/devcontainer.json index 597744fa..bf81ac72 100644 --- a/tests/diff_base/.devcontainer/devcontainer.json +++ b/tests/diff_base/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ { "name": "PLACEHOLDER", "dockerComposeFile": "../docker/compose.yaml", - "service": "PLACEHOLDER", + "service": "PLACEHOLDER-ws", // Workspace settings "workspaceFolder": "/home/ros2-essentials/PLACEHOLDER_ws", // Vscode extensions From 62d572160a3b66e815d30ce0024b728dc5ab2673 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 06:08:08 +0800 Subject: [PATCH 11/24] refactor: Unify docker compose across all workspaces and add tests --- README.md | 22 +++---- cartographer_ws/docker/compose.yaml | 58 ++++++++++++------ husky_ws/docker/compose.yaml | 42 ++++++++----- kobuki_ws/docker/compose.yaml | 67 +++++++++++---------- orbslam3_ws/docker/compose.yaml | 64 ++++++++++++++++---- rtabmap_ws/docker/compose.yaml | 71 ++++++++++++---------- template_ws/docker/compose.yaml | 2 +- tests/diff_base/docker/Dockerfile | 92 +++++++++++++++++++++++++++++ tests/diff_base/docker/compose.yaml | 67 +++++++++++++++++++++ tests/lint_comp_template.py | 39 ++++++++++-- vlp_ws/docker/compose.yaml | 62 +++++++++---------- 11 files changed, 432 insertions(+), 154 deletions(-) create mode 100644 tests/diff_base/docker/Dockerfile create mode 100644 tests/diff_base/docker/compose.yaml diff --git a/README.md b/README.md index 4cd3bddc..ba389f94 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,17 @@ The following Docker images can be pulled by `docker pull ` or by `d Pulling the pre-built Docker images can bypass the time-consuming building process (for both docker compose & devcontainers). -| Docker Image | Description | amd64 | arm64 | -|--------------|-------------|-------|-------| -| [j3soon/ros2-template-ws](https://hub.docker.com/r/j3soon/ros2-template-ws/tags) | [`./template_ws`](./template_ws) | ✔️ | ❌ | -| [j3soon/ros2-orbslam3-ws](https://hub.docker.com/r/j3soon/ros2-orbslam3-ws/tags) | [`./orbslam3_ws`](./orbslam3_ws) | ✔️ | ❌ | -| [j3soon/ros2-rtabmap-ws](https://hub.docker.com/r/j3soon/ros2-rtabmap-ws/tags) | [`./rtabmap_ws`](./rtabmap_ws) | ✔️ | ❌ | -| [j3soon/ros2-ros1-bridge-ws](https://hub.docker.com/r/j3soon/ros2-ros1-bridge-ws/tags) | [`./ros1_bridge_ws`](./ros1_bridge_ws) | ✔️ | ❌ | -| [j3soon/ros2-ros1-bridge-build-ws](https://hub.docker.com/r/j3soon/ros2-ros1-bridge-build-ws/tags) | [`./ros1_bridge_ws`](./ros1_bridge_ws) | ✔️ | ❌ | -| [j3soon/ros2-cartographer-ws](https://hub.docker.com/r/j3soon/ros2-cartographer-ws/tags) | [`./cartographer_ws`](./cartographer_ws) | ✔️ | ❌ | -| [j3soon/ros2-husky-ws](https://hub.docker.com/r/j3soon/ros2-husky-ws/tags) | [`./husky_ws`](./husky_ws) | ✔️ | ✔️ | -| [j3soon/ros2-kobuki-ws](https://hub.docker.com/r/j3soon/ros2-kobuki-ws/tags) | [`./kobuki_ws`](./kobuki_ws) | ✔️ | ✔️ | -| [j3soon/ros2-vlp-ws](https://hub.docker.com/r/j3soon/ros2-vlp-ws/tags) | [`./vlp_ws`](./vlp_ws) | ✔️ | ✔️ | +| Docker Image | Description | amd64 | arm64 | Notes | +|--------------|-------------|-------|-------|-------| +| [j3soon/ros2-template-ws](https://hub.docker.com/r/j3soon/ros2-template-ws/tags) | [`./template_ws`](./template_ws) | ✔️ | ❌ | | +| [j3soon/ros2-orbslam3-ws](https://hub.docker.com/r/j3soon/ros2-orbslam3-ws/tags) | [`./orbslam3_ws`](./orbslam3_ws) | ✔️ | ❌ | | +| [j3soon/ros2-rtabmap-ws](https://hub.docker.com/r/j3soon/ros2-rtabmap-ws/tags) | [`./rtabmap_ws`](./rtabmap_ws) | ✔️ | ❌ | | +| [j3soon/ros2-ros1-bridge-ws](https://hub.docker.com/r/j3soon/ros2-ros1-bridge-ws/tags) | [`./ros1_bridge_ws`](./ros1_bridge_ws) | ✔️ | ❌ | Linting Skipped | +| [j3soon/ros2-ros1-bridge-build-ws](https://hub.docker.com/r/j3soon/ros2-ros1-bridge-build-ws/tags) | [`./ros1_bridge_ws`](./ros1_bridge_ws) | ✔️ | ❌ | Linting Skipped | +| [j3soon/ros2-cartographer-ws](https://hub.docker.com/r/j3soon/ros2-cartographer-ws/tags) | [`./cartographer_ws`](./cartographer_ws) | ✔️ | ❌ | | +| [j3soon/ros2-husky-ws](https://hub.docker.com/r/j3soon/ros2-husky-ws/tags) | [`./husky_ws`](./husky_ws) | ✔️ | ✔️ | | +| [j3soon/ros2-kobuki-ws](https://hub.docker.com/r/j3soon/ros2-kobuki-ws/tags) | [`./kobuki_ws`](./kobuki_ws) | ✔️ | ✔️ | | +| [j3soon/ros2-vlp-ws](https://hub.docker.com/r/j3soon/ros2-vlp-ws/tags) | [`./vlp_ws`](./vlp_ws) | ✔️ | ✔️ | | ## Contributors diff --git a/cartographer_ws/docker/compose.yaml b/cartographer_ws/docker/compose.yaml index 9a361834..4a47aed7 100644 --- a/cartographer_ws/docker/compose.yaml +++ b/cartographer_ws/docker/compose.yaml @@ -1,42 +1,66 @@ services: cartographer-ws: - build: . + build: + context: . + dockerfile: Dockerfile + # TODO: Specify the target platform to build the image, otherwise it will build for the host platform. + # Reference: https://docs.docker.com/compose/compose-file/build/#platforms + # platforms: + # - "linux/arm64" image: j3soon/ros2-cartographer-ws container_name: ros2-cartographer-ws stdin_open: true tty: true + # TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices. privileged: true command: /bin/bash network_mode: host - working_dir: /home/ros2-agv-essentials/cartographer_ws + working_dir: /home/ros2-essentials/cartographer_ws environment: - - DISPLAY=${DISPLAY} - # Set ros2 environment variables. + # Set X11 server environment variable for existing display. + - DISPLAY=$DISPLAY + # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html - - ROS_LOCALHOST_ONLY=1 - - ROS_DOMAIN_ID=42 - - ROS2_WS=/home/ros2-agv-essentials/cartographer_ws + # - https://docs.ros.org/en/humble/Tutorials/Demos/Logging-and-logger-configuration.html#console-output-colorizing + - ROS_LOCALHOST_ONLY=0 + # Localhost only is disabled by default to allow communication with external devices. + - ROS_DOMAIN_ID=0 + # Domain ID is set to 0 to allow communication through ros1_bridge. + - RCUTILS_COLORIZED_OUTPUT=1 + - ROS2_WS=/home/ros2-essentials/cartographer_ws + # TODO: Uncomment the lines below to enable GPU support. + # deploy: + # # Reference : https://docs.docker.com/compose/gpu-support/ + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: all + # capabilities: [ gpu ] volumes: - # Mount local timezone into container. ( Readonly ) + # Mount local timezone into container. # Reference: https://stackoverflow.com/questions/57607381/how-do-i-change-timezone-in-a-docker-container - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro # Mount X11 server - /tmp/.X11-unix:/tmp/.X11-unix + # X11-unix is mounted to allow GUI applications to display on host. - $HOME/.Xauthority:/home/user/.Xauthority - # Direct Rendering Infrastructure + # Xauthority is mounted to allow X11 forwarding for remote display. + # Mount Direct Rendering Infrastructure (DRI) for hardware acceleration support such as OpenGL. - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - /dev/snd:/dev/snd + # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 - - ./cache/.gazebo:/home/user/.gazebo - # Mounting the following directories will forbid direct deletion. - # Consider mount these directories only if the build process is slow. - # "source=${localWorkspaceFolder}/../cache/humble/build,target=/home/ws/build,type=bind", - # "source=${localWorkspaceFolder}/../cache/humble/install,target=/home/ws/install,type=bind", - # "source=${localWorkspaceFolder}/../cache/humble/log,target=/home/ws/log,type=bind" - # Mount workspace - - ../..:/home/ros2-agv-essentials + # Note that this volume is shared among all workspaces. + - gazebo-cache:/home/user/.gazebo + # Mount root workspace to allow easy access to all workspaces. + - ../..:/home/ros2-essentials +volumes: + gazebo-cache: + name: ros2-gazebo-cache diff --git a/husky_ws/docker/compose.yaml b/husky_ws/docker/compose.yaml index 124f14cf..75cce06f 100644 --- a/husky_ws/docker/compose.yaml +++ b/husky_ws/docker/compose.yaml @@ -3,7 +3,7 @@ services: build: context: . dockerfile: Dockerfile - # Specify the target platform to build the image. + # TODO: Specify the target platform to build the image, otherwise it will build for the host platform. # Reference: https://docs.docker.com/compose/compose-file/build/#platforms # platforms: # - "linux/arm64" @@ -11,24 +11,28 @@ services: container_name: ros2-husky-ws stdin_open: true tty: true + # TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices. privileged: true command: /bin/bash network_mode: host - working_dir: /home/ros2-agv-essentials/husky_ws + working_dir: /home/ros2-essentials/husky_ws environment: - - DISPLAY=${DISPLAY} - # Set ros2 environment variables. + # Set X11 server environment variable for existing display. + - DISPLAY=$DISPLAY + # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html # - https://docs.ros.org/en/humble/Tutorials/Demos/Logging-and-logger-configuration.html#console-output-colorizing - # - ROS_LOCALHOST_ONLY=1 - - ROS_DOMAIN_ID=42 - - ROS2_WS=/home/ros2-agv-essentials/husky_ws + - ROS_LOCALHOST_ONLY=0 + # Localhost only is disabled by default to allow communication with external devices. + - ROS_DOMAIN_ID=0 + # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - # If you want to access GPU, please uncomment the lines below. - # Reference : https://docs.docker.com/compose/gpu-support/ + - ROS2_WS=/home/ros2-essentials/husky_ws + # TODO: Uncomment the lines below to enable GPU support. # deploy: + # # Reference : https://docs.docker.com/compose/gpu-support/ # resources: # reservations: # devices: @@ -36,17 +40,27 @@ services: # count: all # capabilities: [ gpu ] volumes: - # Mount local timezone into container. ( Readonly ) + # Mount local timezone into container. # Reference: https://stackoverflow.com/questions/57607381/how-do-i-change-timezone-in-a-docker-container - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro # Mount X11 server - /tmp/.X11-unix:/tmp/.X11-unix + # X11-unix is mounted to allow GUI applications to display on host. - $HOME/.Xauthority:/home/user/.Xauthority - # Mount devices + # Xauthority is mounted to allow X11 forwarding for remote display. + # Mount Direct Rendering Infrastructure (DRI) for hardware acceleration support such as OpenGL. + # - /dev/dri:/dev/dri + # Mount sound card to prevent Gazebo warning. + # - /dev/snd:/dev/snd + # TODO: Uncomment the line below and comment out the two entries above to enable USB support. - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 - - ./cache/.gazebo:/home/user/.gazebo - # Mount workspace - - ../..:/home/ros2-agv-essentials + # Note that this volume is shared among all workspaces. + - gazebo-cache:/home/user/.gazebo + # Mount root workspace to allow easy access to all workspaces. + - ../..:/home/ros2-essentials +volumes: + gazebo-cache: + name: ros2-gazebo-cache diff --git a/kobuki_ws/docker/compose.yaml b/kobuki_ws/docker/compose.yaml index 3063a4a0..80a8fdad 100644 --- a/kobuki_ws/docker/compose.yaml +++ b/kobuki_ws/docker/compose.yaml @@ -3,7 +3,7 @@ services: build: context: . dockerfile: Dockerfile - # Specify the target platform to build the image. + # TODO: Specify the target platform to build the image, otherwise it will build for the host platform. # Reference: https://docs.docker.com/compose/compose-file/build/#platforms # platforms: # - "linux/arm64" @@ -11,52 +11,57 @@ services: container_name: ros2-kobuki-ws stdin_open: true tty: true + # TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices. privileged: true command: /bin/bash network_mode: host - working_dir: /home/ros2-agv-essentials/kobuki_ws + working_dir: /home/ros2-essentials/kobuki_ws environment: - - DISPLAY=${DISPLAY} - # Set ros2 environment variables. + # Set X11 server environment variable for existing display. + - DISPLAY=$DISPLAY + # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html # - https://docs.ros.org/en/humble/Tutorials/Demos/Logging-and-logger-configuration.html#console-output-colorizing - - ROS_LOCALHOST_ONLY=1 - - ROS_DOMAIN_ID=42 - - ROS2_WS=/home/ros2-agv-essentials/kobuki_ws + - ROS_LOCALHOST_ONLY=0 + # Localhost only is disabled by default to allow communication with external devices. + - ROS_DOMAIN_ID=0 + # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - # If you want to access GPU, please uncomment the lines below. - # Reference : https://docs.docker.com/compose/gpu-support/ - # deploy: - # resources: - # reservations: - # devices: - # - driver: nvidia - # count: all - # capabilities: [ gpu ] + - ROS2_WS=/home/ros2-essentials/kobuki_ws + # TODO: Uncomment the lines below to enable GPU support. + # deploy: + # # Reference : https://docs.docker.com/compose/gpu-support/ + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: all + # capabilities: [ gpu ] volumes: - # Mount local timezone into container. ( Readonly ) + # Mount local timezone into container. # Reference: https://stackoverflow.com/questions/57607381/how-do-i-change-timezone-in-a-docker-container - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro # Mount X11 server - /tmp/.X11-unix:/tmp/.X11-unix + # X11-unix is mounted to allow GUI applications to display on host. - $HOME/.Xauthority:/home/user/.Xauthority - # Mount devices. - # If you don't want to mount all devices, you can specify the ones you need. - # But make sure to mount the device below: - # - Direct Rendering Infrastructure: /dev/dri - # - Sound Card: /dev/snd - # - Kubuki Base: usually /dev/ttyUSB0 + # Xauthority is mounted to allow X11 forwarding for remote display. + # Mount Direct Rendering Infrastructure (DRI) for hardware acceleration support such as OpenGL. + # - /dev/dri:/dev/dri + # Mount sound card to prevent Gazebo warning. + # - /dev/snd:/dev/snd + # TODO: Uncomment the line below and comment out the two entries above to enable USB support. - /dev:/dev + # Kobuki is usually mounted at `/dev/ttyUSB0` # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 - - ./cache/.gazebo:/home/user/.gazebo - # Mounting the following directories will forbid direct deletion. - # Consider mount these directories only if the build process is slow. - # "source=${localWorkspaceFolder}/../cache/humble/build,target=/home/ws/build,type=bind", - # "source=${localWorkspaceFolder}/../cache/humble/install,target=/home/ws/install,type=bind", - # "source=${localWorkspaceFolder}/../cache/humble/log,target=/home/ws/log,type=bind" - # Mount workspace - - ../..:/home/ros2-agv-essentials + # Note that this volume is shared among all workspaces. + - gazebo-cache:/home/user/.gazebo + # Mount root workspace to allow easy access to all workspaces. + - ../..:/home/ros2-essentials +volumes: + gazebo-cache: + name: ros2-gazebo-cache diff --git a/orbslam3_ws/docker/compose.yaml b/orbslam3_ws/docker/compose.yaml index 9bad1b1f..458bf896 100644 --- a/orbslam3_ws/docker/compose.yaml +++ b/orbslam3_ws/docker/compose.yaml @@ -1,28 +1,66 @@ services: - # Container-1 orbslam3-ws: - # Build or Reference the image - build: . + build: + context: . + dockerfile: Dockerfile + # TODO: Specify the target platform to build the image, otherwise it will build for the host platform. + # Reference: https://docs.docker.com/compose/compose-file/build/#platforms + # platforms: + # - "linux/arm64" image: j3soon/ros2-orbslam3-ws container_name: ros2-orbslam3-ws stdin_open: true tty: true + # TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices. privileged: true - command: bash + command: /bin/bash network_mode: host - working_dir: /home/ros2-agv-essentials/orbslam3_ws - - # Container Settings + working_dir: /home/ros2-essentials/orbslam3_ws environment: - - DISPLAY=${DISPLAY} + # Set X11 server environment variable for existing display. + - DISPLAY=$DISPLAY + # TODO: Set ros2 environment variables. + # References: + # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html + # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html + # - https://docs.ros.org/en/humble/Tutorials/Demos/Logging-and-logger-configuration.html#console-output-colorizing + - ROS_LOCALHOST_ONLY=0 + # Localhost only is disabled by default to allow communication with external devices. + - ROS_DOMAIN_ID=0 + # Domain ID is set to 0 to allow communication through ros1_bridge. + - RCUTILS_COLORIZED_OUTPUT=1 + - ROS2_WS=/home/ros2-essentials/orbslam3_ws + # TODO: Uncomment the lines below to enable GPU support. + # deploy: + # # Reference : https://docs.docker.com/compose/gpu-support/ + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: all + # capabilities: [ gpu ] volumes: - # Mount local timezone + # Mount local timezone into container. + # Reference: https://stackoverflow.com/questions/57607381/how-do-i-change-timezone-in-a-docker-container - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro - # X-11 mount + # Mount X11 server - /tmp/.X11-unix:/tmp/.X11-unix + # X11-unix is mounted to allow GUI applications to display on host. - $HOME/.Xauthority:/home/user/.Xauthority - # Direct Rendering Infrastructure + # Xauthority is mounted to allow X11 forwarding for remote display. + # Mount Direct Rendering Infrastructure (DRI) for hardware acceleration support such as OpenGL. - /dev/dri:/dev/dri - # Mount workspace - - ..:/home/ros2-agv-essentials/orbslam3_ws + # Mount sound card to prevent Gazebo warning. + - /dev/snd:/dev/snd + # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # - /dev:/dev + # Mount Gazebo models directory to reuse models downloaded during first launch. + # Reference: https://answers.ros.org/question/365658 + # Note that this volume is shared among all workspaces. + - gazebo-cache:/home/user/.gazebo + # Mount root workspace to allow easy access to all workspaces. + - ../..:/home/ros2-essentials +volumes: + gazebo-cache: + name: ros2-gazebo-cache diff --git a/rtabmap_ws/docker/compose.yaml b/rtabmap_ws/docker/compose.yaml index 5e69b239..68a61359 100644 --- a/rtabmap_ws/docker/compose.yaml +++ b/rtabmap_ws/docker/compose.yaml @@ -1,57 +1,66 @@ services: - # Container for ROS2 rtabmap rtabmap-ws: - # Build or Reference the image - build: . + build: + context: . + dockerfile: Dockerfile + # TODO: Specify the target platform to build the image, otherwise it will build for the host platform. + # Reference: https://docs.docker.com/compose/compose-file/build/#platforms + # platforms: + # - "linux/arm64" image: j3soon/ros2-rtabmap-ws container_name: ros2-rtabmap-ws stdin_open: true tty: true + # TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices. privileged: true - command: bash + command: /bin/bash network_mode: host - working_dir: /home/ros2-agv-essentials/rtabmap_ws - - # Container Settings + working_dir: /home/ros2-essentials/rtabmap_ws environment: - - DISPLAY=${DISPLAY} - # Set ros2 environment variables. + # Set X11 server environment variable for existing display. + - DISPLAY=$DISPLAY + # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html # - https://docs.ros.org/en/humble/Tutorials/Demos/Logging-and-logger-configuration.html#console-output-colorizing - - ROS_LOCALHOST_ONLY=1 - - ROS_DOMAIN_ID=42 - - ROS2_WS=/home/ros2-agv-essentials/rtabmap_ws + - ROS_LOCALHOST_ONLY=0 + # Localhost only is disabled by default to allow communication with external devices. + - ROS_DOMAIN_ID=0 + # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - # If you want to access GPU, please uncomment the lines below. - # Reference : https://docs.docker.com/compose/gpu-support/ - # deploy: - # resources: - # reservations: - # devices: - # - driver: nvidia - # count: all - # capabilities: [ gpu ] + - ROS2_WS=/home/ros2-essentials/rtabmap_ws + # TODO: Uncomment the lines below to enable GPU support. + # deploy: + # # Reference : https://docs.docker.com/compose/gpu-support/ + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: all + # capabilities: [ gpu ] volumes: - # Mount local timezone into container. ( Readonly ) + # Mount local timezone into container. # Reference: https://stackoverflow.com/questions/57607381/how-do-i-change-timezone-in-a-docker-container - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro # Mount X11 server - /tmp/.X11-unix:/tmp/.X11-unix + # X11-unix is mounted to allow GUI applications to display on host. - $HOME/.Xauthority:/home/user/.Xauthority - # Direct Rendering Infrastructure + # Xauthority is mounted to allow X11 forwarding for remote display. + # Mount Direct Rendering Infrastructure (DRI) for hardware acceleration support such as OpenGL. - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - /dev/snd:/dev/snd + # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 - - ./cache/.gazebo:/home/user/.gazebo - # Mounting the following directories will forbid direct deletion. - # Consider mount these directories only if the build process is slow. - # "source=${localWorkspaceFolder}/../cache/humble/build,target=/home/ws/build,type=bind", - # "source=${localWorkspaceFolder}/../cache/humble/install,target=/home/ws/install,type=bind", - # "source=${localWorkspaceFolder}/../cache/humble/log,target=/home/ws/log,type=bind" - # Mount workspace - - ../..:/home/ros2-agv-essentials \ No newline at end of file + # Note that this volume is shared among all workspaces. + - gazebo-cache:/home/user/.gazebo + # Mount root workspace to allow easy access to all workspaces. + - ../..:/home/ros2-essentials +volumes: + gazebo-cache: + name: ros2-gazebo-cache diff --git a/template_ws/docker/compose.yaml b/template_ws/docker/compose.yaml index 00261058..f7601350 100644 --- a/template_ws/docker/compose.yaml +++ b/template_ws/docker/compose.yaml @@ -53,7 +53,7 @@ services: - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - /dev/snd:/dev/snd - # Uncomment the line below and comment out the two entries above to enable USB support. + # TODO: Uncomment the line below and comment out the two entries above to enable USB support. # - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 diff --git a/tests/diff_base/docker/Dockerfile b/tests/diff_base/docker/Dockerfile new file mode 100644 index 00000000..690db6fa --- /dev/null +++ b/tests/diff_base/docker/Dockerfile @@ -0,0 +1,92 @@ +# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +FROM osrf/ros:humble-desktop-full AS amd64 +# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +FROM arm64v8/ros:humble AS arm64 + +# Use docker automatic platform args to select the base image. +# It may be `arm64` or `amd64` depending on the platform. +# Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope +FROM $TARGETARCH + +# Arguments for the default user +ARG USERNAME=user +ARG USER_UID=1000 + +# Keep downloaded packages for caching purposes +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache + +# Upgrade packages +# Ref: https://pythonspeed.com/articles/security-updates-in-docker/ +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1264502398 +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1987107404 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +# Install sudo and create a user with sudo privileges +# Ref: https://stackoverflow.com/a/65434659 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y sudo \ + && useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ + && rm -rf /var/lib/apt/lists/* + +# Install common tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + curl \ + git \ + htop \ + iputils-ping \ + nano \ + net-tools \ + tmux \ + tree \ + unzip \ + vim \ + wget \ + zip \ + && rm -rf /var/lib/apt/lists/* + +# Install Python pip +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Install custom tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + git-extras \ + && rm -rf /var/lib/apt/lists/* + +# Install ROS2 Gazebo packages for amd64 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + if [ "$TARGETARCH" = "amd64" ]; then \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-gazebo-ros-pkgs \ + ros-$ROS_DISTRO-gazebo-ros2-control \ + && rm -rf /var/lib/apt/lists/*; \ + fi + +# Install ROS2 RVIZ and other custom ROS2 packages +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-rviz2 \ + && rm -rf /var/lib/apt/lists/* + +# TODO: Add more commands here +# For example, to install additional packages, uncomment the following lines and add the package names +# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ +# apt-get update && apt-get install -y \ +# $OTHER_PACKAGES \ +# && rm -rf /var/lib/apt/lists/* + +USER $USERNAME +COPY .bashrc /home/$USERNAME/.bashrc +# Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount +RUN mkdir /home/$USERNAME/.gazebo +ENTRYPOINT [] +CMD ["/bin/bash"] diff --git a/tests/diff_base/docker/compose.yaml b/tests/diff_base/docker/compose.yaml new file mode 100644 index 00000000..71302d6f --- /dev/null +++ b/tests/diff_base/docker/compose.yaml @@ -0,0 +1,67 @@ +services: + PLACEHOLDER-ws: + build: + context: . + dockerfile: Dockerfile + # TODO: Specify the target platform to build the image, otherwise it will build for the host platform. + # Reference: https://docs.docker.com/compose/compose-file/build/#platforms + # platforms: + # - "linux/arm64" + image: j3soon/ros2-PLACEHOLDER-ws + container_name: ros2-PLACEHOLDER-ws + stdin_open: true + tty: true + # TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices. + privileged: true + command: /bin/bash + network_mode: host + working_dir: /home/ros2-essentials/PLACEHOLDER_ws + environment: + # Set X11 server environment variable for existing display. + - DISPLAY=$DISPLAY + # TODO: Set ros2 environment variables. + # References: + # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html + # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html + # - https://docs.ros.org/en/humble/Tutorials/Demos/Logging-and-logger-configuration.html#console-output-colorizing + - ROS_LOCALHOST_ONLY=0 + # Localhost only is disabled by default to allow communication with external devices. + - ROS_DOMAIN_ID=0 + # Domain ID is set to 0 to allow communication through ros1_bridge. + - RCUTILS_COLORIZED_OUTPUT=1 + - ROS2_WS=/home/ros2-essentials/PLACEHOLDER_ws + # TODO: Uncomment the lines below to enable GPU support. + # deploy: + # # Reference : https://docs.docker.com/compose/gpu-support/ + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: all + # capabilities: [ gpu ] + volumes: + # Mount local timezone into container. + # Reference: https://stackoverflow.com/questions/57607381/how-do-i-change-timezone-in-a-docker-container + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + # Mount X11 server + - /tmp/.X11-unix:/tmp/.X11-unix + # X11-unix is mounted to allow GUI applications to display on host. + - $HOME/.Xauthority:/home/user/.Xauthority + # Xauthority is mounted to allow X11 forwarding for remote display. + # Mount Direct Rendering Infrastructure (DRI) for hardware acceleration support such as OpenGL. + PLACEHOLDER- /dev/dri:/dev/dri + # Mount sound card to prevent Gazebo warning. + PLACEHOLDER- /dev/snd:/dev/snd + # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + PLACEHOLDER- /dev:/dev +MULTILINE_PLACEHOLDER + # Mount Gazebo models directory to reuse models downloaded during first launch. + # Reference: https://answers.ros.org/question/365658 + # Note that this volume is shared among all workspaces. + - gazebo-cache:/home/user/.gazebo + # Mount root workspace to allow easy access to all workspaces. + - ../..:/home/ros2-essentials +volumes: + gazebo-cache: + name: ros2-gazebo-cache diff --git a/tests/lint_comp_template.py b/tests/lint_comp_template.py index 0d1b8da2..8fe3d8e7 100644 --- a/tests/lint_comp_template.py +++ b/tests/lint_comp_template.py @@ -34,14 +34,41 @@ def error(msg, i): continue if i+1 >= len(diff): error("Odd lines", i) - if not diff[i].startswith('- ') or not diff[i+1].startswith('+ '): - error("Expected no line deletion and addition", i) - regexp = "^" + re.escape(diff[i][2:]).replace('PLACEHOLDER', '.*') + "$" - if not re.match(regexp, diff[i+1][2:]): - error("Expected line deletion and addition to differ only in the placeholder", i) - i += 2 + # Stack and compare + if diff[i].startswith('- '): + stack = [diff[i]] + j = i+1 + while j < len(diff) and diff[j].startswith('- '): + stack.append(j) + j += 1 + k = 0 + while k < len(stack) and diff[j+k].startswith('+ '): + regexp = "^" + re.escape(diff[i+k][2:]).replace('PLACEHOLDER', '.*') + "$" + if not re.match(regexp, diff[j+k][2:]): + error("Expected line deletion and addition to differ only in the placeholder", i) + k += 1 + if k != len(stack): + error("Expected no line deletion and addition", i) + elif diff[i].startswith('+ '): + stack = [diff[i]] + j = i+1 + while j < len(diff) and diff[j].startswith('+ '): + stack.append(j) + j += 1 + k = 0 + while k < len(stack) and diff[j+k].startswith('- '): + regexp = "^" + re.escape(diff[j+k][2:]).replace('PLACEHOLDER', '.*') + "$" + if not re.match(regexp, diff[i+k][2:]): + error("Expected line deletion and addition to differ only in the placeholder", i) + k += 1 + if k != len(stack): + error("Expected no line deletion and addition", i) + else: + raise ValueError("Unexpected diff prefix") + i = j + k compare_file_with_template(".devcontainer/devcontainer.json", ignored_workspaces=["ros1_bridge_ws"]) compare_file_with_template(".gitignore") compare_file_with_template("docker/.bashrc") compare_file_with_template("docker/.dockerignore", ignored_workspaces=["ros1_bridge_ws", "orbslam3_ws"]) +compare_file_with_template("docker/compose.yaml", ignored_workspaces=["ros1_bridge_ws"]) diff --git a/vlp_ws/docker/compose.yaml b/vlp_ws/docker/compose.yaml index 319f7fc3..33f01caf 100644 --- a/vlp_ws/docker/compose.yaml +++ b/vlp_ws/docker/compose.yaml @@ -1,12 +1,9 @@ services: - # Container for ROS2 VLP LiDAR vlp-ws: - # Build or Reference the image build: context: . dockerfile: Dockerfile - # Specify the target platform to build the image. - # It could still be automatically detected. + # TODO: Specify the target platform to build the image, otherwise it will build for the host platform. # Reference: https://docs.docker.com/compose/compose-file/build/#platforms # platforms: # - "linux/arm64" @@ -14,53 +11,58 @@ services: container_name: ros2-vlp-ws stdin_open: true tty: true + # TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices. privileged: true - command: bash + command: /bin/bash network_mode: host - working_dir: /home/ros2-agv-essentials/vlp_ws - - # Container Settings + working_dir: /home/ros2-essentials/vlp_ws environment: - - DISPLAY=${DISPLAY} - # Set ros2 environment variables. + # Set X11 server environment variable for existing display. + - DISPLAY=$DISPLAY + # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html # - https://docs.ros.org/en/humble/Tutorials/Demos/Logging-and-logger-configuration.html#console-output-colorizing - ROS_LOCALHOST_ONLY=0 + # Localhost only is disabled by default to allow communication with external devices. - ROS_DOMAIN_ID=0 - - ROS2_WS=/home/ros2-agv-essentials/vlp_ws + # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - # If you want to access GPU, please uncomment the lines below. - # Reference : https://docs.docker.com/compose/gpu-support/ - # deploy: - # resources: - # reservations: - # devices: - # - driver: nvidia - # count: all - # capabilities: [ gpu ] + - ROS2_WS=/home/ros2-essentials/vlp_ws + # TODO: Uncomment the lines below to enable GPU support. + # deploy: + # # Reference : https://docs.docker.com/compose/gpu-support/ + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: all + # capabilities: [ gpu ] volumes: - # Mount local timezone into container. ( Readonly ) + # Mount local timezone into container. # Reference: https://stackoverflow.com/questions/57607381/how-do-i-change-timezone-in-a-docker-container - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro # Mount X11 server - /tmp/.X11-unix:/tmp/.X11-unix + # X11-unix is mounted to allow GUI applications to display on host. - $HOME/.Xauthority:/home/user/.Xauthority - # Direct Rendering Infrastructure + # Xauthority is mounted to allow X11 forwarding for remote display. + # Mount Direct Rendering Infrastructure (DRI) for hardware acceleration support such as OpenGL. - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - /dev/snd:/dev/snd + # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # - /dev:/dev # Mount shared memory for ROS2 communication. - /dev/shm:/dev/shm # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 - - ./cache/.gazebo:/home/user/.gazebo - # Mounting the following directories will forbid direct deletion. - # Consider mount these directories only if the build process is slow. - # "source=${localWorkspaceFolder}/../cache/humble/build,target=/home/ws/build,type=bind", - # "source=${localWorkspaceFolder}/../cache/humble/install,target=/home/ws/install,type=bind", - # "source=${localWorkspaceFolder}/../cache/humble/log,target=/home/ws/log,type=bind" - # Mount workspace - - ../..:/home/ros2-agv-essentials \ No newline at end of file + # Note that this volume is shared among all workspaces. + - gazebo-cache:/home/user/.gazebo + # Mount root workspace to allow easy access to all workspaces. + - ../..:/home/ros2-essentials +volumes: + gazebo-cache: + name: ros2-gazebo-cache From d9b7da9c9c5c121c290e86e64835ce449b6fe118 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 06:09:37 +0800 Subject: [PATCH 12/24] feat(template_ws): Mount shared memory Co-authored-by: assume --- template_ws/docker/compose.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/template_ws/docker/compose.yaml b/template_ws/docker/compose.yaml index f7601350..bdc9893a 100644 --- a/template_ws/docker/compose.yaml +++ b/template_ws/docker/compose.yaml @@ -53,7 +53,9 @@ services: - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - /dev/snd:/dev/snd - # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # Mount shared memory for ROS2 communication. + - /dev/shm:/dev/shm + # TODO: Uncomment the line below and comment out the three entries above to enable USB support. # - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 From c4e62b69b38342e9e1a299b06b27e72529cf5987 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 06:23:44 +0800 Subject: [PATCH 13/24] refactor: Update and unify docker compose across all workspaces and add tests --- README.md | 10 +++++----- cartographer_ws/docker/compose.yaml | 4 +++- husky_ws/docker/compose.yaml | 4 +++- kobuki_ws/docker/compose.yaml | 5 +++-- orbslam3_ws/docker/compose.yaml | 4 +++- rtabmap_ws/docker/compose.yaml | 4 +++- tests/diff_base/docker/compose.yaml | 5 +++-- tests/lint_comp_template.py | 4 ++++ vlp_ws/docker/compose.yaml | 4 ++-- 9 files changed, 29 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ba389f94..0167252a 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,12 @@ Pulling the pre-built Docker images can bypass the time-consuming building proce | [j3soon/ros2-template-ws](https://hub.docker.com/r/j3soon/ros2-template-ws/tags) | [`./template_ws`](./template_ws) | ✔️ | ❌ | | | [j3soon/ros2-orbslam3-ws](https://hub.docker.com/r/j3soon/ros2-orbslam3-ws/tags) | [`./orbslam3_ws`](./orbslam3_ws) | ✔️ | ❌ | | | [j3soon/ros2-rtabmap-ws](https://hub.docker.com/r/j3soon/ros2-rtabmap-ws/tags) | [`./rtabmap_ws`](./rtabmap_ws) | ✔️ | ❌ | | -| [j3soon/ros2-ros1-bridge-ws](https://hub.docker.com/r/j3soon/ros2-ros1-bridge-ws/tags) | [`./ros1_bridge_ws`](./ros1_bridge_ws) | ✔️ | ❌ | Linting Skipped | -| [j3soon/ros2-ros1-bridge-build-ws](https://hub.docker.com/r/j3soon/ros2-ros1-bridge-build-ws/tags) | [`./ros1_bridge_ws`](./ros1_bridge_ws) | ✔️ | ❌ | Linting Skipped | +| [j3soon/ros2-ros1-bridge-ws](https://hub.docker.com/r/j3soon/ros2-ros1-bridge-ws/tags) | [`./ros1_bridge_ws`](./ros1_bridge_ws) | ✔️ | ❌ | Skip linting | +| [j3soon/ros2-ros1-bridge-build-ws](https://hub.docker.com/r/j3soon/ros2-ros1-bridge-build-ws/tags) | [`./ros1_bridge_ws`](./ros1_bridge_ws) | ✔️ | ❌ | Skip linting | | [j3soon/ros2-cartographer-ws](https://hub.docker.com/r/j3soon/ros2-cartographer-ws/tags) | [`./cartographer_ws`](./cartographer_ws) | ✔️ | ❌ | | -| [j3soon/ros2-husky-ws](https://hub.docker.com/r/j3soon/ros2-husky-ws/tags) | [`./husky_ws`](./husky_ws) | ✔️ | ✔️ | | -| [j3soon/ros2-kobuki-ws](https://hub.docker.com/r/j3soon/ros2-kobuki-ws/tags) | [`./kobuki_ws`](./kobuki_ws) | ✔️ | ✔️ | | -| [j3soon/ros2-vlp-ws](https://hub.docker.com/r/j3soon/ros2-vlp-ws/tags) | [`./vlp_ws`](./vlp_ws) | ✔️ | ✔️ | | +| [j3soon/ros2-husky-ws](https://hub.docker.com/r/j3soon/ros2-husky-ws/tags) | [`./husky_ws`](./husky_ws) | ✔️ | ✔️ | Support real husky | +| [j3soon/ros2-kobuki-ws](https://hub.docker.com/r/j3soon/ros2-kobuki-ws/tags) | [`./kobuki_ws`](./kobuki_ws) | ✔️ | ✔️ | Support real kobuki | +| [j3soon/ros2-vlp-ws](https://hub.docker.com/r/j3soon/ros2-vlp-ws/tags) | [`./vlp_ws`](./vlp_ws) | ✔️ | ✔️ | Support real vlp | ## Contributors diff --git a/cartographer_ws/docker/compose.yaml b/cartographer_ws/docker/compose.yaml index 4a47aed7..b6338f92 100644 --- a/cartographer_ws/docker/compose.yaml +++ b/cartographer_ws/docker/compose.yaml @@ -53,7 +53,9 @@ services: - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - /dev/snd:/dev/snd - # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # Mount shared memory for ROS2 communication. + - /dev/shm:/dev/shm + # TODO: Uncomment the line below and comment out the three entries above to enable USB support. # - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 diff --git a/husky_ws/docker/compose.yaml b/husky_ws/docker/compose.yaml index 75cce06f..6bb8a950 100644 --- a/husky_ws/docker/compose.yaml +++ b/husky_ws/docker/compose.yaml @@ -53,7 +53,9 @@ services: # - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. # - /dev/snd:/dev/snd - # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # Mount shared memory for ROS2 communication. + # - /dev/shm:/dev/shm + # TODO: Uncomment the line below and comment out the three entries above to enable USB support. - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 diff --git a/kobuki_ws/docker/compose.yaml b/kobuki_ws/docker/compose.yaml index 80a8fdad..c59da274 100644 --- a/kobuki_ws/docker/compose.yaml +++ b/kobuki_ws/docker/compose.yaml @@ -53,9 +53,10 @@ services: # - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. # - /dev/snd:/dev/snd - # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # Mount shared memory for ROS2 communication. + # - /dev/shm:/dev/shm + # TODO: Uncomment the line below and comment out the three entries above to enable USB support. - /dev:/dev - # Kobuki is usually mounted at `/dev/ttyUSB0` # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. diff --git a/orbslam3_ws/docker/compose.yaml b/orbslam3_ws/docker/compose.yaml index 458bf896..a8b8cdc1 100644 --- a/orbslam3_ws/docker/compose.yaml +++ b/orbslam3_ws/docker/compose.yaml @@ -53,7 +53,9 @@ services: - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - /dev/snd:/dev/snd - # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # Mount shared memory for ROS2 communication. + - /dev/shm:/dev/shm + # TODO: Uncomment the line below and comment out the three entries above to enable USB support. # - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 diff --git a/rtabmap_ws/docker/compose.yaml b/rtabmap_ws/docker/compose.yaml index 68a61359..111ac02c 100644 --- a/rtabmap_ws/docker/compose.yaml +++ b/rtabmap_ws/docker/compose.yaml @@ -53,7 +53,9 @@ services: - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - /dev/snd:/dev/snd - # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # Mount shared memory for ROS2 communication. + - /dev/shm:/dev/shm + # TODO: Uncomment the line below and comment out the three entries above to enable USB support. # - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 diff --git a/tests/diff_base/docker/compose.yaml b/tests/diff_base/docker/compose.yaml index 71302d6f..19e1cc6d 100644 --- a/tests/diff_base/docker/compose.yaml +++ b/tests/diff_base/docker/compose.yaml @@ -53,9 +53,10 @@ services: PLACEHOLDER- /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. PLACEHOLDER- /dev/snd:/dev/snd - # TODO: Uncomment the line below and comment out the two entries above to enable USB support. + # Mount shared memory for ROS2 communication. + PLACEHOLDER- /dev/shm:/dev/shm + # TODO: Uncomment the line below and comment out the three entries above to enable USB support. PLACEHOLDER- /dev:/dev -MULTILINE_PLACEHOLDER # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. diff --git a/tests/lint_comp_template.py b/tests/lint_comp_template.py index 8fe3d8e7..3375ca30 100644 --- a/tests/lint_comp_template.py +++ b/tests/lint_comp_template.py @@ -43,6 +43,8 @@ def error(msg, i): j += 1 k = 0 while k < len(stack) and diff[j+k].startswith('+ '): + if "- MULTILINE_PLACEHOLDER" in diff[i+k]: + raise error("MULTILINE_PLACEHOLDER is not supported in this case yet", i) regexp = "^" + re.escape(diff[i+k][2:]).replace('PLACEHOLDER', '.*') + "$" if not re.match(regexp, diff[j+k][2:]): error("Expected line deletion and addition to differ only in the placeholder", i) @@ -57,6 +59,8 @@ def error(msg, i): j += 1 k = 0 while k < len(stack) and diff[j+k].startswith('- '): + if "- MULTILINE_PLACEHOLDER" in diff[j+k]: + raise error("MULTILINE_PLACEHOLDER is not supported in this case yet", i) regexp = "^" + re.escape(diff[j+k][2:]).replace('PLACEHOLDER', '.*') + "$" if not re.match(regexp, diff[i+k][2:]): error("Expected line deletion and addition to differ only in the placeholder", i) diff --git a/vlp_ws/docker/compose.yaml b/vlp_ws/docker/compose.yaml index 33f01caf..377e3ec0 100644 --- a/vlp_ws/docker/compose.yaml +++ b/vlp_ws/docker/compose.yaml @@ -53,10 +53,10 @@ services: - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - /dev/snd:/dev/snd - # TODO: Uncomment the line below and comment out the two entries above to enable USB support. - # - /dev:/dev # Mount shared memory for ROS2 communication. - /dev/shm:/dev/shm + # TODO: Uncomment the line below and comment out the three entries above to enable USB support. + # - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. From 58f3456d95a6e29d67805e5d9f395ad98fd37b60 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 07:28:20 +0800 Subject: [PATCH 14/24] refactor: Unify dockerfile across all workspaces and add tests --- cartographer_ws/docker/Dockerfile | 98 ++++++++++++---- husky_ws/docker/Dockerfile | 106 +++++++++++------ kobuki_ws/docker/Dockerfile | 113 +++++++++++------- orbslam3_ws/docker/Dockerfile | 184 +++++++++++++++++++----------- rtabmap_ws/docker/Dockerfile | 130 +++++++++++++++------ template_ws/docker/Dockerfile | 4 +- tests/diff_base/docker/Dockerfile | 14 ++- tests/lint_comp_template.py | 17 ++- tests/lint_dockerfile.py | 28 +++++ vlp_ws/docker/Dockerfile | 117 +++++++++++++------ 10 files changed, 564 insertions(+), 247 deletions(-) create mode 100644 tests/lint_dockerfile.py diff --git a/cartographer_ws/docker/Dockerfile b/cartographer_ws/docker/Dockerfile index 5436a1d8..7d9347b1 100644 --- a/cartographer_ws/docker/Dockerfile +++ b/cartographer_ws/docker/Dockerfile @@ -1,50 +1,102 @@ # Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble -FROM osrf/ros:humble-desktop-full +FROM osrf/ros:humble-desktop-full AS amd64 +# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +FROM arm64v8/ros:humble AS arm64 + +# Use docker automatic platform args to select the base image. +# It may be `arm64` or `amd64` depending on the platform. +# Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope +FROM $TARGETARCH LABEL org.opencontainers.image.authors="assume0701@gmail.com" +# Arguments for the default user ARG USERNAME=user 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 \ - # - # [Optional] Add sudo support. Omit if you don't need to install software after connecting. - && apt-get update \ - && apt-get install -y sudo \ - && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ - && chmod 0440 /etc/sudoers.d/$USERNAME \ - && rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get upgrade -y \ + +# Keep downloaded packages for caching purposes +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache + +# Upgrade packages +# Ref: https://pythonspeed.com/articles/security-updates-in-docker/ +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1264502398 +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1987107404 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get upgrade -y \ && rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get install -y python3-pip \ + +# Install sudo and create a user with sudo privileges +# Ref: https://stackoverflow.com/a/65434659 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y sudo \ + && useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ && rm -rf /var/lib/apt/lists/* -ENV SHELL /bin/bash # Install common tools -RUN apt-get update && apt-get install -y \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ curl \ git \ - git-extras \ htop \ + iputils-ping \ + nano \ net-tools \ tmux \ + tree \ + unzip \ vim \ wget \ + zip \ + && rm -rf /var/lib/apt/lists/* + +# Install Python pip +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + python3-pip \ && rm -rf /var/lib/apt/lists/* -# Install turtlebot3, RVIZ, Gazebo and Cartographer -RUN apt-get update && apt-get install -y \ - ros-$ROS_DISTRO-gazebo-ros-pkgs \ +# Install custom tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + git-extras \ + && rm -rf /var/lib/apt/lists/* + +# Install ROS2 Gazebo packages for amd64 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + if [ "$TARGETARCH" = "amd64" ]; then \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-gazebo-ros-pkgs \ + ros-$ROS_DISTRO-gazebo-ros2-control \ + && rm -rf /var/lib/apt/lists/*; \ + fi + +# Install ROS2 RVIZ and other custom ROS2 packages +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ ros-$ROS_DISTRO-rviz2 \ + && rm -rf /var/lib/apt/lists/* + +# TODO: Add more commands here +# For example, to install additional packages, uncomment the following lines and add the package names +# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ +# apt-get update && apt-get install -y \ +# $OTHER_PACKAGES \ +# && rm -rf /var/lib/apt/lists/* +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ ros-$ROS_DISTRO-cartographer \ ros-$ROS_DISTRO-turtlebot3* \ ros-$ROS_DISTRO-rqt-robot-steering \ && rm -rf /var/lib/apt/lists/* -COPY .bashrc /home/$USERNAME/.bashrc - USER $USERNAME +# Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount +RUN mkdir /home/$USERNAME/.gazebo +# TODO: Run additional commands as non-root user here +COPY .bashrc /home/$USERNAME/.bashrc +# TODO: Copy additional files here +ENTRYPOINT [] CMD ["/bin/bash"] diff --git a/husky_ws/docker/Dockerfile b/husky_ws/docker/Dockerfile index 59c28651..70f3f4da 100644 --- a/husky_ws/docker/Dockerfile +++ b/husky_ws/docker/Dockerfile @@ -1,64 +1,92 @@ -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble -FROM arm64v8/ros:humble AS arm64 # Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble FROM osrf/ros:humble-desktop-full AS amd64 +# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +FROM arm64v8/ros:humble AS arm64 # Use docker automatic platform args to select the base image. # It may be `arm64` or `amd64` depending on the platform. -# Reference: -# - https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope +# Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH LABEL org.opencontainers.image.authors="yuzhong1214@gmail.com" -ARG TARGETARCH +# Arguments for the default user ARG USERNAME=user 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 \ - # - # [Optional] Add sudo support. Omit if you don't need to install software after connecting. - && apt-get update \ - && apt-get install -y sudo \ - && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ - && chmod 0440 /etc/sudoers.d/$USERNAME \ - && rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get upgrade -y \ - && rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get install -y python3-pip \ +# Keep downloaded packages for caching purposes +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache + +# Upgrade packages +# Ref: https://pythonspeed.com/articles/security-updates-in-docker/ +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1264502398 +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1987107404 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get upgrade -y \ && rm -rf /var/lib/apt/lists/* -ENV SHELL /bin/bash -# ******************************************************** -# * Anything else you want to do like clean up goes here * -# ******************************************************** +# Install sudo and create a user with sudo privileges +# Ref: https://stackoverflow.com/a/65434659 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y sudo \ + && useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ + && rm -rf /var/lib/apt/lists/* # Install common tools -RUN apt-get update && apt-get install -y \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ curl \ git \ - git-extras \ htop \ + iputils-ping \ + nano \ net-tools \ tmux \ + tree \ + unzip \ vim \ wget \ + zip \ + && rm -rf /var/lib/apt/lists/* + +# Install Python pip +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Install custom tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + git-extras \ && rm -rf /var/lib/apt/lists/* -RUN if [ "$TARGETARCH" = "amd64" ]; then \ +# Install ROS2 Gazebo packages for amd64 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + if [ "$TARGETARCH" = "amd64" ]; then \ apt-get update && apt-get install -y \ ros-$ROS_DISTRO-gazebo-ros-pkgs \ ros-$ROS_DISTRO-gazebo-ros2-control \ && rm -rf /var/lib/apt/lists/*; \ fi -# Install ROS2 packages -RUN apt-get update && apt-get install -y \ +# Install ROS2 RVIZ and other custom ROS2 packages +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ ros-$ROS_DISTRO-rviz2 \ - # + && rm -rf /var/lib/apt/lists/* + +# TODO: Add more commands here +# For example, to install additional packages, uncomment the following lines and add the package names +# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ +# apt-get update && apt-get install -y \ +# $OTHER_PACKAGES \ +# && rm -rf /var/lib/apt/lists/* +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ # The packages below are used by the Husky repository. ros-$ROS_DISTRO-controller-manager \ ros-$ROS_DISTRO-diff-drive-controller \ @@ -83,24 +111,27 @@ RUN apt-get update && apt-get install -y \ ros-$ROS_DISTRO-slam-toolbox \ ros-$ROS_DISTRO-imu-tools \ ros-$ROS_DISTRO-teleop-twist-keyboard \ - && sudo rm -rf /var/lib/apt/lists/* - -COPY .bashrc /home/$USERNAME/.bashrc + && rm -rf /var/lib/apt/lists/* -# [Optional] Set the default user. Omit if you want to keep the default as root. USER $USERNAME -CMD ["/bin/bash"] +# Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount +RUN mkdir /home/$USERNAME/.gazebo +# TODO: Run additional commands as non-root user here +COPY .bashrc /home/$USERNAME/.bashrc +# TODO: Copy additional files here # Setup husky controller by the script. # Build certain packages from source for arm64. COPY script /home/$USERNAME/script -RUN sudo apt-get update \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + sudo apt-get update \ && bash -ie /home/$USERNAME/script/install-clearpath-robot.sh \ && sudo rm -rf /var/lib/apt/lists/* # Note: The script need to be run as user, not root. # Reference: https://github.com/clearpathrobotics/clearpath_computer_installer/tree/main COPY clearpath_computer_installer /home/$USERNAME/clearpath_computer_installer -RUN sudo apt-get update \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + sudo apt-get update \ && bash -ie /home/$USERNAME/clearpath_computer_installer/clearpath_computer_installer.sh \ && sudo rm -rf /var/lib/apt/lists/* # Setup udev rules. @@ -108,3 +139,6 @@ COPY udev_rules /home/$USERNAME/udev_rules RUN /home/$USERNAME/udev_rules/install_udev_rules.sh # Generate robot configuration files. RUN bash -ie /home/$USERNAME/script/husky-generate.sh + +ENTRYPOINT [] +CMD ["/bin/bash"] diff --git a/kobuki_ws/docker/Dockerfile b/kobuki_ws/docker/Dockerfile index feb91c20..d1fce625 100644 --- a/kobuki_ws/docker/Dockerfile +++ b/kobuki_ws/docker/Dockerfile @@ -1,63 +1,94 @@ -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble -FROM arm64v8/ros:humble AS arm64 # Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble FROM osrf/ros:humble-desktop-full AS amd64 +# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +FROM arm64v8/ros:humble AS arm64 # Use docker automatic platform args to select the base image. # It may be `arm64` or `amd64` depending on the platform. -# Reference: -# - https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope +# Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH LABEL org.opencontainers.image.authors="yuzhong1214@gmail.com" -ARG TARGETARCH +# Arguments for the default user ARG USERNAME=user 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 \ - # - # [Optional] Add sudo support. Omit if you don't need to install software after connecting. - && apt-get update \ - && apt-get install -y sudo \ - && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ - && chmod 0440 /etc/sudoers.d/$USERNAME \ - && rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get upgrade -y \ - && rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get install -y python3-pip \ + +# Keep downloaded packages for caching purposes +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache + +# Upgrade packages +# Ref: https://pythonspeed.com/articles/security-updates-in-docker/ +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1264502398 +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1987107404 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get upgrade -y \ && rm -rf /var/lib/apt/lists/* -ENV SHELL /bin/bash -# ******************************************************** -# * Anything else you want to do like clean up goes here * -# ******************************************************** +# Install sudo and create a user with sudo privileges +# Ref: https://stackoverflow.com/a/65434659 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y sudo \ + && useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ + && rm -rf /var/lib/apt/lists/* # Install common tools -RUN apt-get update && apt-get install -y \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ curl \ git \ - git-extras \ htop \ + iputils-ping \ + nano \ net-tools \ tmux \ + tree \ + unzip \ vim \ wget \ + zip \ && rm -rf /var/lib/apt/lists/* -# Install ROS2 RVIZ and Gazebo -RUN if [ "$TARGETARCH" = "amd64" ]; then \ +# Install Python pip +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Install custom tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + git-extras \ + && rm -rf /var/lib/apt/lists/* + +# Install ROS2 Gazebo packages for amd64 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + if [ "$TARGETARCH" = "amd64" ]; then \ apt-get update && apt-get install -y \ ros-$ROS_DISTRO-gazebo-ros-pkgs \ ros-$ROS_DISTRO-gazebo-ros2-control \ && rm -rf /var/lib/apt/lists/*; \ - elif [ "$TARGETARCH" = "arm64" ]; then \ + fi + +# Install ROS2 RVIZ and other custom ROS2 packages +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-rviz2 \ + && rm -rf /var/lib/apt/lists/* + +# TODO: Add more commands here +# For example, to install additional packages, uncomment the following lines and add the package names +# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ +# apt-get update && apt-get install -y \ +# $OTHER_PACKAGES \ +# && rm -rf /var/lib/apt/lists/* + +RUN if [ "$TARGETARCH" = "arm64" ]; then \ # Fix the issue of Eigen - # Reference: - # - https://gitlab.com/libeigen/eigen/-/issues/2326 + # Reference: https://gitlab.com/libeigen/eigen/-/issues/2326 sed -i 's/EIGEN_ALWAYS_INLINE eigen_packet_wrapper() {}/EIGEN_ALWAYS_INLINE eigen_packet_wrapper() = default;/' /usr/include/eigen3/Eigen/src/Core/GenericPacketMath.h; \ fi @@ -65,7 +96,8 @@ RUN if [ "$TARGETARCH" = "amd64" ]; then \ # The list of packages below was identified by executing the following command: # sudo rosdep install --from-paths src --ignore-src -y # Install these packages to avoid having to run `rosdep install` every time you build the workspace. -RUN apt-get update && apt-get install -y \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ ros-$ROS_DISTRO-rviz2 \ ros-$ROS_DISTRO-ros-testing \ ros-$ROS_DISTRO-kobuki-velocity-smoother \ @@ -81,7 +113,6 @@ RUN apt-get update && apt-get install -y \ ros-$ROS_DISTRO-imu-tools \ ros-$ROS_DISTRO-pointcloud-to-laserscan \ ros-$ROS_DISTRO-teleop-twist-keyboard \ - # # Install navigation dependencies # Reference: # - https://docs.nav2.org/development_guides/build_docs/index.html @@ -92,18 +123,22 @@ RUN apt-get update && apt-get install -y \ ros-$ROS_DISTRO-robot-localization \ && rm -rf /var/lib/apt/lists/* -COPY .bashrc /home/$USERNAME/.bashrc - -# [Optional] Set the default user. Omit if you want to keep the default as root. USER $USERNAME -CMD ["/bin/bash"] +# Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount +RUN mkdir /home/$USERNAME/.gazebo +# TODO: Run additional commands as non-root user here +COPY .bashrc /home/$USERNAME/.bashrc +# TODO: Copy additional files here # Setup udev rules for Kobuki. COPY udev_rules /home/$USERNAME/udev_rules RUN /home/$USERNAME/udev_rules/install_udev_rules.sh # Build the kobuki driver workspace -COPY --chown=$USER_UID:$USER_GID kobuki_driver_ws /home/$USERNAME/kobuki_driver_ws +COPY --chown=$USER_UID kobuki_driver_ws /home/$USERNAME/kobuki_driver_ws RUN cd /home/$USERNAME/kobuki_driver_ws \ && rm -rf COLCON_IGNORE \ - && /bin/bash -c "source /opt/ros/$ROS_DISTRO/setup.bash; colcon build --symlink-install" \ No newline at end of file + && /bin/bash -c "source /opt/ros/$ROS_DISTRO/setup.bash; colcon build --symlink-install" + +ENTRYPOINT [] +CMD ["/bin/bash"] diff --git a/orbslam3_ws/docker/Dockerfile b/orbslam3_ws/docker/Dockerfile index 7d26637a..a13ea09b 100644 --- a/orbslam3_ws/docker/Dockerfile +++ b/orbslam3_ws/docker/Dockerfile @@ -1,112 +1,160 @@ -FROM osrf/ros:humble-desktop-full +# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +FROM osrf/ros:humble-desktop-full AS amd64 +# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +FROM arm64v8/ros:humble AS arm64 + +# Use docker automatic platform args to select the base image. +# It may be `arm64` or `amd64` depending on the platform. +# Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope +FROM $TARGETARCH LABEL org.opencontainers.image.authors="assume0701@gmail.com" -LABEL description = \ - "A image for ROS2 humble and ORB-SLAM3 develop environment." +# Arguments for the default user ARG USERNAME=user +ARG USER_UID=1000 + +# Keep downloaded packages for caching purposes +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache + +# Upgrade packages +# Ref: https://pythonspeed.com/articles/security-updates-in-docker/ +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1264502398 +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1987107404 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +# Install sudo and create a user with sudo privileges +# Ref: https://stackoverflow.com/a/65434659 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y sudo \ + && useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ + && rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get upgrade -y \ +# Install common tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + curl \ + git \ + htop \ + iputils-ping \ + nano \ + net-tools \ + tmux \ + tree \ + unzip \ + vim \ + wget \ + zip \ && rm -rf /var/lib/apt/lists/* -############################################# -# --- Basic setup --- -RUN apt-get update && \ - apt-get install -y \ - # Basic tools - vim \ - curl \ - tree \ - wget \ - tmux \ - # ORB-SLAM dependencies - libopencv-dev \ - opencv-data \ - libglew-dev \ - ffmpeg \ - libboost-system-dev \ - libeigen3-dev \ - # ROS dependencies - ros-$ROS_DISTRO-vision-opencv \ - ros-$ROS_DISTRO-message-filters \ - # Python related - python3-pip && \ - rm -rf /var/lib/apt/lists/* - -# add user with default bash -RUN adduser --disabled-password --gecos '' --shell /bin/bash ${USERNAME} && \ - adduser ${USERNAME} sudo && \ - echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers - -############################################# -# --- Build Pangolin from source --- -USER ${USERNAME} -WORKDIR /home/${USERNAME} - -# get pangolin sources, certain commit : https://github.com/stevenlovegrove/Pangolin/tree/d484494645cb7361374ac0ef6b27e9ee6feffbd7 +# Install Python pip +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Install custom tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + git-extras \ + && rm -rf /var/lib/apt/lists/* + +# Install ROS2 Gazebo packages for amd64 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + if [ "$TARGETARCH" = "amd64" ]; then \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-gazebo-ros-pkgs \ + ros-$ROS_DISTRO-gazebo-ros2-control \ + && rm -rf /var/lib/apt/lists/*; \ + fi + +# Install ROS2 RVIZ and other custom ROS2 packages +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-rviz2 \ + && rm -rf /var/lib/apt/lists/* + +# TODO: Add more commands here +# For example, to install additional packages, uncomment the following lines and add the package names +# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ +# apt-get update && apt-get install -y \ +# $OTHER_PACKAGES \ +# && rm -rf /var/lib/apt/lists/* +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + # ORB-SLAM dependencies + libopencv-dev \ + opencv-data \ + libglew-dev \ + ffmpeg \ + libboost-system-dev \ + libeigen3-dev \ + # ROS dependencies + ros-$ROS_DISTRO-vision-opencv \ + ros-$ROS_DISTRO-message-filters \ + && rm -rf /var/lib/apt/lists/* + +USER $USERNAME +# Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount +RUN mkdir /home/$USERNAME/.gazebo +# TODO: Run additional commands as non-root user here + +# Build Pangolin from source at commit: https://github.com/stevenlovegrove/Pangolin/tree/d484494645cb7361374ac0ef6b27e9ee6feffbd7 +# TODO(@j3soon): Simplify the git commands here RUN mkdir -p /home/${USERNAME}/Pangolin/build && \ cd /home/${USERNAME}/Pangolin && \ git init && \ git remote add origin https://github.com/stevenlovegrove/Pangolin.git && \ git pull origin d484494645cb7361374ac0ef6b27e9ee6feffbd7 && \ git rm -r --cached . - -WORKDIR /home/${USERNAME}/Pangolin/build - -# build pangolin -RUN cmake .. && \ +RUN cd /home/${USERNAME}/Pangolin/build && \ + cmake .. && \ cmake --build . -############################################# -# --- Build ORB-SLAM3 from source -WORKDIR /home/${USERNAME} - +# Build ORB-SLAM3 from source at commit: https://github.com/UZ-SLAMLab/ORB_SLAM3/commit/4452a3c4ab75b1cde34e5505a36ec3f9edcdc4c4 +# TODO(@j3soon): Simplify the git commands here RUN mkdir -p /home/${USERNAME}/ORB_SLAM3 && \ cd /home/${USERNAME}/ORB_SLAM3 && \ git init && \ git remote add origin https://github.com/UZ-SLAMLab/ORB_SLAM3.git && \ git pull origin 4452a3c4ab75b1cde34e5505a36ec3f9edcdc4c4 && \ git rm -r --cached . - -# Change to c++14 for compile error +# Change to c++14 for resolving compile error # Ref : https://github.com/UZ-SLAMLab/ORB_SLAM3/issues/387 # Ref : https://github.com/Soldann/MORB_SLAM/issues/3 -RUN sed -i 's/++11/++14/g' ORB_SLAM3/CMakeLists.txt && \ - sed -i 's/++11/++14/g' ORB_SLAM3/Thirdparty/g2o/CMakeLists.txt && \ - sed -i 's/++11/++14/g' ORB_SLAM3/Thirdparty/Sophus/CMakeLists.txt - -RUN cd ORB_SLAM3 && \ +RUN sed -i 's/++11/++14/g' /home/${USERNAME}/ORB_SLAM3/CMakeLists.txt && \ + sed -i 's/++11/++14/g' /home/${USERNAME}/ORB_SLAM3/Thirdparty/g2o/CMakeLists.txt && \ + sed -i 's/++11/++14/g' /home/${USERNAME}/ORB_SLAM3/Thirdparty/Sophus/CMakeLists.txt +RUN cd /home/${USERNAME}/ORB_SLAM3 && \ ./build.sh - -RUN cd ORB_SLAM3/Thirdparty/Sophus/build && \ +RUN cd /home/${USERNAME}/ORB_SLAM3/Thirdparty/Sophus/build && \ sudo make install -############################################# -# --- Build ROS2-SLAM3 +# Build ORB-SLAM3 for ROS2 RUN mkdir -p /home/${USERNAME}/test_ws/src - WORKDIR /home/${USERNAME}/test_ws - RUN colcon build - RUN mkdir -p src/orbslam3_ros2 && \ cd src/orbslam3_ros2 && \ git init && \ git remote add origin https://github.com/zang09/ORB_SLAM3_ROS2.git && \ git pull origin 00c54335ccc010d74c1e24e336aa817604124947 && \ git rm -r --cached . - # Fix path error and colcon build error # Ref : https://github.com/alsora/ros2-ORB_SLAM2/issues/8#issuecomment-1461570970 RUN sed -i 's/foxy\/lib\/python3.8/humble\/lib\/python3.10/g' src/orbslam3_ros2/CMakeLists.txt && \ sed -i 's/Pangolin)/Pangolin OpenCV)/g' src/orbslam3_ros2/CMakeLists.txt && \ sed -i 's/Install\/ORB_SLAM\/ORB_SLAM3/ORB_SLAM3/g' src/orbslam3_ros2/CMakeModules/FindORB_SLAM3.cmake - RUN rosdep update && \ . /opt/ros/humble/setup.sh && \ colcon build --symlink-install --packages-select orbslam3 -# Create work directory and went in -WORKDIR /home/${USERNAME}/ros_ws - -CMD ["bash"] +COPY .bashrc /home/$USERNAME/.bashrc +# TODO: Copy additional files here +ENTRYPOINT [] +CMD ["/bin/bash"] diff --git a/rtabmap_ws/docker/Dockerfile b/rtabmap_ws/docker/Dockerfile index da6ed2bb..bee05d01 100644 --- a/rtabmap_ws/docker/Dockerfile +++ b/rtabmap_ws/docker/Dockerfile @@ -1,46 +1,104 @@ -FROM introlab3it/rtabmap:jammy +# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +FROM introlab3it/rtabmap:jammy AS amd64 +# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +FROM introlab3it/rtabmap:jammy AS arm64 + +# Use docker automatic platform args to select the base image. +# It may be `arm64` or `amd64` depending on the platform. +# Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope +FROM $TARGETARCH LABEL org.opencontainers.image.authors="assume0701@gmail.com" -LABEL description = \ - "A image for ROS2 humble and RTAB-Map develop environment." +# Arguments for the default user ARG USERNAME=user +ARG USER_UID=1000 + +# Keep downloaded packages for caching purposes +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache -RUN apt-get update && apt-get upgrade -y \ +# Upgrade packages +# Ref: https://pythonspeed.com/articles/security-updates-in-docker/ +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1264502398 +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1987107404 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get upgrade -y \ && rm -rf /var/lib/apt/lists/* -############################################# -# --- Basic setup --- -RUN apt-get update && \ - apt-get install -y \ - sudo \ - vim \ - curl \ - tree \ - tmux \ - # --- - # Simulation required packages - ros-humble-turtlebot3 \ - ros-humble-turtlebot3-gazebo \ - ros-humble-gazebo-ros-pkgs \ - ros-humble-joint-state-publisher-gui \ - ros-humble-rqt-robot-steering \ - # --- - # RTAB-MAP required packages - ros-humble-rtabmap-ros && \ - rm -rf /var/lib/apt/lists/* - -# Install Gazebo -RUN curl -sSL http://get.gazebosim.org | sh - -# add user with default bash -RUN adduser --disabled-password --gecos '' --shell /bin/bash ${USERNAME} && \ - adduser ${USERNAME} sudo && \ - echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers +# Install sudo and create a user with sudo privileges +# Ref: https://stackoverflow.com/a/65434659 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y sudo \ + && useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ + && rm -rf /var/lib/apt/lists/* -COPY .bashrc /home/$USERNAME/.bashrc +# Install common tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + curl \ + git \ + htop \ + iputils-ping \ + nano \ + net-tools \ + tmux \ + tree \ + unzip \ + vim \ + wget \ + zip \ + && rm -rf /var/lib/apt/lists/* + +# Install Python pip +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* -# Login with user -USER ${USERNAME} +# Install custom tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + git-extras \ + && rm -rf /var/lib/apt/lists/* + +# Install ROS2 Gazebo packages for amd64 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + if [ "$TARGETARCH" = "amd64" ]; then \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-gazebo-ros-pkgs \ + ros-$ROS_DISTRO-gazebo-ros2-control \ + && rm -rf /var/lib/apt/lists/*; \ + fi + +# Install ROS2 RVIZ and other custom ROS2 packages +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-rviz2 \ + && rm -rf /var/lib/apt/lists/* -CMD ["bash"] \ No newline at end of file +# TODO: Add more commands here +# For example, to install additional packages, uncomment the following lines and add the package names +# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ +# apt-get update && apt-get install -y \ +# $OTHER_PACKAGES \ +# && rm -rf /var/lib/apt/lists/* +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-turtlebot3 \ + ros-$ROS_DISTRO-turtlebot3-gazebo \ + ros-$ROS_DISTRO-joint-state-publisher-gui \ + ros-$ROS_DISTRO-rqt-robot-steering \ + ros-$ROS_DISTRO-rtabmap-ros \ + && rm -rf /var/lib/apt/lists/* + +USER $USERNAME +# Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount +RUN mkdir /home/$USERNAME/.gazebo +# TODO: Run additional commands as non-root user here +COPY .bashrc /home/$USERNAME/.bashrc +# TODO: Copy additional files here +ENTRYPOINT [] +CMD ["/bin/bash"] diff --git a/template_ws/docker/Dockerfile b/template_ws/docker/Dockerfile index 690db6fa..eaa3d3d2 100644 --- a/template_ws/docker/Dockerfile +++ b/template_ws/docker/Dockerfile @@ -85,8 +85,10 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ # && rm -rf /var/lib/apt/lists/* USER $USERNAME -COPY .bashrc /home/$USERNAME/.bashrc # Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount RUN mkdir /home/$USERNAME/.gazebo +# TODO: Run additional commands as non-root user here +COPY .bashrc /home/$USERNAME/.bashrc +# TODO: Copy additional files here ENTRYPOINT [] CMD ["/bin/bash"] diff --git a/tests/diff_base/docker/Dockerfile b/tests/diff_base/docker/Dockerfile index 690db6fa..3262cc4f 100644 --- a/tests/diff_base/docker/Dockerfile +++ b/tests/diff_base/docker/Dockerfile @@ -1,13 +1,13 @@ # Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble -FROM osrf/ros:humble-desktop-full AS amd64 +FROM PLACEHOLDER AS amd64 # Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble -FROM arm64v8/ros:humble AS arm64 +FROM PLACEHOLDER AS arm64 # Use docker automatic platform args to select the base image. # It may be `arm64` or `amd64` depending on the platform. # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH - +MULTILINE_PLACEHOLDER # Arguments for the default user ARG USERNAME=user ARG USER_UID=1000 @@ -83,10 +83,14 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ # apt-get update && apt-get install -y \ # $OTHER_PACKAGES \ # && rm -rf /var/lib/apt/lists/* - +MULTILINE_PLACEHOLDER USER $USERNAME -COPY .bashrc /home/$USERNAME/.bashrc # Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount RUN mkdir /home/$USERNAME/.gazebo +# TODO: Run additional commands as non-root user here +MULTILINE_PLACEHOLDER +COPY .bashrc /home/$USERNAME/.bashrc +# TODO: Copy additional files here +MULTILINE_PLACEHOLDER ENTRYPOINT [] CMD ["/bin/bash"] diff --git a/tests/lint_comp_template.py b/tests/lint_comp_template.py index 3375ca30..6af81c02 100644 --- a/tests/lint_comp_template.py +++ b/tests/lint_comp_template.py @@ -9,17 +9,18 @@ current_dir = os.path.dirname(os.path.realpath(__file__)) repo_dir = os.path.realpath(f"{current_dir}/..") -def compare_file_with_template(filepath, ignored_workspaces=[]): - logging.info(f"Checking if '{filepath}' matches the template...") +def compare_file_with_template(filepath, targetpath=None, ignored_workspaces=[]): + targetpath = targetpath or filepath + logging.info(f"Checking if '{targetpath}' matches the template...") template_path = f"{repo_dir}/tests/diff_base/{filepath}" template = Path(template_path).read_text().splitlines(keepends=True) # keepends to preserve trailing newlines - for filename in glob.glob(f"{repo_dir}/*_ws/{filepath}"): + for filename in glob.glob(f"{repo_dir}/*_ws/{targetpath}"): # Skip certain cases intentionally if any(ws in filename for ws in ignored_workspaces): continue logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") content = Path(filename).read_text().splitlines(keepends=True) - diff = list(filter(lambda x: x.startswith('- ') or x.startswith('+ '), difflib.ndiff(template, content))) + diff = list(filter(lambda x: x.startswith('- ') or x.startswith('+ ') or x.startswith(' '), difflib.ndiff(template, content))) def error(msg, i): diff.insert(i+2, "! <<< Parsing failed before reaching here >>>\n") logging.info('\n' + ''.join(diff)) @@ -32,6 +33,9 @@ def error(msg, i): while i < len(diff) and diff[i].startswith('+ '): i += 1 continue + if diff[i].startswith(' '): + i += 1 + continue if i+1 >= len(diff): error("Odd lines", i) # Stack and compare @@ -42,7 +46,7 @@ def error(msg, i): stack.append(j) j += 1 k = 0 - while k < len(stack) and diff[j+k].startswith('+ '): + while k < len(stack) and j+k < len(diff) and diff[j+k].startswith('+ '): if "- MULTILINE_PLACEHOLDER" in diff[i+k]: raise error("MULTILINE_PLACEHOLDER is not supported in this case yet", i) regexp = "^" + re.escape(diff[i+k][2:]).replace('PLACEHOLDER', '.*') + "$" @@ -58,7 +62,7 @@ def error(msg, i): stack.append(j) j += 1 k = 0 - while k < len(stack) and diff[j+k].startswith('- '): + while k < len(stack) and j+k < len(diff) and diff[j+k].startswith('- '): if "- MULTILINE_PLACEHOLDER" in diff[j+k]: raise error("MULTILINE_PLACEHOLDER is not supported in this case yet", i) regexp = "^" + re.escape(diff[j+k][2:]).replace('PLACEHOLDER', '.*') + "$" @@ -76,3 +80,4 @@ def error(msg, i): compare_file_with_template("docker/.bashrc") compare_file_with_template("docker/.dockerignore", ignored_workspaces=["ros1_bridge_ws", "orbslam3_ws"]) compare_file_with_template("docker/compose.yaml", ignored_workspaces=["ros1_bridge_ws"]) +compare_file_with_template("docker/Dockerfile", ignored_workspaces=["ros1_bridge_ws"]) diff --git a/tests/lint_dockerfile.py b/tests/lint_dockerfile.py new file mode 100644 index 00000000..e5853701 --- /dev/null +++ b/tests/lint_dockerfile.py @@ -0,0 +1,28 @@ +import glob +import logging +import os +from pathlib import Path + +logging.basicConfig(level=logging.INFO) +current_dir = os.path.dirname(os.path.realpath(__file__)) +repo_dir = os.path.realpath(f"{current_dir}/..") + +logging.info("Checking `Dockerfile` files...") +for filename in glob.glob(f"{repo_dir}/*_ws/docker/Dockerfile*"): + logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") + # Skip certain cases intentionally + if "ros1_bridge_ws" in filename: + continue + content = Path(filename).read_text() + if "ros-humble-" in content: + raise ValueError(f"`ros-humble-*` should not exist, use `ros-$ROS_DISTRO-*` instead: '{filename}'") + if "$USER_GID" in content: + raise ValueError(f"`$USER_GID` should not exist since it's unnecessary: '{filename}'") + if "RUN apt-get update" in content: + raise ValueError(f"`RUN apt-get update` should not exist, use cache mounts instead: '{filename}'") + if "RUN sudo apt-get update" in content: + raise ValueError(f"`RUN sudo apt-get update` should not exist, use cache mounts instead: '{filename}'") + if "RUN apt-get install" in content: + raise ValueError(f"`RUN apt-get install` should not exist, use with `apt-get update` instead: '{filename}'") + if " apt-get install" in content: + raise ValueError(f"` apt-get install` should not exist, use with `apt-get update` in the same line instead: '{filename}'") diff --git a/vlp_ws/docker/Dockerfile b/vlp_ws/docker/Dockerfile index 95721625..202e6dc8 100644 --- a/vlp_ws/docker/Dockerfile +++ b/vlp_ws/docker/Dockerfile @@ -1,62 +1,113 @@ -# Base Image: https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble -FROM arm64v8/ros:humble AS arm64 -# Base Image: https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble FROM osrf/ros:humble-desktop-full AS amd64 +# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +FROM arm64v8/ros:humble AS arm64 # Use docker automatic platform args to select the base image. # It may be `arm64` or `amd64` depending on the platform. -# Reference: -# - https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope +# Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH LABEL org.opencontainers.image.authors="assume0701@gmail.com" -LABEL description = \ - "An image for ROS2 VLP LiDAR." -ARG TARGETARCH +# Arguments for the default user ARG USERNAME=user ARG USER_UID=1000 -ARG USER_GID=$USER_UID -############################################# -# --- Basic setup --- +# Keep downloaded packages for caching purposes +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache -# Install necessary packages, Note: formation ref: template_ws -RUN apt-get update && apt-get install -y \ - sudo \ - vim \ +# Upgrade packages +# Ref: https://pythonspeed.com/articles/security-updates-in-docker/ +# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1264502398 +# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1987107404 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +# Install sudo and create a user with sudo privileges +# Ref: https://stackoverflow.com/a/65434659 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y sudo \ + && useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ + && rm -rf /var/lib/apt/lists/* + +# Install common tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ curl \ - tree \ + git \ + htop \ + iputils-ping \ + nano \ + net-tools \ tmux \ + tree \ + unzip \ + vim \ + wget \ + zip \ + && rm -rf /var/lib/apt/lists/* + +# Install Python pip +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + python3-pip \ && rm -rf /var/lib/apt/lists/* +# Install custom tools +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + git-extras \ + && rm -rf /var/lib/apt/lists/* + +# Install ROS2 Gazebo packages for amd64 +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + if [ "$TARGETARCH" = "amd64" ]; then \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-gazebo-ros-pkgs \ + ros-$ROS_DISTRO-gazebo-ros2-control \ + && rm -rf /var/lib/apt/lists/*; \ + fi + +# Install ROS2 RVIZ and other custom ROS2 packages +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-rviz2 \ + && rm -rf /var/lib/apt/lists/* + +# TODO: Add more commands here +# For example, to install additional packages, uncomment the following lines and add the package names +# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ +# apt-get update && apt-get install -y \ +# $OTHER_PACKAGES \ +# && rm -rf /var/lib/apt/lists/* # Install ROS2 and Gazebo simulation packages when using `amd64` platform -RUN if [ "$TARGETARCH" = "amd64" ]; then \ - apt update && apt install -y \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + if [ "$TARGETARCH" = "amd64" ]; then \ + apt-get update && apt-get install -y \ ros-$ROS_DISTRO-turtlebot3-gazebo \ - ros-$ROS_DISTRO-gazebo-ros-pkgs \ ros-$ROS_DISTRO-joint-state-publisher-gui \ ros-$ROS_DISTRO-rqt-robot-steering \ && rm -rf /var/lib/apt/lists/*; \ - curl -sSL http://get.gazebosim.org | sh; \ fi # Install ROS2 velodyne package -RUN apt-get update && \ - apt-get install -y \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + apt-get update && apt-get install -y \ ros-$ROS_DISTRO-turtlebot3 \ ros-$ROS_DISTRO-diagnostic-updater \ ros-$ROS_DISTRO-velodyne && \ rm -rf /var/lib/apt/lists/* -# # add user with default bash -RUN adduser --disabled-password --gecos '' --shell /bin/bash ${USERNAME} && \ - adduser ${USERNAME} sudo && \ - echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers - -COPY .bashrc /home/${USERNAME}/.bashrc - -# Login with user -USER ${USERNAME} - -CMD ["bash"] \ No newline at end of file +USER $USERNAME +# Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount +RUN mkdir /home/$USERNAME/.gazebo +# TODO: Run additional commands as non-root user here +COPY .bashrc /home/$USERNAME/.bashrc +# TODO: Copy additional files here +ENTRYPOINT [] +CMD ["/bin/bash"] From e9c2a97ae05bbf9c7011f4199c10af3f373dcd78 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 13:58:13 +0800 Subject: [PATCH 15/24] docs: Replace all old names from `ros2-agv-essentials` to `ros2-essentials` and add tests --- cartographer_ws/README.md | 6 +++--- husky_ws/README.md | 4 ++-- husky_ws/src/citysim/README.md | 2 +- kobuki_ws/README.md | 12 ++++++------ orbslam3_ws/README.md | 4 ++-- rtabmap_ws/README.md | 4 ++-- tests/lint_readme.py | 15 +++++++++++++++ vlp_ws/README.md | 4 ++-- 8 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 tests/lint_readme.py diff --git a/cartographer_ws/README.md b/cartographer_ws/README.md index 254d1e18..a1c87a8f 100644 --- a/cartographer_ws/README.md +++ b/cartographer_ws/README.md @@ -7,7 +7,7 @@ git clone https://github.com/j3soon/ros2-essentials.git ``` ```bash -cd ros2-agv-essentials/cartographer_ws/docker +cd ros2-essentials/cartographer_ws/docker docker compose pull docker compose up -d --build ``` @@ -18,7 +18,7 @@ docker compose up -d --build ```sh docker attach ros2-cartographer-ws - cd /home/ros2-agv-essentials/cartographer_ws + cd /home/ros2-essentials/cartographer_ws ``` - Open the turtlebot simulation in `tmux` @@ -41,7 +41,7 @@ docker compose up -d --build ```sh docker attach ros2-cartographer-ws -cd /home/ros2-agv-essentials/cartographer_ws +cd /home/ros2-essentials/cartographer_ws rosdep update rosdep install --from-paths src --ignore-src --rosdistro humble -y colcon build diff --git a/husky_ws/README.md b/husky_ws/README.md index 987d0db7..b90e9424 100644 --- a/husky_ws/README.md +++ b/husky_ws/README.md @@ -55,7 +55,7 @@ Before attempting any examples, please remember to build the packages first. If you encounter any dependency errors, please use rosdep to resolve them. ```bash -cd /home/ros2-agv-essentials/husky_ws +cd /home/ros2-essentials/husky_ws rosdep update rosdep install --from-paths src --ignore-src --rosdistro humble -y colcon build @@ -97,7 +97,7 @@ ros2 launch husky_navigation slam_launch.py ```bash= # Move to the workspace, source .bashrc, and bringup husky. -cd /home/ros2-agv-essentials/husky_ws +cd /home/ros2-essentials/husky_ws source ~/.bashrc ./script/husky-bringup.sh diff --git a/husky_ws/src/citysim/README.md b/husky_ws/src/citysim/README.md index d05d662f..8f76e68c 100644 --- a/husky_ws/src/citysim/README.md +++ b/husky_ws/src/citysim/README.md @@ -11,7 +11,7 @@ Please ensure that you have set up the `GAZEBO_MODEL_PATH` correctly. ```bash cd $ROS2_WS/src/citysim -export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/home/ros2-agv-essentials/husky_ws/src/citysim/models +export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/home/ros2-essentials/husky_ws/src/citysim/models gazebo worlds/simple_city.world ``` diff --git a/kobuki_ws/README.md b/kobuki_ws/README.md index 3a0fa567..8d4b6d4d 100644 --- a/kobuki_ws/README.md +++ b/kobuki_ws/README.md @@ -25,7 +25,7 @@ This repository is primarily based on the [kobuki-base](https://github.com/kobuk > If you only need to bring up the real Kobuki robot, you don't need to compile the workspace. The Kobuki driver is already included in the Docker image. After the Docker image is built, you can directly bring up the robot. ```bash -cd /home/ros2-agv-essentials/kobuki_ws +cd /home/ros2-essentials/kobuki_ws # For x86_64 architecture colcon build --symlink-install @@ -69,12 +69,12 @@ ros2 launch kobuki_launch kobuki.launch.py is_sim:=true ```bash # Inside the container -cd /home/ros2-agv-essentials/kobuki_ws +cd /home/ros2-essentials/kobuki_ws ./script/kobuki-bringup.sh # or Outside the container cd /path/to/kobuki_ws/docker -docker compose run kobuki-ws /home/ros2-agv-essentials/kobuki_ws/script/kobuki-bringup.sh +docker compose run kobuki-ws /home/ros2-essentials/kobuki_ws/script/kobuki-bringup.sh ``` If you have successfully connected to the Kobuki, you should hear a sound from it. Otherwise, there may be errors. You can try re-plugging the USB cable, restarting the Kobuki, or even restarting the container. @@ -101,12 +101,12 @@ To control the Kobuki with a keyboard, you can use the `teleop_twist_keyboard` p # - Angular 0.3 # Inside the container -cd /home/ros2-agv-essentials/kobuki_ws +cd /home/ros2-essentials/kobuki_ws ./script/kobuki-teleop.sh # or Outside the container cd /path/to/kobuki_ws/docker -docker compose run kobuki-ws /home/ros2-agv-essentials/kobuki_ws/script/kobuki-teleop.sh +docker compose run kobuki-ws /home/ros2-essentials/kobuki_ws/script/kobuki-teleop.sh ``` ### Launch the demo of SLAM @@ -152,7 +152,7 @@ Note that the arm64 architecture is emulated by the QEMU, so it may consume a lo When the building process ends, use `docker compose up -d` and attach to the container by running `docker attach ros2-kobuki-ws`. After that, we can start building the ROS packages. If you have built the packages for the x86_64 architecture before, remember to delete the `build`, `install`, and `log` folders. ```bash -cd /home/ros2-agv-essentials/kobuki_ws +cd /home/ros2-essentials/kobuki_ws colcon build --symlink-install --packages-ignore velodyne_gazebo_plugins ``` diff --git a/orbslam3_ws/README.md b/orbslam3_ws/README.md index 8b50150f..448ba90f 100644 --- a/orbslam3_ws/README.md +++ b/orbslam3_ws/README.md @@ -7,7 +7,7 @@ git clone https://github.com/j3soon/ros2-essentials.git ``` ```bash -cd ros2-agv-essentials/orbslam3_ws/docker +cd ros2-essentials/orbslam3_ws/docker docker compose pull docker compose up -d --build ``` @@ -17,7 +17,7 @@ docker compose up -d --build - Attach to the container ```sh docker attach ros2-orbslam3-ws - cd /home/ros2-agv-essentials/orbslam3_ws + cd /home/ros2-essentials/orbslam3_ws ``` - Prepare data, only need to be done once - Download dataset (~1.2G) diff --git a/rtabmap_ws/README.md b/rtabmap_ws/README.md index 3f4931bc..222110b9 100644 --- a/rtabmap_ws/README.md +++ b/rtabmap_ws/README.md @@ -7,7 +7,7 @@ git clone https://github.com/j3soon/ros2-essentials.git ``` ```bash -cd ros2-agv-essentials/rtabmap_ws/docker +cd ros2-essentials/rtabmap_ws/docker docker compose pull docker compose up -d --build ``` @@ -15,7 +15,7 @@ docker compose up -d --build - Attach to the container ```sh docker attach ros2-rtabmap-ws - cd /home/ros2-agv-essentials/rtabmap_ws + cd /home/ros2-essentials/rtabmap_ws colcon build --symlink-install ``` diff --git a/tests/lint_readme.py b/tests/lint_readme.py new file mode 100644 index 00000000..5a8277e3 --- /dev/null +++ b/tests/lint_readme.py @@ -0,0 +1,15 @@ +import glob +import logging +import os +from pathlib import Path + +logging.basicConfig(level=logging.INFO) +current_dir = os.path.dirname(os.path.realpath(__file__)) +repo_dir = os.path.realpath(f"{current_dir}/..") + +logging.info("Checking `README.md` files...") +for filename in glob.glob(f"{repo_dir}/*_ws/README.md"): + logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") + content = Path(filename).read_text() + if "ros2-agv-essentials" in content: + raise ValueError(f"`ros2-agv-essentials` should not exist, use `ros2-essentials` instead: '{filename}'") diff --git a/vlp_ws/README.md b/vlp_ws/README.md index 7d6573f0..0002ad37 100644 --- a/vlp_ws/README.md +++ b/vlp_ws/README.md @@ -129,13 +129,13 @@ ros2 launch vlp_cartographer vlp_driver.launch.py - LiDAR driver ```bash - docker exec -it ros2-vlp-ws /home/ros2-agv-essentials/vlp_ws/scripts/lidar-driver-bringup.sh + docker exec -it ros2-vlp-ws /home/ros2-essentials/vlp_ws/scripts/lidar-driver-bringup.sh ``` - After launching the driver, launch the cartographer in another terminal ```bash - docker exec -it ros2-vlp-ws /home/ros2-agv-essentials/vlp_ws/scripts/lidar-slam-bringup.sh + docker exec -it ros2-vlp-ws /home/ros2-essentials/vlp_ws/scripts/lidar-slam-bringup.sh ``` --- From 8f30bd40b3422d2e88bc8bf838ccdc1ad306ebe6 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 13:59:55 +0800 Subject: [PATCH 16/24] refactor(husky_ws): Rename `ros2_ws` to `husky_driver_ws` for clarity --- husky_ws/docker/.bashrc | 2 +- husky_ws/docker/script/install-clearpath-robot.sh | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/husky_ws/docker/.bashrc b/husky_ws/docker/.bashrc index f65d6e18..1f680580 100644 --- a/husky_ws/docker/.bashrc +++ b/husky_ws/docker/.bashrc @@ -27,7 +27,7 @@ if [ ! -f $ROS2_WS/install/setup.bash ]; then fi # TODO: Source other workspace environments as underlay # Source Clearpath robot environment -source ~/ros2_ws/install/local_setup.bash +source ~/husky_driver_ws/install/local_setup.bash # Source Clearpath default environment installed by `clearpath_computer_installer.sh` source /etc/clearpath/setup.bash # Source workspace environment diff --git a/husky_ws/docker/script/install-clearpath-robot.sh b/husky_ws/docker/script/install-clearpath-robot.sh index b946ed62..a2dfef21 100755 --- a/husky_ws/docker/script/install-clearpath-robot.sh +++ b/husky_ws/docker/script/install-clearpath-robot.sh @@ -7,8 +7,8 @@ sudo bash -c 'echo "deb https://packages.clearpathrobotics.com/stable/ubuntu $(l sudo apt-get update # Create custom global workspace -mkdir -p ~/ros2_ws/src -cd ~/ros2_ws/src +mkdir -p ~/husky_driver_ws/src +cd ~/husky_driver_ws/src # `clearpath_computer_installer.sh` requires `ros-humble-clearpath-robot`. # Install from source since package doesn't exist on arm64, error message: # @@ -24,7 +24,7 @@ cd .. # Ref: https://github.com/clearpathrobotics/clearpath_robot/pull/19 # Ref: https://github.com/clearpathrobotics/clearpath_robot/pull/22 # I think this package isn't used anyway. -sed -i 's/micro_ros_agent<\/exec_depend>//' ~/ros2_ws/src/clearpath_robot/clearpath_generator_robot/package.xml +sed -i 's/micro_ros_agent<\/exec_depend>//' ~/husky_driver_ws/src/clearpath_robot/clearpath_generator_robot/package.xml # Temporarily remove `sevcon_traction` dependency # Ref: https://github.com/clearpathrobotics/clearpath_robot/commit/2ef406f30c074e578db6ea799f5c2714bce1c15d @@ -32,23 +32,23 @@ sed -i 's/micro_ros_agent<\/exec_depend>//' ~/ros2_ws/src/clearpath_robot/clearpath_generator_robot/package.xml +sed -i 's/sevcon_traction<\/exec_depend>//' ~/husky_driver_ws/src/clearpath_robot/clearpath_generator_robot/package.xml # Temporarily remove `umx_driver` dependency # This package is only used for redshift and chrobotics, so it isn't required for our case. # Ref: https://github.com/clearpathrobotics/clearpath_robot/blob/40b1c40a7d229ede7a674cb0fb359fc83c754adb/clearpath_sensors/launch/redshift_um7.launch.py#L69 # Ref: https://github.com/clearpathrobotics/clearpath_robot/blob/40b1c40a7d229ede7a674cb0fb359fc83c754adb/clearpath_sensors/launch/chrobotics_um6.launch.py#L69 -sed -i 's/umx_driver<\/exec_depend>//' ~/ros2_ws/src/clearpath_robot/clearpath_sensors/package.xml +sed -i 's/umx_driver<\/exec_depend>//' ~/husky_driver_ws/src/clearpath_robot/clearpath_sensors/package.xml # Temporarily remove `valence_bms_driver` dependency # Ref: https://github.com/clearpathrobotics/clearpath_robot/pull/47 # This type of batteries are only used in W200, so they aren't required for Husky. # Ref: https://github.com/clearpathrobotics/clearpath_robot/blob/40b1c40a7d229ede7a674cb0fb359fc83c754adb/clearpath_generator_robot/clearpath_generator_robot/launch/generator.py#L152-L156 # Ref: https://github.com/clearpathrobotics/clearpath_config/blob/996eb50d0b05c87b65b8ffddcddd33239abd422e/clearpath_config/platform/battery.py#L51-L54 -sed -i 's/valence_bms_driver<\/exec_depend>//' ~/ros2_ws/src/clearpath_robot/clearpath_generator_robot/package.xml +sed -i 's/valence_bms_driver<\/exec_depend>//' ~/husky_driver_ws/src/clearpath_robot/clearpath_generator_robot/package.xml # Continue building the workspace -cd ~/ros2_ws +cd ~/husky_driver_ws rosdep update rosdep install -i --from-path src --rosdistro humble -y colcon build From 2d3bb93808020795399066297799fed86eb646f1 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 14:30:00 +0800 Subject: [PATCH 17/24] fix: Add TARGETARCH argument to Dockerfile --- cartographer_ws/docker/Dockerfile | 1 + husky_ws/docker/Dockerfile | 1 + kobuki_ws/docker/Dockerfile | 1 + orbslam3_ws/docker/Dockerfile | 1 + rtabmap_ws/docker/Dockerfile | 1 + template_ws/docker/Dockerfile | 1 + tests/diff_base/docker/Dockerfile | 1 + vlp_ws/docker/Dockerfile | 1 + 8 files changed, 8 insertions(+) diff --git a/cartographer_ws/docker/Dockerfile b/cartographer_ws/docker/Dockerfile index 7d9347b1..36781efb 100644 --- a/cartographer_ws/docker/Dockerfile +++ b/cartographer_ws/docker/Dockerfile @@ -7,6 +7,7 @@ FROM arm64v8/ros:humble AS arm64 # It may be `arm64` or `amd64` depending on the platform. # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH +ARG TARGETARCH LABEL org.opencontainers.image.authors="assume0701@gmail.com" diff --git a/husky_ws/docker/Dockerfile b/husky_ws/docker/Dockerfile index 70f3f4da..74ea4982 100644 --- a/husky_ws/docker/Dockerfile +++ b/husky_ws/docker/Dockerfile @@ -7,6 +7,7 @@ FROM arm64v8/ros:humble AS arm64 # It may be `arm64` or `amd64` depending on the platform. # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH +ARG TARGETARCH LABEL org.opencontainers.image.authors="yuzhong1214@gmail.com" diff --git a/kobuki_ws/docker/Dockerfile b/kobuki_ws/docker/Dockerfile index d1fce625..d2a7d35a 100644 --- a/kobuki_ws/docker/Dockerfile +++ b/kobuki_ws/docker/Dockerfile @@ -7,6 +7,7 @@ FROM arm64v8/ros:humble AS arm64 # It may be `arm64` or `amd64` depending on the platform. # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH +ARG TARGETARCH LABEL org.opencontainers.image.authors="yuzhong1214@gmail.com" diff --git a/orbslam3_ws/docker/Dockerfile b/orbslam3_ws/docker/Dockerfile index a13ea09b..0c67bfe8 100644 --- a/orbslam3_ws/docker/Dockerfile +++ b/orbslam3_ws/docker/Dockerfile @@ -7,6 +7,7 @@ FROM arm64v8/ros:humble AS arm64 # It may be `arm64` or `amd64` depending on the platform. # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH +ARG TARGETARCH LABEL org.opencontainers.image.authors="assume0701@gmail.com" diff --git a/rtabmap_ws/docker/Dockerfile b/rtabmap_ws/docker/Dockerfile index bee05d01..0750e1bc 100644 --- a/rtabmap_ws/docker/Dockerfile +++ b/rtabmap_ws/docker/Dockerfile @@ -7,6 +7,7 @@ FROM introlab3it/rtabmap:jammy AS arm64 # It may be `arm64` or `amd64` depending on the platform. # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH +ARG TARGETARCH LABEL org.opencontainers.image.authors="assume0701@gmail.com" diff --git a/template_ws/docker/Dockerfile b/template_ws/docker/Dockerfile index eaa3d3d2..f9063ab2 100644 --- a/template_ws/docker/Dockerfile +++ b/template_ws/docker/Dockerfile @@ -7,6 +7,7 @@ FROM arm64v8/ros:humble AS arm64 # It may be `arm64` or `amd64` depending on the platform. # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH +ARG TARGETARCH # Arguments for the default user ARG USERNAME=user diff --git a/tests/diff_base/docker/Dockerfile b/tests/diff_base/docker/Dockerfile index 3262cc4f..faab7f71 100644 --- a/tests/diff_base/docker/Dockerfile +++ b/tests/diff_base/docker/Dockerfile @@ -7,6 +7,7 @@ FROM PLACEHOLDER AS arm64 # It may be `arm64` or `amd64` depending on the platform. # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH +ARG TARGETARCH MULTILINE_PLACEHOLDER # Arguments for the default user ARG USERNAME=user diff --git a/vlp_ws/docker/Dockerfile b/vlp_ws/docker/Dockerfile index 202e6dc8..c0a83f46 100644 --- a/vlp_ws/docker/Dockerfile +++ b/vlp_ws/docker/Dockerfile @@ -7,6 +7,7 @@ FROM arm64v8/ros:humble AS arm64 # It may be `arm64` or `amd64` depending on the platform. # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH +ARG TARGETARCH LABEL org.opencontainers.image.authors="assume0701@gmail.com" From 6715046c4ac046b8260f677043f58323867ae20d Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 15:44:38 +0800 Subject: [PATCH 18/24] fix(template_ws): Replace container name in devcontainers during workspace creation --- scripts/create_workspace.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/create_workspace.sh b/scripts/create_workspace.sh index a6c10486..941964a4 100755 --- a/scripts/create_workspace.sh +++ b/scripts/create_workspace.sh @@ -38,9 +38,10 @@ rm -rf "${NEW_WS_DIR}/README.md" echo "# ${NEW_WS_NAME_UNDERSCORE}" > "${NEW_WS_DIR}/README.md" # Replace the "template_ws" with new workspace name in each file. +sed -i 's/"name": "Template",/"name": "TODO",/g' "${NEW_WS_DIR}/.devcontainer/devcontainer.json" sed -i "s/template_ws/${NEW_WS_NAME_UNDERSCORE}/g" "${NEW_WS_DIR}/.devcontainer/devcontainer.json" sed -i "s/template-ws/${NEW_WS_NAME_HYPHEN}/g" "${NEW_WS_DIR}/.devcontainer/devcontainer.json" sed -i "s/template_ws/${NEW_WS_NAME_UNDERSCORE}/g" "${NEW_WS_DIR}/docker/compose.yaml" sed -i "s/template-ws/${NEW_WS_NAME_HYPHEN}/g" "${NEW_WS_DIR}/docker/compose.yaml" -echo "Done." \ No newline at end of file +echo "Done." From aac298f2289ac0897ce2d0b2d90102b79fb881e1 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 15:57:43 +0800 Subject: [PATCH 19/24] docs: Fix comments and linting --- cartographer_ws/docker/Dockerfile | 4 ++-- cartographer_ws/docker/compose.yaml | 2 +- husky_ws/docker/Dockerfile | 4 ++-- husky_ws/docker/compose.yaml | 2 +- kobuki_ws/docker/Dockerfile | 4 ++-- kobuki_ws/docker/compose.yaml | 2 +- orbslam3_ws/docker/Dockerfile | 4 ++-- orbslam3_ws/docker/compose.yaml | 2 +- rtabmap_ws/docker/Dockerfile | 4 ++-- rtabmap_ws/docker/compose.yaml | 2 +- template_ws/docker/Dockerfile | 4 ++-- template_ws/docker/compose.yaml | 2 +- tests/diff_base/docker/Dockerfile | 4 ++-- tests/diff_base/docker/compose.yaml | 2 +- vlp_ws/docker/Dockerfile | 4 ++-- vlp_ws/docker/compose.yaml | 2 +- 16 files changed, 24 insertions(+), 24 deletions(-) diff --git a/cartographer_ws/docker/Dockerfile b/cartographer_ws/docker/Dockerfile index 36781efb..f6e5178c 100644 --- a/cartographer_ws/docker/Dockerfile +++ b/cartographer_ws/docker/Dockerfile @@ -1,6 +1,6 @@ -# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble FROM osrf/ros:humble-desktop-full AS amd64 -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble FROM arm64v8/ros:humble AS arm64 # Use docker automatic platform args to select the base image. diff --git a/cartographer_ws/docker/compose.yaml b/cartographer_ws/docker/compose.yaml index b6338f92..f556d017 100644 --- a/cartographer_ws/docker/compose.yaml +++ b/cartographer_ws/docker/compose.yaml @@ -31,8 +31,8 @@ services: - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/cartographer_ws # TODO: Uncomment the lines below to enable GPU support. + # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: - # # Reference : https://docs.docker.com/compose/gpu-support/ # resources: # reservations: # devices: diff --git a/husky_ws/docker/Dockerfile b/husky_ws/docker/Dockerfile index 74ea4982..e15a4efb 100644 --- a/husky_ws/docker/Dockerfile +++ b/husky_ws/docker/Dockerfile @@ -1,6 +1,6 @@ -# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble FROM osrf/ros:humble-desktop-full AS amd64 -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble FROM arm64v8/ros:humble AS arm64 # Use docker automatic platform args to select the base image. diff --git a/husky_ws/docker/compose.yaml b/husky_ws/docker/compose.yaml index 6bb8a950..a8629553 100644 --- a/husky_ws/docker/compose.yaml +++ b/husky_ws/docker/compose.yaml @@ -31,8 +31,8 @@ services: - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/husky_ws # TODO: Uncomment the lines below to enable GPU support. + # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: - # # Reference : https://docs.docker.com/compose/gpu-support/ # resources: # reservations: # devices: diff --git a/kobuki_ws/docker/Dockerfile b/kobuki_ws/docker/Dockerfile index d2a7d35a..b0823e44 100644 --- a/kobuki_ws/docker/Dockerfile +++ b/kobuki_ws/docker/Dockerfile @@ -1,6 +1,6 @@ -# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble FROM osrf/ros:humble-desktop-full AS amd64 -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble FROM arm64v8/ros:humble AS arm64 # Use docker automatic platform args to select the base image. diff --git a/kobuki_ws/docker/compose.yaml b/kobuki_ws/docker/compose.yaml index c59da274..33c39ef1 100644 --- a/kobuki_ws/docker/compose.yaml +++ b/kobuki_ws/docker/compose.yaml @@ -31,8 +31,8 @@ services: - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/kobuki_ws # TODO: Uncomment the lines below to enable GPU support. + # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: - # # Reference : https://docs.docker.com/compose/gpu-support/ # resources: # reservations: # devices: diff --git a/orbslam3_ws/docker/Dockerfile b/orbslam3_ws/docker/Dockerfile index 0c67bfe8..54f8c52b 100644 --- a/orbslam3_ws/docker/Dockerfile +++ b/orbslam3_ws/docker/Dockerfile @@ -1,6 +1,6 @@ -# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble FROM osrf/ros:humble-desktop-full AS amd64 -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble FROM arm64v8/ros:humble AS arm64 # Use docker automatic platform args to select the base image. diff --git a/orbslam3_ws/docker/compose.yaml b/orbslam3_ws/docker/compose.yaml index a8b8cdc1..a6e1be26 100644 --- a/orbslam3_ws/docker/compose.yaml +++ b/orbslam3_ws/docker/compose.yaml @@ -31,8 +31,8 @@ services: - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/orbslam3_ws # TODO: Uncomment the lines below to enable GPU support. + # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: - # # Reference : https://docs.docker.com/compose/gpu-support/ # resources: # reservations: # devices: diff --git a/rtabmap_ws/docker/Dockerfile b/rtabmap_ws/docker/Dockerfile index 0750e1bc..add27ae2 100644 --- a/rtabmap_ws/docker/Dockerfile +++ b/rtabmap_ws/docker/Dockerfile @@ -1,6 +1,6 @@ -# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/introlab3it/rtabmap/tags?page=1&name=jammy FROM introlab3it/rtabmap:jammy AS amd64 -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/introlab3it/rtabmap/tags?page=1&name=jammy FROM introlab3it/rtabmap:jammy AS arm64 # Use docker automatic platform args to select the base image. diff --git a/rtabmap_ws/docker/compose.yaml b/rtabmap_ws/docker/compose.yaml index 111ac02c..b303c3bd 100644 --- a/rtabmap_ws/docker/compose.yaml +++ b/rtabmap_ws/docker/compose.yaml @@ -31,8 +31,8 @@ services: - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/rtabmap_ws # TODO: Uncomment the lines below to enable GPU support. + # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: - # # Reference : https://docs.docker.com/compose/gpu-support/ # resources: # reservations: # devices: diff --git a/template_ws/docker/Dockerfile b/template_ws/docker/Dockerfile index f9063ab2..f7173a6f 100644 --- a/template_ws/docker/Dockerfile +++ b/template_ws/docker/Dockerfile @@ -1,6 +1,6 @@ -# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble FROM osrf/ros:humble-desktop-full AS amd64 -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble FROM arm64v8/ros:humble AS arm64 # Use docker automatic platform args to select the base image. diff --git a/template_ws/docker/compose.yaml b/template_ws/docker/compose.yaml index bdc9893a..0d4c9658 100644 --- a/template_ws/docker/compose.yaml +++ b/template_ws/docker/compose.yaml @@ -31,8 +31,8 @@ services: - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/template_ws # TODO: Uncomment the lines below to enable GPU support. + # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: - # # Reference : https://docs.docker.com/compose/gpu-support/ # resources: # reservations: # devices: diff --git a/tests/diff_base/docker/Dockerfile b/tests/diff_base/docker/Dockerfile index faab7f71..3628b2c6 100644 --- a/tests/diff_base/docker/Dockerfile +++ b/tests/diff_base/docker/Dockerfile @@ -1,6 +1,6 @@ -# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +# Base Image: PLACEHOLDER FROM PLACEHOLDER AS amd64 -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +# Base Image: PLACEHOLDER FROM PLACEHOLDER AS arm64 # Use docker automatic platform args to select the base image. diff --git a/tests/diff_base/docker/compose.yaml b/tests/diff_base/docker/compose.yaml index 19e1cc6d..685df1a3 100644 --- a/tests/diff_base/docker/compose.yaml +++ b/tests/diff_base/docker/compose.yaml @@ -31,8 +31,8 @@ services: - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/PLACEHOLDER_ws # TODO: Uncomment the lines below to enable GPU support. + # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: - # # Reference : https://docs.docker.com/compose/gpu-support/ # resources: # reservations: # devices: diff --git a/vlp_ws/docker/Dockerfile b/vlp_ws/docker/Dockerfile index c0a83f46..47399e69 100644 --- a/vlp_ws/docker/Dockerfile +++ b/vlp_ws/docker/Dockerfile @@ -1,6 +1,6 @@ -# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble FROM osrf/ros:humble-desktop-full AS amd64 -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble FROM arm64v8/ros:humble AS arm64 # Use docker automatic platform args to select the base image. diff --git a/vlp_ws/docker/compose.yaml b/vlp_ws/docker/compose.yaml index 377e3ec0..5fc17ea2 100644 --- a/vlp_ws/docker/compose.yaml +++ b/vlp_ws/docker/compose.yaml @@ -31,8 +31,8 @@ services: - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/vlp_ws # TODO: Uncomment the lines below to enable GPU support. + # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: - # # Reference : https://docs.docker.com/compose/gpu-support/ # resources: # reservations: # devices: From a1e22605363516c99682594e20589d822c88adc6 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 16:06:49 +0800 Subject: [PATCH 20/24] docs: Add todo for more environment variables --- cartographer_ws/docker/compose.yaml | 2 +- husky_ws/docker/compose.yaml | 2 +- kobuki_ws/docker/compose.yaml | 2 +- orbslam3_ws/docker/compose.yaml | 2 +- rtabmap_ws/docker/compose.yaml | 2 +- template_ws/docker/compose.yaml | 2 +- tests/diff_base/docker/compose.yaml | 5 +++-- vlp_ws/docker/compose.yaml | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cartographer_ws/docker/compose.yaml b/cartographer_ws/docker/compose.yaml index f556d017..df701945 100644 --- a/cartographer_ws/docker/compose.yaml +++ b/cartographer_ws/docker/compose.yaml @@ -19,7 +19,6 @@ services: environment: # Set X11 server environment variable for existing display. - DISPLAY=$DISPLAY - # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html @@ -30,6 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/cartographer_ws + # TODO: Set more environment variables. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: diff --git a/husky_ws/docker/compose.yaml b/husky_ws/docker/compose.yaml index a8629553..a69e1a08 100644 --- a/husky_ws/docker/compose.yaml +++ b/husky_ws/docker/compose.yaml @@ -19,7 +19,6 @@ services: environment: # Set X11 server environment variable for existing display. - DISPLAY=$DISPLAY - # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html @@ -30,6 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/husky_ws + # TODO: Set more environment variables. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: diff --git a/kobuki_ws/docker/compose.yaml b/kobuki_ws/docker/compose.yaml index 33c39ef1..9d8a942a 100644 --- a/kobuki_ws/docker/compose.yaml +++ b/kobuki_ws/docker/compose.yaml @@ -19,7 +19,6 @@ services: environment: # Set X11 server environment variable for existing display. - DISPLAY=$DISPLAY - # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html @@ -30,6 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/kobuki_ws + # TODO: Set more environment variables. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: diff --git a/orbslam3_ws/docker/compose.yaml b/orbslam3_ws/docker/compose.yaml index a6e1be26..14c54e1f 100644 --- a/orbslam3_ws/docker/compose.yaml +++ b/orbslam3_ws/docker/compose.yaml @@ -19,7 +19,6 @@ services: environment: # Set X11 server environment variable for existing display. - DISPLAY=$DISPLAY - # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html @@ -30,6 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/orbslam3_ws + # TODO: Set more environment variables. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: diff --git a/rtabmap_ws/docker/compose.yaml b/rtabmap_ws/docker/compose.yaml index b303c3bd..36a209ed 100644 --- a/rtabmap_ws/docker/compose.yaml +++ b/rtabmap_ws/docker/compose.yaml @@ -19,7 +19,6 @@ services: environment: # Set X11 server environment variable for existing display. - DISPLAY=$DISPLAY - # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html @@ -30,6 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/rtabmap_ws + # TODO: Set more environment variables. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: diff --git a/template_ws/docker/compose.yaml b/template_ws/docker/compose.yaml index 0d4c9658..63a19d47 100644 --- a/template_ws/docker/compose.yaml +++ b/template_ws/docker/compose.yaml @@ -19,7 +19,6 @@ services: environment: # Set X11 server environment variable for existing display. - DISPLAY=$DISPLAY - # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html @@ -30,6 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/template_ws + # TODO: Set more environment variables. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: diff --git a/tests/diff_base/docker/compose.yaml b/tests/diff_base/docker/compose.yaml index 685df1a3..41929f83 100644 --- a/tests/diff_base/docker/compose.yaml +++ b/tests/diff_base/docker/compose.yaml @@ -12,14 +12,13 @@ services: stdin_open: true tty: true # TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices. - privileged: true + PLACEHOLDERprivileged: true command: /bin/bash network_mode: host working_dir: /home/ros2-essentials/PLACEHOLDER_ws environment: # Set X11 server environment variable for existing display. - DISPLAY=$DISPLAY - # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html @@ -30,6 +29,8 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/PLACEHOLDER_ws + # TODO: Set more environment variables. +MULTILINE_PLACEHOLDER # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: diff --git a/vlp_ws/docker/compose.yaml b/vlp_ws/docker/compose.yaml index 5fc17ea2..cb722880 100644 --- a/vlp_ws/docker/compose.yaml +++ b/vlp_ws/docker/compose.yaml @@ -19,7 +19,6 @@ services: environment: # Set X11 server environment variable for existing display. - DISPLAY=$DISPLAY - # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html @@ -30,6 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/vlp_ws + # TODO: Set more environment variables. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: From de4743aed9ea4d02972ae85d6fd1cc2c8f536a4d Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 16:19:20 +0800 Subject: [PATCH 21/24] fix: Remove placeholders that are mistakenly added to certain workspace; Rename placeholders and add comment-only placeholders --- cartographer_ws/docker/.bashrc | 1 - rtabmap_ws/docker/.bashrc | 1 - .../diff_base/.devcontainer/devcontainer.json | 6 +-- tests/diff_base/.gitignore | 2 +- tests/diff_base/docker/.bashrc | 4 +- tests/diff_base/docker/.dockerignore | 2 +- tests/diff_base/docker/Dockerfile | 16 ++++---- tests/diff_base/docker/compose.yaml | 38 +++++++++---------- tests/lint_comp_template.py | 20 ++++++---- vlp_ws/docker/.bashrc | 1 - 10 files changed, 47 insertions(+), 44 deletions(-) diff --git a/cartographer_ws/docker/.bashrc b/cartographer_ws/docker/.bashrc index f9184745..ed090d4a 100644 --- a/cartographer_ws/docker/.bashrc +++ b/cartographer_ws/docker/.bashrc @@ -26,6 +26,5 @@ if [ ! -f $ROS2_WS/install/setup.bash ]; then echo "Workspace built." fi # TODO: Source other workspace environments as underlay -MULTILINE_PLACEHOLDER # Source workspace environment source $ROS2_WS/install/setup.bash diff --git a/rtabmap_ws/docker/.bashrc b/rtabmap_ws/docker/.bashrc index f9184745..ed090d4a 100644 --- a/rtabmap_ws/docker/.bashrc +++ b/rtabmap_ws/docker/.bashrc @@ -26,6 +26,5 @@ if [ ! -f $ROS2_WS/install/setup.bash ]; then echo "Workspace built." fi # TODO: Source other workspace environments as underlay -MULTILINE_PLACEHOLDER # Source workspace environment source $ROS2_WS/install/setup.bash diff --git a/tests/diff_base/.devcontainer/devcontainer.json b/tests/diff_base/.devcontainer/devcontainer.json index bf81ac72..43c72c3e 100644 --- a/tests/diff_base/.devcontainer/devcontainer.json +++ b/tests/diff_base/.devcontainer/devcontainer.json @@ -1,10 +1,10 @@ /* Reference: https://aka.ms/devcontainer.json */ { - "name": "PLACEHOLDER", + "name": "{PLACEHOLDER}", "dockerComposeFile": "../docker/compose.yaml", - "service": "PLACEHOLDER-ws", + "service": "{PLACEHOLDER}-ws", // Workspace settings - "workspaceFolder": "/home/ros2-essentials/PLACEHOLDER_ws", + "workspaceFolder": "/home/ros2-essentials/{PLACEHOLDER}_ws", // Vscode extensions "customizations": { "vscode": { diff --git a/tests/diff_base/.gitignore b/tests/diff_base/.gitignore index 90c2d24c..071f689a 100644 --- a/tests/diff_base/.gitignore +++ b/tests/diff_base/.gitignore @@ -5,4 +5,4 @@ /build /install /log -MULTILINE_PLACEHOLDER \ No newline at end of file +{PLACEHOLDER_MULTILINE} \ No newline at end of file diff --git a/tests/diff_base/docker/.bashrc b/tests/diff_base/docker/.bashrc index 9938f36d..29f8cd2f 100644 --- a/tests/diff_base/docker/.bashrc +++ b/tests/diff_base/docker/.bashrc @@ -19,13 +19,13 @@ if [ ! -f $ROS2_WS/install/setup.bash ]; then # TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore ` to ignore x86 packages # Ref: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html if [ $(arch) == "aarch64" ]; then - colcon build --symlink-installPLACEHOLDER + colcon build --symlink-install{PLACEHOLDER} else colcon build --symlink-install fi echo "Workspace built." fi # TODO: Source other workspace environments as underlay -MULTILINE_PLACEHOLDER +{PLACEHOLDER_MULTILINE} # Source workspace environment source $ROS2_WS/install/setup.bash diff --git a/tests/diff_base/docker/.dockerignore b/tests/diff_base/docker/.dockerignore index fe415ff7..2fb484e4 100644 --- a/tests/diff_base/docker/.dockerignore +++ b/tests/diff_base/docker/.dockerignore @@ -1,3 +1,3 @@ * !.bashrc -MULTILINE_PLACEHOLDER \ No newline at end of file +{PLACEHOLDER_MULTILINE} \ No newline at end of file diff --git a/tests/diff_base/docker/Dockerfile b/tests/diff_base/docker/Dockerfile index 3628b2c6..a1eb1d02 100644 --- a/tests/diff_base/docker/Dockerfile +++ b/tests/diff_base/docker/Dockerfile @@ -1,14 +1,14 @@ -# Base Image: PLACEHOLDER -FROM PLACEHOLDER AS amd64 -# Base Image: PLACEHOLDER -FROM PLACEHOLDER AS arm64 +# Base Image: {PLACEHOLDER} +FROM {PLACEHOLDER} AS amd64 +# Base Image: {PLACEHOLDER} +FROM {PLACEHOLDER} AS arm64 # Use docker automatic platform args to select the base image. # It may be `arm64` or `amd64` depending on the platform. # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope FROM $TARGETARCH ARG TARGETARCH -MULTILINE_PLACEHOLDER +{PLACEHOLDER_MULTILINE} # Arguments for the default user ARG USERNAME=user ARG USER_UID=1000 @@ -84,14 +84,14 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ # apt-get update && apt-get install -y \ # $OTHER_PACKAGES \ # && rm -rf /var/lib/apt/lists/* -MULTILINE_PLACEHOLDER +{PLACEHOLDER_MULTILINE} USER $USERNAME # Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount RUN mkdir /home/$USERNAME/.gazebo # TODO: Run additional commands as non-root user here -MULTILINE_PLACEHOLDER +{PLACEHOLDER_MULTILINE} COPY .bashrc /home/$USERNAME/.bashrc # TODO: Copy additional files here -MULTILINE_PLACEHOLDER +{PLACEHOLDER_MULTILINE} ENTRYPOINT [] CMD ["/bin/bash"] diff --git a/tests/diff_base/docker/compose.yaml b/tests/diff_base/docker/compose.yaml index 41929f83..4e218032 100644 --- a/tests/diff_base/docker/compose.yaml +++ b/tests/diff_base/docker/compose.yaml @@ -1,5 +1,5 @@ services: - PLACEHOLDER-ws: + {PLACEHOLDER}-ws: build: context: . dockerfile: Dockerfile @@ -7,15 +7,15 @@ services: # Reference: https://docs.docker.com/compose/compose-file/build/#platforms # platforms: # - "linux/arm64" - image: j3soon/ros2-PLACEHOLDER-ws - container_name: ros2-PLACEHOLDER-ws + image: j3soon/ros2-{PLACEHOLDER}-ws + container_name: ros2-{PLACEHOLDER}-ws stdin_open: true tty: true # TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices. - PLACEHOLDERprivileged: true + {PLACEHOLDER_#}privileged: true command: /bin/bash network_mode: host - working_dir: /home/ros2-essentials/PLACEHOLDER_ws + working_dir: /home/ros2-essentials/{PLACEHOLDER}_ws environment: # Set X11 server environment variable for existing display. - DISPLAY=$DISPLAY @@ -28,18 +28,18 @@ services: - ROS_DOMAIN_ID=0 # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - - ROS2_WS=/home/ros2-essentials/PLACEHOLDER_ws + - ROS2_WS=/home/ros2-essentials/{PLACEHOLDER}_ws # TODO: Set more environment variables. -MULTILINE_PLACEHOLDER +{PLACEHOLDER_MULTILINE} # TODO: Uncomment the lines below to enable GPU support. - # # Reference: https://docs.docker.com/compose/gpu-support/ - # deploy: - # resources: - # reservations: - # devices: - # - driver: nvidia - # count: all - # capabilities: [ gpu ] + {PLACEHOLDER_#}# Reference: https://docs.docker.com/compose/gpu-support/ + {PLACEHOLDER_#}deploy: + {PLACEHOLDER_#} resources: + {PLACEHOLDER_#} reservations: + {PLACEHOLDER_#} devices: + {PLACEHOLDER_#} - driver: nvidia + {PLACEHOLDER_#} count: all + {PLACEHOLDER_#} capabilities: [ gpu ] volumes: # Mount local timezone into container. # Reference: https://stackoverflow.com/questions/57607381/how-do-i-change-timezone-in-a-docker-container @@ -51,13 +51,13 @@ MULTILINE_PLACEHOLDER - $HOME/.Xauthority:/home/user/.Xauthority # Xauthority is mounted to allow X11 forwarding for remote display. # Mount Direct Rendering Infrastructure (DRI) for hardware acceleration support such as OpenGL. - PLACEHOLDER- /dev/dri:/dev/dri + {PLACEHOLDER_#}- /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - PLACEHOLDER- /dev/snd:/dev/snd + {PLACEHOLDER_#}- /dev/snd:/dev/snd # Mount shared memory for ROS2 communication. - PLACEHOLDER- /dev/shm:/dev/shm + {PLACEHOLDER_#}- /dev/shm:/dev/shm # TODO: Uncomment the line below and comment out the three entries above to enable USB support. - PLACEHOLDER- /dev:/dev + {PLACEHOLDER_#}- /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. diff --git a/tests/lint_comp_template.py b/tests/lint_comp_template.py index 6af81c02..45e962f7 100644 --- a/tests/lint_comp_template.py +++ b/tests/lint_comp_template.py @@ -9,6 +9,12 @@ current_dir = os.path.dirname(os.path.realpath(__file__)) repo_dir = os.path.realpath(f"{current_dir}/..") +def get_regexp_from_template_line(line): + regexp = re.escape(line) \ + .replace(r'\{PLACEHOLDER_\#\}', '(# )?') \ + .replace(r'\{PLACEHOLDER\}', '.*') + return f"^{regexp}$" + def compare_file_with_template(filepath, targetpath=None, ignored_workspaces=[]): targetpath = targetpath or filepath logging.info(f"Checking if '{targetpath}' matches the template...") @@ -28,7 +34,7 @@ def error(msg, i): raise ValueError(f"'{filepath}' does not match the template: '{filename}'") i = 0 while i < len(diff): - if "- MULTILINE_PLACEHOLDER" in diff[i]: # don't use exact match to avoid cases without trailing newline + if "- {PLACEHOLDER_MULTILINE}" in diff[i]: # don't use exact match to avoid cases without trailing newline i += 1 while i < len(diff) and diff[i].startswith('+ '): i += 1 @@ -47,9 +53,9 @@ def error(msg, i): j += 1 k = 0 while k < len(stack) and j+k < len(diff) and diff[j+k].startswith('+ '): - if "- MULTILINE_PLACEHOLDER" in diff[i+k]: - raise error("MULTILINE_PLACEHOLDER is not supported in this case yet", i) - regexp = "^" + re.escape(diff[i+k][2:]).replace('PLACEHOLDER', '.*') + "$" + if "- {PLACEHOLDER_MULTILINE}" in diff[i+k]: + raise error("{PLACEHOLDER_MULTILINE} is not supported in this case yet", i) + regexp = get_regexp_from_template_line(diff[i+k][2:]) if not re.match(regexp, diff[j+k][2:]): error("Expected line deletion and addition to differ only in the placeholder", i) k += 1 @@ -63,9 +69,9 @@ def error(msg, i): j += 1 k = 0 while k < len(stack) and j+k < len(diff) and diff[j+k].startswith('- '): - if "- MULTILINE_PLACEHOLDER" in diff[j+k]: - raise error("MULTILINE_PLACEHOLDER is not supported in this case yet", i) - regexp = "^" + re.escape(diff[j+k][2:]).replace('PLACEHOLDER', '.*') + "$" + if "- {PLACEHOLDER_MULTILINE}" in diff[j+k]: + raise error("{PLACEHOLDER_MULTILINE} is not supported in this case yet", i) + regexp = get_regexp_from_template_line(diff[j+k][2:]) if not re.match(regexp, diff[i+k][2:]): error("Expected line deletion and addition to differ only in the placeholder", i) k += 1 diff --git a/vlp_ws/docker/.bashrc b/vlp_ws/docker/.bashrc index e0db1d55..d8352e3e 100644 --- a/vlp_ws/docker/.bashrc +++ b/vlp_ws/docker/.bashrc @@ -26,6 +26,5 @@ if [ ! -f $ROS2_WS/install/setup.bash ]; then echo "Workspace built." fi # TODO: Source other workspace environments as underlay -MULTILINE_PLACEHOLDER # Source workspace environment source $ROS2_WS/install/setup.bash From 66c9bd87569759b5ab6e4bcef9b2ebce21d09499 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 16:23:29 +0800 Subject: [PATCH 22/24] docs: Add todo for more volume mounts --- cartographer_ws/docker/compose.yaml | 3 ++- husky_ws/docker/compose.yaml | 3 ++- kobuki_ws/docker/compose.yaml | 3 ++- orbslam3_ws/docker/compose.yaml | 3 ++- rtabmap_ws/docker/compose.yaml | 3 ++- template_ws/docker/compose.yaml | 3 ++- tests/diff_base/docker/compose.yaml | 4 +++- vlp_ws/docker/compose.yaml | 3 ++- 8 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cartographer_ws/docker/compose.yaml b/cartographer_ws/docker/compose.yaml index df701945..cb079eb1 100644 --- a/cartographer_ws/docker/compose.yaml +++ b/cartographer_ws/docker/compose.yaml @@ -29,7 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/cartographer_ws - # TODO: Set more environment variables. + # TODO: Add more environment variables here. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: @@ -61,6 +61,7 @@ services: # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. - gazebo-cache:/home/user/.gazebo + # TODO: Add more volume mounts here. # Mount root workspace to allow easy access to all workspaces. - ../..:/home/ros2-essentials volumes: diff --git a/husky_ws/docker/compose.yaml b/husky_ws/docker/compose.yaml index a69e1a08..8bb97b10 100644 --- a/husky_ws/docker/compose.yaml +++ b/husky_ws/docker/compose.yaml @@ -29,7 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/husky_ws - # TODO: Set more environment variables. + # TODO: Add more environment variables here. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: @@ -61,6 +61,7 @@ services: # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. - gazebo-cache:/home/user/.gazebo + # TODO: Add more volume mounts here. # Mount root workspace to allow easy access to all workspaces. - ../..:/home/ros2-essentials volumes: diff --git a/kobuki_ws/docker/compose.yaml b/kobuki_ws/docker/compose.yaml index 9d8a942a..7471d5f6 100644 --- a/kobuki_ws/docker/compose.yaml +++ b/kobuki_ws/docker/compose.yaml @@ -29,7 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/kobuki_ws - # TODO: Set more environment variables. + # TODO: Add more environment variables here. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: @@ -61,6 +61,7 @@ services: # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. - gazebo-cache:/home/user/.gazebo + # TODO: Add more volume mounts here. # Mount root workspace to allow easy access to all workspaces. - ../..:/home/ros2-essentials volumes: diff --git a/orbslam3_ws/docker/compose.yaml b/orbslam3_ws/docker/compose.yaml index 14c54e1f..88a94a74 100644 --- a/orbslam3_ws/docker/compose.yaml +++ b/orbslam3_ws/docker/compose.yaml @@ -29,7 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/orbslam3_ws - # TODO: Set more environment variables. + # TODO: Add more environment variables here. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: @@ -61,6 +61,7 @@ services: # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. - gazebo-cache:/home/user/.gazebo + # TODO: Add more volume mounts here. # Mount root workspace to allow easy access to all workspaces. - ../..:/home/ros2-essentials volumes: diff --git a/rtabmap_ws/docker/compose.yaml b/rtabmap_ws/docker/compose.yaml index 36a209ed..e0392a3c 100644 --- a/rtabmap_ws/docker/compose.yaml +++ b/rtabmap_ws/docker/compose.yaml @@ -29,7 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/rtabmap_ws - # TODO: Set more environment variables. + # TODO: Add more environment variables here. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: @@ -61,6 +61,7 @@ services: # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. - gazebo-cache:/home/user/.gazebo + # TODO: Add more volume mounts here. # Mount root workspace to allow easy access to all workspaces. - ../..:/home/ros2-essentials volumes: diff --git a/template_ws/docker/compose.yaml b/template_ws/docker/compose.yaml index 63a19d47..abe1e143 100644 --- a/template_ws/docker/compose.yaml +++ b/template_ws/docker/compose.yaml @@ -29,7 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/template_ws - # TODO: Set more environment variables. + # TODO: Add more environment variables here. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: @@ -61,6 +61,7 @@ services: # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. - gazebo-cache:/home/user/.gazebo + # TODO: Add more volume mounts here. # Mount root workspace to allow easy access to all workspaces. - ../..:/home/ros2-essentials volumes: diff --git a/tests/diff_base/docker/compose.yaml b/tests/diff_base/docker/compose.yaml index 4e218032..d18260d2 100644 --- a/tests/diff_base/docker/compose.yaml +++ b/tests/diff_base/docker/compose.yaml @@ -29,7 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/{PLACEHOLDER}_ws - # TODO: Set more environment variables. + # TODO: Add more environment variables here. {PLACEHOLDER_MULTILINE} # TODO: Uncomment the lines below to enable GPU support. {PLACEHOLDER_#}# Reference: https://docs.docker.com/compose/gpu-support/ @@ -62,6 +62,8 @@ services: # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. - gazebo-cache:/home/user/.gazebo + # TODO: Add more volume mounts here. +{PLACEHOLDER_MULTILINE} # Mount root workspace to allow easy access to all workspaces. - ../..:/home/ros2-essentials volumes: diff --git a/vlp_ws/docker/compose.yaml b/vlp_ws/docker/compose.yaml index cb722880..364ae7ae 100644 --- a/vlp_ws/docker/compose.yaml +++ b/vlp_ws/docker/compose.yaml @@ -29,7 +29,7 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/vlp_ws - # TODO: Set more environment variables. + # TODO: Add more environment variables here. # TODO: Uncomment the lines below to enable GPU support. # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: @@ -61,6 +61,7 @@ services: # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. - gazebo-cache:/home/user/.gazebo + # TODO: Add more volume mounts here. # Mount root workspace to allow easy access to all workspaces. - ../..:/home/ros2-essentials volumes: From 91ef33e1a49162ddcae6c1268cafa1e7628f8e23 Mon Sep 17 00:00:00 2001 From: YuZhong-Chen Date: Thu, 22 Aug 2024 18:35:35 +0800 Subject: [PATCH 23/24] fix(kobuki_ws): Ignore package when building workspace in .bashrc --- kobuki_ws/docker/.bashrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kobuki_ws/docker/.bashrc b/kobuki_ws/docker/.bashrc index ba8a33c9..2641d9fb 100644 --- a/kobuki_ws/docker/.bashrc +++ b/kobuki_ws/docker/.bashrc @@ -19,7 +19,7 @@ if [ ! -f $ROS2_WS/install/setup.bash ]; then # TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore ` to ignore x86 packages # Ref: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html if [ $(arch) == "aarch64" ]; then - colcon build --symlink-install + colcon build --symlink-install --packages-ignore velodyne_gazebo_plugins else colcon build --symlink-install fi From ea75147c5d48388a73d43495654105841a3ddb39 Mon Sep 17 00:00:00 2001 From: YuZhong-Chen Date: Thu, 22 Aug 2024 18:39:01 +0800 Subject: [PATCH 24/24] style(vlp_ws): Adjust the position of the line break. --- vlp_ws/docker/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vlp_ws/docker/Dockerfile b/vlp_ws/docker/Dockerfile index 47399e69..485e0a3b 100644 --- a/vlp_ws/docker/Dockerfile +++ b/vlp_ws/docker/Dockerfile @@ -86,6 +86,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ # apt-get update && apt-get install -y \ # $OTHER_PACKAGES \ # && rm -rf /var/lib/apt/lists/* + # Install ROS2 and Gazebo simulation packages when using `amd64` platform RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ if [ "$TARGETARCH" = "amd64" ]; then \ @@ -101,8 +102,8 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ apt-get update && apt-get install -y \ ros-$ROS_DISTRO-turtlebot3 \ ros-$ROS_DISTRO-diagnostic-updater \ - ros-$ROS_DISTRO-velodyne && \ - rm -rf /var/lib/apt/lists/* + ros-$ROS_DISTRO-velodyne \ + && rm -rf /var/lib/apt/lists/* USER $USERNAME # Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount