Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker): install CUDA development/runtime libraries only 1 time #5419

Merged
merged 7 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
mitsudome-r marked this conversation as resolved.
Show resolved Hide resolved
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
@@ -1,7 +1,7 @@
ARG BASE_IMAGE

# hadolint ignore=DL3006
FROM $BASE_IMAGE AS base

Check warning on line 4 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/

Check warning on line 4 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build-and-push-cuda

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/

Check warning on line 4 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build

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"]
ARG ROS_DISTRO

Expand Down Expand Up @@ -35,8 +35,18 @@
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/

Check warning on line 49 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build-and-push-cuda

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/

Check warning on line 49 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build

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"]
ARG ROS_DISTRO

Expand Down Expand Up @@ -258,6 +268,19 @@
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 @@
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 @@
&& 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 @@
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 @@
&& 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 @@
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 @@
&& 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 @@
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
Loading