From d9d21c2ace735e657f61bdeba9e843f9149e1871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fan=20Ulus?= Date: Sun, 21 Jul 2024 23:31:15 +0300 Subject: [PATCH] Add builder image and build action (#2) * Add builder image and build action --- .github/workflows/builder-build.yml | 111 +++++++++++++++ Dockerfile | 205 ++++++++++++++++++++++++++++ autoware.repos.yml | 141 +++++++++++++++++++ 3 files changed, 457 insertions(+) create mode 100644 .github/workflows/builder-build.yml create mode 100644 Dockerfile create mode 100644 autoware.repos.yml diff --git a/.github/workflows/builder-build.yml b/.github/workflows/builder-build.yml new file mode 100644 index 0000000..1ec8d17 --- /dev/null +++ b/.github/workflows/builder-build.yml @@ -0,0 +1,111 @@ +name: Build Autoware builder container images +on: + workflow_dispatch: + schedule: + - cron: '34 15 * * 0' # 15:34 UTC every Sunday + push: + paths: + - Dockerfile + - autoware.repos.yml + - .github/workflows/builder-build.yml # Self-trigger + +env: + REGISTRY: ghcr.io + IMAGE_NAME: bounverif/autoware + AUTOWARE_VERSION: latest + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + packages: write + +jobs: + autoware-builder-build: + runs-on: ubuntu-latest + steps: + - name: Maximize build space + uses: easimon/maximize-build-space@v10 + with: + root-reserve-mb: 2048 # Reserve disk space for repository + remove-dotnet: 'true' + remove-android: 'true' + remove-haskell: 'true' + remove-codeql: 'true' + remove-docker-images: 'true' + build-mount-path: '/var/lib/docker' # The remaining space only for Docker + - name: Restart docker + run: sudo service docker restart + + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to the registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set current date as the version + run: echo "AUTOWARE_VERSION=$(date +'%Y%m%d')" >> $GITHUB_ENV + + - name: Build builder image + uses: docker/build-push-action@v6 + with: + context: . + target: autoware-builder + build-args: | + "AUTOWARE_VERSION=${{ env.AUTOWARE_VERSION }}" + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.AUTOWARE_VERSION }}-builder + load: true + no-cache: true + cache-to: type=inline + + - name: Build builder w/cache image + uses: docker/build-push-action@v6 + with: + context: . + target: autoware-builder-with-cache + build-args: | + "AUTOWARE_VERSION=${{ env.AUTOWARE_VERSION }}" + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.AUTOWARE_VERSION }}-builder-with-cache + load: true + cache-from: | + type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.AUTOWARE_VERSION }}-builder + cache-to: type=inline + + - name: Push builder image + uses: docker/build-push-action@v6 + with: + context: . + target: autoware-builder + build-args: | + "AUTOWARE_VERSION=${{ env.AUTOWARE_VERSION }}" + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-builder + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.AUTOWARE_VERSION }}-builder + push: true + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.AUTOWARE_VERSION }}-builder + cache-to: type=inline + + - name: Push builder-with-cache image + uses: docker/build-push-action@v6 + with: + context: . + target: autoware-builder-with-cache + build-args: | + "AUTOWARE_VERSION=${{ env.AUTOWARE_VERSION }}" + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-builder-with-cache + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.AUTOWARE_VERSION }}-builder-with-cache + push: true + cache-from: | + type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.AUTOWARE_VERSION }}-builder + type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.AUTOWARE_VERSION }}-builder-with-cache + cache-to: type=inline diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2195ef4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,205 @@ +FROM ubuntu:22.04 AS autoware-base + +ARG TARGETARCH +ENV ID=ubuntu +ENV VERSION_ID=22.04 +ENV CACHEMOUNT_PREFIX=/${TARGETARCH}/${ID}${VERSION_ID} +ENV DEBIAN_FRONTEND=noninteractive + +# Metadata +LABEL org.opencontainers.image.vendor="tr.edu.bogazici.cmpe.bounverif" +LABEL org.opencontainers.image.version="0.1.0" +LABEL org.opencontainers.image.authors="Bogazici University System Verification Group" +LABEL org.opencontainers.image.source="https://github.com/bounverif/autoware" +LABEL org.opencontainers.image.title="Autoware" + +# Autoware variables +ARG AUTOWARE_VERSION=latest +ENV AUTOWARE_VERSION=${AUTOWARE_VERSION} +ENV AUTOWARE_SOURCE_DIR=/usr/local/src/autoware +ENV AUTOWARE_BUILD_DIR=/tmp/build/autoware +ENV AUTOWARE_INSTALL_DIR=/opt/autoware/humble + +# CUDA variables +ARG CUDA_ARCH=x86_64 +ARG CUDA_DISTRO=ubuntu2204 +ARG CUDA_KEYRING_PACKAGE=cuda-keyring_1.1-1_all.deb +ARG CUDA_KEYRING_FILEPATH=https://developer.download.nvidia.com/compute/cuda/repos/${CUDA_DISTRO}/${CUDA_ARCH}/${CUDA_KEYRING_PACKAGE} + +# Debian containers save no deb archives by default. +# The following command disables clean-up actions to enable +# --mount=type=cache,target=/var/cache/apt +# optimizations. Otherwise, apt caching does not work. +RUN rm -f /etc/apt/apt.conf.d/docker-clean + +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=${CACHEMOUNT_PREFIX}/var/cache/apt \ + apt-get update && apt-get install -y --no-install-recommends \ + sudo \ + tini \ + wget \ + gnupg2 \ + ca-certificates \ + && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* + +# User management +ARG USER=bounverif +ARG USERGROUP=${USER} +ARG UID=1000 +ARG GID=${UID} + +RUN groupadd ${USERGROUP} -g ${GID} && \ + useradd -ms /bin/bash ${USER} -g ${USERGROUP} -u ${UID} && \ + printf "${USER} ALL= NOPASSWD: ALL\\n" >> /etc/sudoers + +# Repository management +RUN wget -qO- "https://keyserver.ubuntu.com/pks/lookup?fingerprint=on&op=get&search=0x6125E2A8C77F2818FB7BD15B93C4A3FD7BB9C367" | gpg --dearmour -o /usr/share/keyrings/ansible-archive-keyring.gpg && \ + echo "deb [signed-by=/usr/share/keyrings/ansible-archive-keyring.gpg] http://ppa.launchpad.net/ansible/ansible/ubuntu jammy main" | tee /etc/apt/sources.list.d/ansible.list && \ + wget -qO- "https://raw.githubusercontent.com/ros/rosdistro/master/ros.key" | gpg --dearmour -o /usr/share/keyrings/ros-archive-keyring.gpg && \ + echo "deb [signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu jammy main" > /etc/apt/sources.list.d/ros2.list && \ + wget -q ${CUDA_KEYRING_FILEPATH} && dpkg -i ${CUDA_KEYRING_PACKAGE} && rm ${CUDA_KEYRING_PACKAGE} + +FROM autoware-base AS autoware-source + +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=${CACHEMOUNT_PREFIX}/var/cache/apt \ + apt-get update && apt-get install -y --no-install-recommends \ + git \ + python3-minimal \ + python3-vcstool \ + && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* + +COPY autoware.repos.yml /var/lib/autoware/autoware.repos.${AUTOWARE_VERSION}.yml + +RUN mkdir -p ${AUTOWARE_SOURCE_DIR} && vcs import --shallow ${AUTOWARE_SOURCE_DIR} < /var/lib/autoware/autoware.repos.${AUTOWARE_VERSION}.yml + +FROM autoware-base AS autoware-builder-nocuda + +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=${CACHEMOUNT_PREFIX}/var/cache/apt \ + apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + git \ + cmake \ + ccache \ + ninja-build \ + python3-minimal \ + python3-vcstool \ + python3-rosdep \ + python3-colcon-core \ + python3-colcon-common-extensions \ + && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* + +RUN --mount=type=bind,from=autoware-source,source=${AUTOWARE_SOURCE_DIR},target=${AUTOWARE_SOURCE_DIR} \ + --mount=type=cache,target=/var/cache/apt,sharing=locked,id=${CACHEMOUNT_PREFIX}/var/cache/apt \ + rosdep init && apt update && rosdep update && \ + rosdep install -y \ + --from-paths ${AUTOWARE_SOURCE_DIR} \ + --ignore-src \ + --rosdistro humble \ + && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* + +ENV CMAKE_GENERATOR=Ninja + +ENV CMAKE_C_COMPILER_LAUNCHER=ccache +ENV CMAKE_CXX_COMPILER_LAUNCHER=ccache + +ENV CCACHE_DIR=/var/cache/ccache + +RUN mkdir -p ${CCACHE_DIR} && chmod 777 ${CCACHE_DIR} + +FROM autoware-builder-nocuda AS autoware-builder + +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=${CACHEMOUNT_PREFIX}/var/cache/apt \ + apt-get update && apt-get install -y --no-install-recommends \ + cuda-minimal-build-12-4 \ + libcublas-dev-12-4 \ + libcurand-dev-12-4 \ + libcusolver-dev-12-4 \ + libnvinfer-dev=8.* \ + libnvinfer-headers-dev=8.* \ + libnvinfer-plugin-dev=8.* \ + libnvinfer-headers-plugin-dev=8.* \ + libnvparsers-dev=8.* \ + libnvonnxparsers-dev=8.* \ + && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* + +ENV PATH="/usr/local/cuda-12.4/bin:${PATH}" + +FROM autoware-builder AS autoware-builder-with-cache + +# +# This build is only for producing a build cache to be saved in the image. +# Hence, we do not want build artifacts and logs. +# +RUN --mount=type=bind,from=autoware-source,source=${AUTOWARE_SOURCE_DIR},target=${AUTOWARE_SOURCE_DIR} \ + . /opt/ros/humble/setup.sh && \ + colcon --log-base /dev/null build \ + --base-paths ${AUTOWARE_SOURCE_DIR} \ + --build-base ${AUTOWARE_BUILD_DIR} \ + --install-base ${AUTOWARE_INSTALL_DIR} \ + --packages-up-to autoware_launch \ + --event-handlers \ + console_direct- \ + console_stderr+ \ + console_cohesion- \ + console_start_end- \ + console_package_list- \ + status- \ + summary+ \ + desktop_notification- \ + --cmake-args \ + -DCMAKE_BUILD_TYPE=Release \ + " -Wno-dev" \ + " --no-warn-unused-cli" \ + && rm -rf ${AUTOWARE_BUILD_DIR} \ + && rm -rf ${AUTOWARE_INSTALL_DIR} \ + && du -h --max-depth=0 ${CCACHE_DIR} + +FROM autoware-builder-with-cache AS autoware-prebuilt + +COPY autoware.repos.yml /var/lib/autoware/autoware.repos.${AUTOWARE_VERSION}.yml + +RUN mkdir -p ${AUTOWARE_SOURCE_DIR} && vcs import --shallow ${AUTOWARE_SOURCE_DIR} < /var/lib/autoware/autoware.repos.${AUTOWARE_VERSION}.yml \ + ccache --zero-stats && \ + . /opt/ros/humble/setup.sh && \ + colcon --log-base /dev/null build \ + --base-paths ${AUTOWARE_SOURCE_DIR} \ + --build-base ${AUTOWARE_BUILD_DIR} \ + --install-base ${AUTOWARE_INSTALL_DIR} \ + --packages-up-to autoware_launch \ + --event-handlers \ + console_direct- \ + console_stderr+ \ + console_cohesion- \ + console_start_end- \ + console_package_list- \ + status- \ + summary+ \ + desktop_notification- \ + --cmake-args \ + -DCMAKE_BUILD_TYPE=Release \ + " -Wno-dev" \ + " --no-warn-unused-cli" \ + && rm -rf ${AUTOWARE_SOURCE_DIR} \ + && rm -rf ${AUTOWARE_BUILD_DIR} \ + && ccache -v --show-stats + +FROM autoware-base AS autoware-runtime + +# This is not complete. It is just a placeholder for the final image. + +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,graphics + +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=${CACHEMOUNT_PREFIX}/var/cache/apt \ + apt-get update && apt-get install -y --no-install-recommends \ + libcublas-12-4 \ + libcurand-12-4 \ + && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* + +COPY --from=autoware-prebuilt ${AUTOWARE_INSTALL_DIR} ${AUTOWARE_INSTALL_DIR} + +FROM autoware-builder AS autoware-devel + +# This is not complete. It is just a placeholder for the final image. + +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,graphics diff --git a/autoware.repos.yml b/autoware.repos.yml new file mode 100644 index 0000000..961a50e --- /dev/null +++ b/autoware.repos.yml @@ -0,0 +1,141 @@ +repositories: + # core + core/autoware_msgs: + type: git + url: https://github.com/autowarefoundation/autoware_msgs.git + version: 1.1.0 + core/autoware_adapi_msgs: + type: git + url: https://github.com/autowarefoundation/autoware_adapi_msgs.git + version: 1.3.0 + core/autoware_internal_msgs: + type: git + url: https://github.com/autowarefoundation/autoware_internal_msgs.git + version: 1.1.0 + # TODO(youtalk): Remove autoware_common when https://github.com/autowarefoundation/autoware/issues/4911 is closed + core/autoware_common: + type: git + url: https://github.com/autowarefoundation/autoware_common.git + version: remove-autoware-cmake-utils + core/autoware_cmake: + type: git + url: https://github.com/autowarefoundation/autoware_cmake.git + version: 1.0.0 + core/autoware_utils: + type: git + url: https://github.com/autowarefoundation/autoware_utils.git + version: 1.0.0 + core/autoware_lanelet2_extension: + type: git + url: https://github.com/autowarefoundation/autoware_lanelet2_extension.git + version: 0.5.0 + core/autoware.core: + type: git + url: https://github.com/autowarefoundation/autoware.core.git + version: main + core/external/autoware_auto_msgs: # TODO(mfc): Remove when autoware_msgs is merged + type: git + url: https://github.com/tier4/autoware_auto_msgs.git + version: tier4/main + # universe + universe/autoware.universe: + type: git + url: https://github.com/autowarefoundation/autoware.universe.git + version: main + universe/external/tier4_ad_api_adaptor: # TODO(TIER IV): Improve design/code and transfer to AWF + type: git + url: https://github.com/tier4/tier4_ad_api_adaptor.git + version: tier4/universe + universe/external/tier4_autoware_msgs: + type: git + url: https://github.com/tier4/tier4_autoware_msgs.git + version: tier4/universe + universe/external/morai_msgs: + type: git + url: https://github.com/MORAI-Autonomous/MORAI-ROS2_morai_msgs.git + version: main + universe/external/muSSP: + type: git + url: https://github.com/tier4/muSSP.git + version: tier4/main + universe/external/ndt_omp: + type: git + url: https://github.com/tier4/ndt_omp.git + version: tier4/main + universe/external/pointcloud_to_laserscan: + type: git + url: https://github.com/tier4/pointcloud_to_laserscan.git + version: tier4/main + universe/external/eagleye: + type: git + url: https://github.com/MapIV/eagleye.git + version: autoware-main + universe/external/rtklib_ros_bridge: + type: git + url: https://github.com/MapIV/rtklib_ros_bridge.git + version: ros2-v0.1.0 + universe/external/llh_converter: + type: git + url: https://github.com/MapIV/llh_converter.git + version: ros2 + universe/external/ament_cmake: # TODO(mitsudome-r): remove when https://github.com/ament/ament_cmake/pull/448 is merged + type: git + url: https://github.com/autowarefoundation/ament_cmake.git + version: feat/faster_ament_libraries_deduplicate + universe/external/glog: # TODO(Horibe): to use isGoogleInitialized() API in v0.6.0. Remove when the rosdep glog version is updated to v0.6.0 (already updated in Ubuntu 24.04) + type: git + url: https://github.com/tier4/glog.git + version: v0.6.0_t4-ros + # launcher + launcher/autoware_launch: + type: git + url: https://github.com/autowarefoundation/autoware_launch.git + version: main + # sensor_component + sensor_component/external/sensor_component_description: + type: git + url: https://github.com/tier4/sensor_component_description.git + version: main + sensor_component/external/tamagawa_imu_driver: + type: git + url: https://github.com/tier4/tamagawa_imu_driver.git + version: ros2 + sensor_component/external/nebula: + type: git + url: https://github.com/tier4/nebula.git + version: main + sensor_component/external/transport_drivers: + type: git + url: https://github.com/MapIV/transport_drivers.git + version: boost + # sensor_kit + sensor_kit/sample_sensor_kit_launch: + type: git + url: https://github.com/autowarefoundation/sample_sensor_kit_launch.git + version: main + sensor_kit/external/awsim_sensor_kit_launch: # TODO: Integrate into sample_sensor_kit_launch + type: git + url: https://github.com/RobotecAI/awsim_sensor_kit_launch.git + version: main + sensor_kit/awsim_labs_sensor_kit_launch: + type: git + url: https://github.com/autowarefoundation/awsim_labs_sensor_kit_launch.git + version: main + # vehicle + vehicle/sample_vehicle_launch: + type: git + url: https://github.com/autowarefoundation/sample_vehicle_launch.git + version: main + vehicle/external/pacmod_interface: + type: git + url: https://github.com/tier4/pacmod_interface.git + version: main + vehicle/external/pacmod3_msgs: + type: git + url: https://github.com/astuff/pacmod3_msgs.git + version: 1.0.0 + # param + param/autoware_individual_params: + type: git + url: https://github.com/autowarefoundation/autoware_individual_params.git + version: main \ No newline at end of file