Skip to content

Commit

Permalink
feat(docker): install CUDA development/runtime libraries only 1 time (#…
Browse files Browse the repository at this point in the history
…5419)

* add base-cuda

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>

* update svg

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>

* not cache cuda packages

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>

* push base-cuda image

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>

* Update docker-build-and-push.yaml

* Update docker-build-and-push-arm64.yaml

* separate jobs

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>

---------

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
  • Loading branch information
youtalk authored Nov 12, 2024
1 parent a0d3fca commit 21aa069
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 344 deletions.
26 changes: 26 additions & 0 deletions .github/actions/docker-build-and-push-cuda/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ inputs:
runs:
using: composite
steps:
- name: Install jq and vcstool
run: |
sudo apt-get -y update
sudo apt-get -y install jq python3-pip
pip install --no-cache-dir vcstool
shell: bash

- name: Run vcs import
run: |
mkdir src
vcs import src < autoware.repos
shell: bash

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

Expand Down Expand Up @@ -51,6 +64,18 @@ runs:
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
shell: bash

- name: Docker meta for autoware:base-cuda
id: meta-base-cuda
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }}
tags: |
type=raw,value=base-cuda-${{ inputs.platform }}
type=raw,value=base-cuda-${{ steps.date.outputs.date }}-${{ inputs.platform }}
bake-target: docker-metadata-action-base-cuda
flavor: |
latest=false
- name: Docker meta for autoware:universe-sensing-perception-devel-cuda
id: meta-universe-sensing-perception-devel-cuda
uses: docker/metadata-action@v5
Expand Down Expand Up @@ -112,6 +137,7 @@ runs:
push: true
files: |
docker/docker-bake-cuda.hcl
${{ steps.meta-base-cuda.outputs.bake-file }}
${{ steps.meta-universe-sensing-perception-devel-cuda.outputs.bake-file }}
${{ steps.meta-universe-sensing-perception-cuda.outputs.bake-file }}
${{ steps.meta-universe-devel-cuda.outputs.bake-file }}
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/docker-build-and-push-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,39 @@ jobs:
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:arm64-main
*.cache-to=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:arm64-${{ github.ref_name }},mode=max
- name: Show disk space
if: always()
run: |
df -h
docker-build-and-push-cuda:
needs: [load-env, docker-build-and-push]
runs-on: [self-hosted, linux, ARM64]
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set git config
uses: autowarefoundation/autoware-github-actions/set-git-config@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Free disk space
uses: ./.github/actions/free-disk-space

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
files: |
*.env
*.repos
.github/actions/docker-build-and-push/action.yaml
.github/workflows/docker-build-and-push*.yaml
ansible-galaxy-requirements.yaml
ansible/**
docker/**
- name: Build 'Autoware' with CUDA
if: ${{ steps.changed-files.outputs.any_changed == 'true' ||
github.event_name == 'workflow_dispatch' ||
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/docker-build-and-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ jobs:
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:amd64-main
*.cache-to=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:amd64-${{ github.ref_name }},mode=max
- name: Show disk space
if: always()
run: |
df -h
docker-build-and-push-cuda:
needs: [load-env, docker-build-and-push]
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set git config
uses: autowarefoundation/autoware-github-actions/set-git-config@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Free disk space
uses: ./.github/actions/free-disk-space

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
files: |
*.env
*.repos
.github/actions/docker-build-and-push/action.yaml
.github/workflows/docker-build-and-push*.yaml
ansible-galaxy-requirements.yaml
ansible/**
docker/**
- name: Build 'Autoware' with CUDA
if: ${{ steps.changed-files.outputs.any_changed == 'true' ||
github.event_name == 'workflow_dispatch' ||
Expand Down
76 changes: 56 additions & 20 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ RUN chmod +x /ros_entrypoint.sh
ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["/bin/bash"]

FROM base AS base-cuda
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Set up CUDA runtime environment and artifacts
# hadolint ignore=SC2002
RUN --mount=type=ssh \
./setup-dev-env.sh -y --module base --download-artifacts --no-cuda-drivers --runtime openadkit \
&& pip uninstall -y ansible ansible-core \
&& apt-get autoremove -y && rm -rf "$HOME"/.cache

# hadolint ignore=DL3006
FROM $BASE_IMAGE AS rosdep-depend

Check warning on line 49 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build-and-push

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG $BASE_IMAGE results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
Expand Down Expand Up @@ -258,6 +268,19 @@ RUN --mount=type=cache,target=${CCACHE_DIR} \
ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["/bin/bash"]

FROM universe-common-devel AS universe-common-devel-cuda
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Set up CUDA development environment
# hadolint ignore=SC2002
RUN --mount=type=ssh \
./setup-dev-env.sh -y --module all --no-cuda-drivers --runtime openadkit \
&& pip uninstall -y ansible ansible-core \
&& apt-get autoremove -y && rm -rf "$HOME"/.cache

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["/bin/bash"]

FROM universe-common-devel AS universe-sensing-perception-devel
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG ROS_DISTRO
Expand Down Expand Up @@ -290,17 +313,18 @@ RUN --mount=type=cache,target=${CCACHE_DIR} \
ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["/bin/bash"]

FROM universe-sensing-perception-devel AS universe-sensing-perception-devel-cuda
FROM universe-common-devel-cuda AS universe-sensing-perception-devel-cuda
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG ROS_DISTRO
ENV CCACHE_DIR="/root/.ccache"

# Set up CUDA development environment
# Install rosdep dependencies
COPY --from=rosdep-universe-sensing-perception-depend /rosdep-universe-sensing-perception-depend-packages.txt /tmp/rosdep-universe-sensing-perception-depend-packages.txt
# hadolint ignore=SC2002
RUN --mount=type=ssh \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
./setup-dev-env.sh -y --module all --no-cuda-drivers openadkit \
&& pip uninstall -y ansible ansible-core \
&& apt-get autoremove -y && rm -rf "$HOME"/.cache
apt-get update \
&& cat /tmp/rosdep-universe-sensing-perception-depend-packages.txt | xargs apt-get install -y --no-install-recommends \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache

# hadolint ignore=SC1091
RUN --mount=type=cache,target=${CCACHE_DIR} \
Expand Down Expand Up @@ -328,6 +352,8 @@ RUN --mount=type=cache,target=${CCACHE_DIR} \
&& du -sh ${CCACHE_DIR} && ccache -s \
&& rm -rf /autoware/build

COPY --from=universe-sensing-perception-devel /opt/autoware /opt/autoware

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["/bin/bash"]

Expand Down Expand Up @@ -474,17 +500,19 @@ RUN --mount=type=cache,target=${CCACHE_DIR} \
ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["/bin/bash"]

FROM universe-devel AS universe-devel-cuda
FROM universe-common-devel-cuda AS universe-devel-cuda
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Set up CUDA development environment
# Install rosdep dependencies
COPY --from=rosdep-universe-depend /rosdep-universe-depend-packages.txt /tmp/rosdep-universe-depend-packages.txt
# hadolint ignore=SC2002
RUN --mount=type=ssh \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
./setup-dev-env.sh -y --module all --no-cuda-drivers openadkit \
&& pip uninstall -y ansible ansible-core \
&& apt-get autoremove -y && rm -rf "$HOME"/.cache
apt-get update \
&& cat /tmp/rosdep-universe-depend-packages.txt | xargs apt-get install -y --no-install-recommends \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache

COPY --from=universe-sensing-perception-devel-cuda /opt/autoware /opt/autoware
COPY --from=universe-devel /opt/autoware /opt/autoware

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["/bin/bash"]
Expand All @@ -508,7 +536,8 @@ RUN --mount=type=ssh \
&& find / -name "*.o" -type f -delete \
&& find / -name "*.h" -type f -delete \
&& find / -name "*.hpp" -type f -delete \
&& rm -rf /root/.local/pipx /opt/ros/"$ROS_DISTRO"/include /etc/apt/sources.list.d/cuda*.list \
&& rm -rf /autoware/ansible /autoware/ansible-galaxy-requirements.yaml /autoware/setup-dev-env.sh /autoware/*.env \
/root/.local/pipx /opt/ros/"$ROS_DISTRO"/include /etc/apt/sources.list.d/cuda*.list \
/etc/apt/sources.list.d/docker.list /etc/apt/sources.list.d/nvidia-docker.list \
/usr/include /usr/share/doc /usr/lib/gcc /usr/lib/jvm /usr/lib/llvm*

Expand All @@ -521,17 +550,20 @@ RUN echo "source /opt/autoware/setup.bash" > /etc/bash.bashrc
ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["/bin/bash"]

FROM universe-sensing-perception AS universe-sensing-perception-cuda
FROM base-cuda AS universe-sensing-perception-cuda
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG ROS_DISTRO
ARG LIB_DIR

# Set up CUDA runtime environment and artifacts
# Set up runtime environment
COPY --from=rosdep-universe-sensing-perception-depend /rosdep-universe-sensing-perception-exec-depend-packages.txt /tmp/rosdep-universe-sensing-perception-exec-depend-packages.txt
# hadolint ignore=SC2002
RUN --mount=type=ssh \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
./setup-dev-env.sh -y --module all --download-artifacts --no-cuda-drivers --runtime openadkit \
./setup-dev-env.sh -y --module all --no-nvidia --no-cuda-drivers --runtime openadkit \
&& pip uninstall -y ansible ansible-core \
&& apt-get update \
&& cat /tmp/rosdep-universe-sensing-perception-exec-depend-packages.txt | xargs apt-get install -y --no-install-recommends \
&& apt-get autoremove -y && rm -rf "$HOME"/.cache \
&& find /usr/lib/$LIB_DIR-linux-gnu -name "*.a" -type f -delete \
&& find / -name "*.o" -type f -delete \
Expand Down Expand Up @@ -665,7 +697,8 @@ RUN --mount=type=ssh \
&& find / -name "*.o" -type f -delete \
&& find / -name "*.h" -type f -delete \
&& find / -name "*.hpp" -type f -delete \
&& rm -rf /root/.local/pipx /opt/ros/"$ROS_DISTRO"/include /etc/apt/sources.list.d/cuda*.list \
&& rm -rf /autoware/ansible /autoware/ansible-galaxy-requirements.yaml /autoware/setup-dev-env.sh /autoware/*.env \
/root/.local/pipx /opt/ros/"$ROS_DISTRO"/include /etc/apt/sources.list.d/cuda*.list \
/etc/apt/sources.list.d/docker.list /etc/apt/sources.list.d/nvidia-docker.list \
/usr/include /usr/share/doc /usr/lib/gcc /usr/lib/jvm /usr/lib/llvm*

Expand All @@ -678,17 +711,20 @@ RUN echo "source /opt/autoware/setup.bash" > /etc/bash.bashrc
ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["/bin/bash"]

FROM universe AS universe-cuda
FROM base-cuda AS universe-cuda
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG ROS_DISTRO
ARG LIB_DIR

# Set up CUDA runtime environment and artifacts
# Set up runtime environment
COPY --from=rosdep-universe-depend /rosdep-exec-depend-packages.txt /tmp/rosdep-exec-depend-packages.txt
# hadolint ignore=SC2002
RUN --mount=type=ssh \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
./setup-dev-env.sh -y --module all --download-artifacts --no-cuda-drivers --runtime openadkit \
./setup-dev-env.sh -y --module all --no-nvidia --no-cuda-drivers --runtime openadkit \
&& pip uninstall -y ansible ansible-core \
&& apt-get update \
&& cat /tmp/rosdep-exec-depend-packages.txt | xargs apt-get install -y --no-install-recommends \
&& apt-get autoremove -y && rm -rf "$HOME"/.cache \
&& find /usr/lib/$LIB_DIR-linux-gnu -name "*.a" -type f -delete \
&& find / -name "*.o" -type f -delete \
Expand Down
Loading

0 comments on commit 21aa069

Please sign in to comment.