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): introduce autoware-base images #5476

Merged
merged 16 commits into from
Nov 25, 2024
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
youtalk marked this conversation as resolved.
Show resolved Hide resolved
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 }}
29 changes: 29 additions & 0 deletions .github/workflows/autoware-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: autoware-base

on:
schedule:
- cron: 0 0 15 * * # every 15th of the month
workflow_dispatch:

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

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

- name: Set up QEMU
mitsudome-r marked this conversation as resolved.
Show resolved Hide resolved
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 }}
48 changes: 48 additions & 0 deletions docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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
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 \
&& /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"
}
Loading