Skip to content

Commit

Permalink
feat(docker,ci): split prebuilt stage into autoware-core and autoware…
Browse files Browse the repository at this point in the history
…-universe stages (autowarefoundation#4961)

* add autoware-core stage

Signed-off-by: Yutaka Kondo <[email protected]>

* rename autoware-universe

Signed-off-by: Yutaka Kondo <[email protected]>

* chage copy order

Signed-off-by: Yutaka Kondo <[email protected]>

* run on pr

Signed-off-by: Yutaka Kondo <[email protected]>

* remove --from

Signed-off-by: Yutaka Kondo <[email protected]>

* fix copy

Signed-off-by: Yutaka Kondo <[email protected]>

* update bake

Signed-off-by: Yutaka Kondo <[email protected]>

* revert pr

Signed-off-by: Yutaka Kondo <[email protected]>

* rename to rosdep-depend

Signed-off-by: Yutaka Kondo <[email protected]>

* alphabet order

Signed-off-by: Yutaka Kondo <[email protected]>

---------

Signed-off-by: Yutaka Kondo <[email protected]>
  • Loading branch information
youtalk authored Jul 16, 2024
1 parent 022854b commit 45c3a78
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 29 deletions.
25 changes: 19 additions & 6 deletions .github/actions/docker-build-and-push/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,27 @@ runs:
latest=false
suffix=-base
- name: Docker meta for prebuilt
id: meta-prebuilt
- name: Docker meta for autoware-core
id: meta-autoware-core
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }}
tags: ${{ steps.set-docker-tags.outputs.tags }}
bake-target: docker-metadata-action-prebuilt
bake-target: docker-metadata-action-autoware-core
flavor: |
latest=false
suffix=-prebuilt${{ inputs.tag-suffix }}
suffix=-autoware-core${{ inputs.tag-suffix }}
- name: Docker meta for autoware-universe
id: meta-autoware-universe
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.actor }}/${{ inputs.bake-target }}
tags: ${{ steps.set-docker-tags.outputs.tags }}
bake-target: docker-metadata-action-autoware-universe
flavor: |
latest=false
suffix=-autoware-universe${{ inputs.tag-suffix }}
- name: Docker meta for devel
id: meta-devel
Expand Down Expand Up @@ -161,7 +172,8 @@ runs:
files: |
docker/docker-bake.hcl
${{ steps.meta-base.outputs.bake-file }}
${{ steps.meta-prebuilt.outputs.bake-file }}
${{ steps.meta-autoware-core.outputs.bake-file }}
${{ steps.meta-autoware-universe.outputs.bake-file }}
${{ steps.meta-devel.outputs.bake-file }}
${{ steps.meta-runtime.outputs.bake-file }}
provenance: false
Expand All @@ -176,7 +188,8 @@ runs:
files: |
docker/docker-bake.hcl
${{ steps.meta-base.outputs.bake-file }}
${{ steps.meta-prebuilt.outputs.bake-file }}
${{ steps.meta-autoware-core.outputs.bake-file }}
${{ steps.meta-autoware-universe.outputs.bake-file }}
${{ steps.meta-devel.outputs.bake-file }}
${{ steps.meta-runtime.outputs.bake-file }}
provenance: false
Expand Down
72 changes: 54 additions & 18 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ RUN --mount=type=ssh \
# Create entrypoint
CMD ["/bin/bash"]

FROM $BASE_IMAGE as src-imported
FROM $BASE_IMAGE as rosdep-depend
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG ROS_DISTRO

# Copy files
COPY setup-dev-env.sh ansible-galaxy-requirements.yaml amd64.env arm64.env /autoware/
COPY ansible/ /autoware/ansible/
WORKDIR /autoware
Expand All @@ -52,17 +51,28 @@ RUN --mount=type=ssh \
&& pip uninstall -y ansible ansible-core \
&& apt-get autoremove -y && rm -rf "$HOME"/.cache

# Copy repository files
COPY src /autoware/src

# Generate install package lists
COPY src/core /autoware/src/core
RUN rosdep update && rosdep keys --ignore-src --from-paths src \
| xargs rosdep resolve --rosdistro ${ROS_DISTRO} \
| grep -v '^#' \
| sed 's/ \+/\n/g'\
| sort \
> /rosdep-all-depend-packages.txt \
&& cat /rosdep-all-depend-packages.txt
> /rosdep-core-depend-packages.txt \
&& cat /rosdep-core-depend-packages.txt
COPY src/launcher /autoware/src/launcher
COPY src/param /autoware/src/param
COPY src/sensor_component /autoware/src/sensor_component
COPY src/sensor_kit /autoware/src/sensor_kit
COPY src/universe /autoware/src/universe
COPY src/vehicle /autoware/src/vehicle
RUN rosdep keys --ignore-src --from-paths src \
| xargs rosdep resolve --rosdistro ${ROS_DISTRO} \
| grep -v '^#' \
| sed 's/ \+/\n/g'\
| sort \
> /rosdep-universe-depend-packages.txt \
&& cat /rosdep-universe-depend-packages.txt
RUN rosdep keys --dependency-types=exec --ignore-src --from-paths src \
| xargs rosdep resolve --rosdistro ${ROS_DISTRO} \
| grep -v '^#' \
Expand All @@ -71,7 +81,7 @@ RUN rosdep keys --dependency-types=exec --ignore-src --from-paths src \
> /rosdep-exec-depend-packages.txt \
&& cat /rosdep-exec-depend-packages.txt

FROM base as prebuilt
FROM base as autoware-core
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG ROS_DISTRO
ARG SETUP_ARGS
Expand All @@ -87,30 +97,57 @@ RUN --mount=type=ssh \
&& apt-get autoremove -y && rm -rf "$HOME"/.cache

# Install rosdep dependencies
COPY --from=src-imported /rosdep-all-depend-packages.txt /tmp/rosdep-all-depend-packages.txt
COPY --from=rosdep-depend /rosdep-core-depend-packages.txt /tmp/rosdep-core-depend-packages.txt
# hadolint ignore=SC2002
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& cat /tmp/rosdep-all-depend-packages.txt | xargs apt-get install -y --no-install-recommends \
&& cat /tmp/rosdep-core-depend-packages.txt | xargs apt-get install -y --no-install-recommends \
&& apt-get autoremove -y && rm -rf "$HOME"/.cache

# Build Autoware
COPY --from=src-imported /autoware/src /autoware/src
COPY src/core /autoware/src/core
RUN --mount=type=cache,target=${CCACHE_DIR} \
source /opt/ros/"$ROS_DISTRO"/setup.bash \
&& du -sh ${CCACHE_DIR} && ccache -s \
&& colcon build --cmake-args \
" -Wno-dev" \
" --no-warn-unused-cli" \
--mixin release compile-commands ccache \
&& du -sh ${CCACHE_DIR} && ccache -s

FROM autoware-core as autoware-universe
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG ROS_DISTRO
ARG SETUP_ARGS
ENV CCACHE_DIR="/root/.ccache"

# Install rosdep dependencies
COPY --from=rosdep-depend /rosdep-universe-depend-packages.txt /tmp/rosdep-universe-depend-packages.txt
# hadolint ignore=SC2002
RUN --mount=type=ssh \
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

# Build Autoware
COPY src/launcher /autoware/src/launcher
COPY src/param /autoware/src/param
COPY src/sensor_component /autoware/src/sensor_component
COPY src/sensor_kit /autoware/src/sensor_kit
COPY src/universe /autoware/src/universe
COPY src/vehicle /autoware/src/vehicle
RUN --mount=type=cache,target=${CCACHE_DIR} \
source /opt/ros/"$ROS_DISTRO"/setup.bash \
&& du -sh ${CCACHE_DIR} && ccache -s \
&& find /autoware/install -type d -exec chmod 777 {} \; \
&& rm -rf /autoware/build /autoware/src
&& colcon build --cmake-args \
" -Wno-dev" \
" --no-warn-unused-cli" \
--mixin release compile-commands ccache \
&& du -sh ${CCACHE_DIR} && ccache -s

CMD ["/bin/bash"]

FROM prebuilt as devel
FROM autoware-universe as devel
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Install development tools and artifacts
Expand All @@ -134,7 +171,7 @@ ARG LIB_DIR
ARG SETUP_ARGS

# Set up runtime environment and artifacts
COPY --from=src-imported /rosdep-exec-depend-packages.txt /tmp/rosdep-exec-depend-packages.txt
COPY --from=rosdep-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 \
Expand All @@ -153,8 +190,7 @@ RUN --mount=type=ssh \
/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*

# Copy prebuilt binaries
COPY --from=prebuilt /autoware/install/ /autoware/install/
COPY --from=autoware-universe /autoware/install/ /autoware/install/

# Copy bash aliases
COPY docker/etc/.bash_aliases /root/.bash_aliases
Expand Down
17 changes: 12 additions & 5 deletions docker/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
group "default" {
targets = ["base", "prebuilt", "devel", "runtime"]
targets = ["base", "autoware-core", "autoware-universe", "devel", "runtime"]
}

// For docker/metadata-action
target "docker-metadata-action-base" {}
target "docker-metadata-action-prebuilt" {}
target "docker-metadata-action-autoware-core" {}
target "docker-metadata-action-autoware-universe" {}
target "docker-metadata-action-devel" {}
target "docker-metadata-action-runtime" {}

Expand All @@ -14,10 +15,16 @@ target "base" {
target = "base"
}

target "prebuilt" {
inherits = ["docker-metadata-action-prebuilt"]
target "autoware-core" {
inherits = ["docker-metadata-action-autoware-core"]
dockerfile = "docker/Dockerfile"
target = "prebuilt"
target = "autoware-core"
}

target "autoware-universe" {
inherits = ["docker-metadata-action-autoware-universe"]
dockerfile = "docker/Dockerfile"
target = "autoware-universe"
}

target "devel" {
Expand Down

0 comments on commit 45c3a78

Please sign in to comment.