Skip to content

Commit

Permalink
update dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
  • Loading branch information
isamu-takagi committed Apr 24, 2024
1 parent 02bbbd0 commit 8b9ee70
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 74 deletions.
52 changes: 7 additions & 45 deletions .github/actions/docker-build-and-push/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,57 +27,20 @@ runs:
sudo apt-get -y install jq
shell: bash

# workflow_dispatch: latest, date
# schedule: latest, date
# tag: semver
- name: Set Docker tags
id: set-docker-tags
run: |
tags=()
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
tags+=("latest")
tags+=("{{date 'YYYYMMDD'}}")
else
tags+=("type=schedule,pattern=latest")
tags+=("type=schedule,pattern={{date 'YYYYMMDD'}}")
tags+=("type=semver,pattern={{version}}")
tags+=("type=match,pattern=\d+.\d+")
fi
# Workaround for multiline strings
# https://git.luolix.topmunity/t/set-output-truncates-multiline-strings/16852
tags_multiline=$(printf "%s\n" "${tags[@]}")
tags_multiline="${tags_multiline//'%'/'%25'}"
tags_multiline="${tags_multiline//$'\n'/'%0A'}"
tags_multiline="${tags_multiline//$'\r'/'%0D'}"
echo ::set-output name=tags::$tags_multiline
shell: bash

- name: Docker meta for devel
id: meta-devel
- name: Docker meta for runtime
id: meta-runtime
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }}
tags: ${{ steps.set-docker-tags.outputs.tags }}
bake-target: docker-metadata-action-devel
tags: |
type=raw,value=latest
type=raw,value={{date 'YYYYMMDD'}}
bake-target: docker-metadata-action-runtime
flavor: |
latest=false
prefix=${{ inputs.tag-prefix }}
suffix=${{ inputs.tag-suffix }}
- name: Docker meta for prebuilt
id: meta-prebuilt
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }}
tags: ${{ steps.set-docker-tags.outputs.tags }}
bake-target: docker-metadata-action-prebuilt
flavor: |
latest=false
prefix=${{ inputs.tag-prefix }}
suffix=-prebuilt${{ inputs.tag-suffix }}
- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v2
Expand All @@ -93,7 +56,6 @@ runs:
push: ${{ github.event_name == 'schedule' || github.ref_name == github.event.repository.default_branch || github.event_name == 'push'}}
files: |
docker/${{ inputs.bake-target }}/docker-bake.hcl
${{ steps.meta-devel.outputs.bake-file }}
${{ steps.meta-prebuilt.outputs.bake-file }}
${{ steps.meta-runtime.outputs.bake-file }}
set: |
${{ inputs.build-args }}
6 changes: 2 additions & 4 deletions .github/workflows/docker-build-and-push-main.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: docker-build-and-push-main

on:
schedule:
- cron: 0 0 1,15 * *
workflow_dispatch:

jobs:
Expand All @@ -12,9 +10,9 @@ jobs:
fail-fast: false
matrix:
name:
- no-cuda
- no-nvidia
include:
- name: no-cuda
- name: no-nvidia
base_image_env: base_image
setup-args: --no-nvidia
additional-tag-suffix: ""
Expand Down
22 changes: 15 additions & 7 deletions docker/autoware-universe/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# hadolint global ignore=DL3006,DL3008
ARG BASE_IMAGE

# ==============================================================================
FROM $BASE_IMAGE as devel
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG ROS_DISTRO
Expand All @@ -23,7 +24,7 @@ WORKDIR /autoware

# Set up development environment
RUN --mount=type=ssh \
./setup-dev-env.sh -y $SETUP_ARGS universe \
./setup-dev-env.sh -y --runtime $SETUP_ARGS universe \
&& pip uninstall -y ansible ansible-core \
&& mkdir src \
&& vcs import src < autoware.repos \
Expand All @@ -48,18 +49,25 @@ RUN mkdir -p /etc/OpenCL/vendors \
&& echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd \
&& chmod 644 /etc/OpenCL/vendors/nvidia.icd

# Create entrypoint
RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" > /etc/bash.bashrc
CMD ["/bin/bash"]

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

# Build and change permission for runtime data conversion
RUN source /opt/ros/"$ROS_DISTRO"/setup.bash \
&& colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release \
&& find /autoware/install -type d -exec chmod 777 {} \; \
&& rm -rf /autoware/build /autoware/src
&& find /autoware/install -type d -exec chmod 777 {} \;

# Create entrypoint
RUN echo "source /autoware/install/setup.bash" > /etc/bash.bashrc
CMD ["/bin/bash"]

# ==============================================================================
FROM devel as runtime

# Remove setup files and copy install directory
RUN rm -rf /autoware/*
COPY --from=prebuilt /autoware/install/ /autoware/install/

# Create entrypoint
RUN echo "source /autoware/install/setup.bash" > /etc/bash.bashrc
Expand Down
12 changes: 10 additions & 2 deletions docker/autoware-universe/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
group "default" {
targets = ["devel", "prebuilt"]
targets = ["devel", "prebuilt", "runtime"]
}

// For docker/metadata-action
target "docker-metadata-action-devel" {}
target "docker-metadata-action-prebuilt" {}
target "docker-metadata-action-runtime" {}

// For source image
target "devel" {
Expand All @@ -13,9 +14,16 @@ target "devel" {
target = "devel"
}

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

// For runtime image
target "runtime" {
inherits = ["docker-metadata-action-runtime"]
dockerfile = "docker/autoware-universe/Dockerfile"
target = "runtime"
}
21 changes: 5 additions & 16 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ WORKSPACE_ROOT="$SCRIPT_DIR/../"
args=()
while [ "$1" != "" ]; do
case "$1" in
--no-cuda)
option_no_cuda=true
--no-nvidia)
option_no_nvidia=true
;;
--platform)
option_platform="$2"
shift
;;
--no-prebuilt)
option_no_prebuilt=true
;;
*)
args+=("$1")
;;
Expand All @@ -27,22 +24,14 @@ while [ "$1" != "" ]; do
done

# Set CUDA options
if [ "$option_no_cuda" = "true" ]; then
if [ "$option_no_nvidia" = "true" ]; then
setup_args="--no-nvidia"
image_name_suffix=""
else
setup_args="--no-cuda-drivers"
image_name_suffix="-cuda"
fi

# Set prebuilt options
if [ "$option_no_prebuilt" = "true" ]; then
targets=("devel")
else
# default targets include devel and prebuilt
targets=()
fi

# Set platform
if [ -n "$option_platform" ]; then
platform="$option_platform"
Expand Down Expand Up @@ -70,7 +59,7 @@ docker buildx bake --no-cache --load --progress=plain -f "$SCRIPT_DIR/autoware-u
--set "*.args.ROS_DISTRO=$rosdistro" \
--set "*.args.BASE_IMAGE=$base_image" \
--set "*.args.SETUP_ARGS=$setup_args" \
--set "devel.tags=ghcr.io/automotiveaichallenge/autoware-universe:$rosdistro-latest$image_name_suffix" \
--set "devel.tags=ghcr.io/automotiveaichallenge/autoware-universe:$rosdistro-latest-devel$image_name_suffix" \

Check warning on line 62 in docker/build.sh

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (automotiveaichallenge)
--set "prebuilt.tags=ghcr.io/automotiveaichallenge/autoware-universe:$rosdistro-latest-prebuilt$image_name_suffix" \

Check warning on line 63 in docker/build.sh

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (automotiveaichallenge)
"${targets[@]}"
--set "runtime.tags=ghcr.io/automotiveaichallenge/autoware-universe:$rosdistro-latest-runtime$image_name_suffix"

Check warning on line 64 in docker/build.sh

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (automotiveaichallenge)
set +x

0 comments on commit 8b9ee70

Please sign in to comment.