diff --git a/template_ws/.devcontainer/devcontainer.json b/template_ws/.devcontainer/devcontainer.json index 73b636a3..b7c6fef6 100644 --- a/template_ws/.devcontainer/devcontainer.json +++ b/template_ws/.devcontainer/devcontainer.json @@ -19,7 +19,5 @@ "ms-iot.vscode-ros" ] } - }, - // Lifecycle scripts - "postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/postCreateCommand.sh" + } } \ No newline at end of file diff --git a/template_ws/.devcontainer/postCreateCommand.sh b/template_ws/.devcontainer/postCreateCommand.sh deleted file mode 100755 index 8ba176f9..00000000 --- a/template_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-essentials/ -# colcon build diff --git a/template_ws/docker/.bashrc b/template_ws/docker/.bashrc index fead3a0b..51e26e5d 100644 --- a/template_ws/docker/.bashrc +++ b/template_ws/docker/.bashrc @@ -1,10 +1,23 @@ # Source global ROS2 environment source /opt/ros/$ROS_DISTRO/setup.bash -# 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 + # Ref: https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html + rosdep install --from-paths src --ignore-src -y # 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