diff --git a/.circleci/config.yml b/.circleci/config.yml index 2391c81..3925460 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,7 +28,7 @@ jobs: # Pull docker image from docker hub # XTERM used for better catkin_make output docker: - - image: usdotfhwastol/autoware.ai:carma-system-4.1.0 + - image: usdotfhwastol/autoware.ai:carma-system-4.2.0 user: carma environment: TERM: xterm # use xterm to get full display output from build diff --git a/Dockerfile b/Dockerfile index 95f1d0c..de51a6e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,15 +12,19 @@ # License for the specific language governing permissions and limitations under # the License. -FROM usdotfhwastol/autoware.ai:carma-system-4.1.0 as setup +FROM usdotfhwastol/autoware.ai:carma-system-4.2.0 as setup +ARG ROS1_PACKAGES="" +ENV ROS1_PACKAGES=${ROS1_PACKAGES} +ARG ROS2_PACKAGES="" +ENV ROS2_PACKAGES=${ROS2_PACKAGES} RUN mkdir ~/src COPY --chown=carma . /home/carma/src/ RUN ~/src/docker/checkout.bash RUN ~/src/docker/install.sh -FROM usdotfhwastol/autoware.ai:carma-system-4.1.0 +FROM usdotfhwastol/autoware.ai:carma-system-4.2.0 ARG BUILD_DATE="NULL" diff --git a/docker/build-image.sh b/docker/build-image.sh index f9ff271..a4f5e4a 100755 --- a/docker/build-image.sh +++ b/docker/build-image.sh @@ -44,9 +44,59 @@ while [[ $# -gt 0 ]]; do COMPONENT_VERSION_STRING=develop shift ;; + --ros-1-packages|--ros1) + ROS1_PACKAGES="" + shift + ;; + --ros-2-packages|--ros2) + ROS2_PACKAGES="" + shift + ;; + *) + # Var test based on Stack Overflow question: https://stackoverflow.com/questions/5406858/difference-between-unset-and-empty-variables-in-bash + # Asker: green69 + # Answerer: geekosaur + if [ "${ROS2_PACKAGES+set}" = "set" ]; then + ROS2_PACKAGES="$ROS2_PACKAGES $arg" + elif [ "${ROS1_PACKAGES+set}" = "set" ]; then + ROS1_PACKAGES="$ROS1_PACKAGES $arg" + else + echo "Unknown argument $arg..." + exit -1 + fi + shift + ;; esac done +if [[ ! -z "$ROS1_PACKAGES$ROS2_PACKAGES" ]]; then + echo "Performing incremental build of image to rebuild packages: $ROS1_PACKAGES $ROS2_PACKAGES..." + + echo "Updating Dockerfile references to use most recent image as base image" + # Trim of docker image LS command sourced from + # https://stackoverflow.com/questions/50625619/why-doesnt-the-cut-command-work-for-a-docker-image-ls-command + # Question Asker: Chris F + # Question Answerer: Arount + MOST_RECENT_IMAGE_DATA=$(docker image ls | grep $IMAGE | tr -s ' ') + + if [[ -z "$MOST_RECENT_IMAGE_DATA" ]]; then + echo No prior image exists to use as base, an initial image must be built first before attempting incremental build. + exit -1 + fi + + MOST_RECENT_IMAGE_HASH=$(echo $MOST_RECENT_IMAGE_DATA | cut -d " " -f 3) + MOST_RECENT_IMAGE_ORG=$(echo $MOST_RECENT_IMAGE_DATA | cut -d " " -f 1 | cut -d "/" -f 1) + MOST_RECENT_IMAGE_TAG=$(echo $MOST_RECENT_IMAGE_DATA | cut -d " " -f 2) + MOST_RECENT_IMAGE_DATE=$(echo $MOST_RECENT_IMAGE_DATA | cut -d " " -f 4,5,6) + + echo Using $MOST_RECENT_IMAGE_TAG $MOST_RECENT_IMAGE_HASH $MOST_RECENT_IMAGE_DATE as base for partial build... + + sed -i "s|^FROM[[:space:]]*[^[:space:]]*|FROM $MOST_RECENT_IMAGE_HASH|I" ../Dockerfile + + COMPONENT_VERSION_STRING="SNAPSHOT" + USERNAME="local" +fi + if [[ -z "$COMPONENT_VERSION_STRING" ]]; then COMPONENT_VERSION_STRING=$("./get-component-version.sh") fi @@ -61,8 +111,18 @@ if [[ $COMPONENT_VERSION_STRING = "develop" ]]; then --build-arg VERSION="$COMPONENT_VERSION_STRING" \ --build-arg VCS_REF=`git rev-parse --short HEAD` \ --build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` . +elif [[ $COMPONENT_VERSION_STRING = "SNAPSHOT" ]]; then + docker build --network=host --no-cache -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING \ + --build-arg ROS1_PACKAGES="$ROS1_PACKAGES" \ + --build-arg ROS2_PACKAGES="$ROS2_PACKAGES" \ + --build-arg VERSION="$COMPONENT_VERSION_STRING" \ + --build-arg VCS_REF=`git rev-parse --short HEAD` \ + --build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` . else - docker build --no-cache -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING \ + #The addition of --network=host was a fix for a DNS resolution error that occured + #when running the platform inside an Ubuntu 20.04 virtual machine. The error and possible soliutions are + # discussed here: https://github.com/moby/moby/issues/41003 + docker build --network=host --no-cache -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING \ --build-arg VERSION="$COMPONENT_VERSION_STRING" \ --build-arg VCS_REF=`git rev-parse --short HEAD` \ --build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` . diff --git a/docker/checkout.bash b/docker/checkout.bash index f5491a2..ce16c64 100755 --- a/docker/checkout.bash +++ b/docker/checkout.bash @@ -39,6 +39,6 @@ if [[ "$BRANCH" = "develop" ]]; then git clone https://github.com/usdot-fhwa-stol/carma-msgs.git ${dir}/src/CARMAMsgs --branch $BRANCH git clone https://github.com/usdot-fhwa-stol/carma-utils.git ${dir}/src/CARMAUtils --branch $BRANCH else - git clone https://github.com/usdot-fhwa-stol/carma-msgs.git ${dir}/src/CARMAMsgs --branch carma-system-4.1.0 - git clone https://github.com/usdot-fhwa-stol/carma-utils.git ${dir}/src/CARMAUtils --branch carma-system-4.1.0 + git clone https://github.com/usdot-fhwa-stol/carma-msgs.git ${dir}/src/CARMAMsgs --branch carma-system-4.2.0 + git clone https://github.com/usdot-fhwa-stol/carma-utils.git ${dir}/src/CARMAUtils --branch carma-system-4.2.0 fi diff --git a/docker/install.sh b/docker/install.sh index ca48475..145869e 100755 --- a/docker/install.sh +++ b/docker/install.sh @@ -15,16 +15,25 @@ # the License. # Source ros2 -source /opt/ros/foxy/setup.bash +if [[ ! -z "$ROS2_PACKAGES" ]]; then + echo "Sourcing previous build for incremental build start point..." + source /opt/carma/install/setup.bash +else + echo "Sourcing base image for full build..." + source /opt/ros/foxy/setup.bash +fi + # Get driver sudo apt-get update && sudo apt install curl gnupg2 lsb-release sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null -# Install the driver -sudo apt install ros-foxy-velodyne-driver -y -# Install pointcloud conversion package -sudo apt-get install ros-foxy-velodyne-pointcloud +# Install the driver and pointcloud conversion package +sudo apt install ros-foxy-velodyne-driver -y ros-foxy-velodyne-pointcloud # Build wrapper cd ~ -colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --packages-up-to velodyne_lidar_driver_wrapper driver_shutdown_ros2 +if [[ ! -z "$ROS2_PACKAGES" ]]; then + colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --packages-above $ROS2_PACKAGES +else + colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --packages-up-to velodyne_lidar_driver_wrapper driver_shutdown_ros2 +fi