Skip to content

Commit

Permalink
feat(docker): introduce autoware-base images (#140)
Browse files Browse the repository at this point in the history
* add base image workflow

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

* MUST REVERT

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

* rename

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

* rename

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

* fix with

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

* change run

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

* fix hcl

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

* add platform

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

* fix description

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

* remove checkout

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

* Revert "MUST REVERT"

This reverts commit bb9f18a.

* remove entrypoint

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

* remove entrypoint

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

---------

Signed-off-by: Yutaka Kondo <[email protected]>
  • Loading branch information
youtalk authored Nov 25, 2024
1 parent ae4c496 commit d338b36
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 1 deletion.
63 changes: 63 additions & 0 deletions .github/actions/docker-build-and-push-base/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: docker-build-and-push-base
description: Composite action to build and push base images to registry.

inputs:
target-image:
description: Target docker image name in the registry.
required: true
build-args:
description: Additional build args.
required: false

runs:
using: composite
steps:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Get current date
id: date
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
shell: bash

- name: Docker meta for autoware-base:latest
id: meta-base
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.target-image }}
tags: |
type=raw,value=${{ steps.date.outputs.date }}
bake-target: docker-metadata-action-base
flavor: |
latest=true
- name: Docker meta for autoware-base:cuda-latest
id: meta-base-cuda
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.target-image }}
tags: |
type=raw,value=cuda-latest
type=raw,value=cuda-${{ steps.date.outputs.date }}
bake-target: docker-metadata-action-base-cuda
flavor: |
latest=false
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and Push to GitHub Container Registry
uses: docker/bake-action@v5
with:
push: true
files: |
docker/docker-bake-base.hcl
${{ steps.meta-base.outputs.bake-file }}
${{ steps.meta-base-cuda.outputs.bake-file }}
provenance: false
set: |
${{ inputs.build-args }}
31 changes: 31 additions & 0 deletions .github/workflows/autoware-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: autoware-base

on:
push:
branches:
- main
tags:
workflow_dispatch:

jobs:
load-env:
uses: ./.github/workflows/load-env.yaml

docker-build-and-push-base:
needs: load-env
runs-on: buildjet-16vcpu-ubuntu-2204
steps:
- name: Check out this repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Build Autoware's base images
uses: ./.github/actions/docker-build-and-push-base
with:
target-image: autoware-base
build-args: |
*.platform=linux/amd64,linux/arm64
*.args.ROS_DISTRO=${{ needs.load-env.outputs.rosdistro }}
*.args.BASE_IMAGE=${{ needs.load-env.outputs.base_image }}
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ RUN --mount=type=ssh \
# Create entrypoint
COPY docker/etc/ros_entrypoint.sh /ros_entrypoint.sh
RUN chmod +x /ros_entrypoint.sh
ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["/bin/bash"]

FROM base AS base-cuda
Expand Down
47 changes: 47 additions & 0 deletions docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ARG BASE_IMAGE

# hadolint ignore=DL3006
FROM $BASE_IMAGE AS base
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/
COPY docker/scripts/cleanup_apt.sh /autoware/cleanup_apt.sh
RUN chmod +x /autoware/cleanup_apt.sh
WORKDIR /autoware

# Install apt packages and add GitHub to known hosts for private repositories
RUN rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
gosu \
ssh \
&& /autoware/cleanup_apt.sh \
&& mkdir -p ~/.ssh \
&& ssh-keyscan github.com >> ~/.ssh/known_hosts

# Set up base environment
RUN --mount=type=ssh \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
./setup-dev-env.sh -y --module base --no-nvidia --no-cuda-drivers --runtime openadkit \
&& pip uninstall -y ansible ansible-core \
&& /autoware/cleanup_apt.sh \
&& echo "source /opt/ros/${ROS_DISTRO}/setup.bash" > /etc/bash.bashrc

# Create entrypoint
COPY docker/etc/ros_entrypoint.sh /ros_entrypoint.sh
RUN chmod +x /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 \
&& /autoware/cleanup_apt.sh true
22 changes: 22 additions & 0 deletions docker/docker-bake-base.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
group "default" {
targets = [
"base",
"base-cuda"
]
}

// For docker/metadata-action
target "docker-metadata-action-base" {}
target "docker-metadata-action-base-cuda" {}

target "base" {
inherits = ["docker-metadata-action-base"]
dockerfile = "docker/Dockerfile.base"
target = "base"
}

target "base-cuda" {
inherits = ["docker-metadata-action-base-cuda"]
dockerfile = "docker/Dockerfile.base"
target = "base-cuda"
}

0 comments on commit d338b36

Please sign in to comment.