Skip to content

Commit

Permalink
add base image workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Yutaka Kondo <[email protected]>
  • Loading branch information
youtalk committed Nov 22, 2024
1 parent ae4c496 commit 07265c7
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
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:latest-cuda
id: meta-base-cuda
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.target-image }}
tags: |
type=raw,value=latest-cuda
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.hcl
${{ steps.meta-base.outputs.bake-file }}
${{ steps.meta-base-cuda.outputs.bake-file }}
provenance: false
set: |
${{ inputs.build-args }}
38 changes: 38 additions & 0 deletions .github/workflows/autoware-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: autoware-base

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

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

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

- name: Check out autowarefoundation/autoware repository
uses: actions/checkout@v4
with:
repository: autowarefoundation/autoware
path: 'autoware'

- 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:
name: autoware-base
target-image: docker-bake-base.hcl
build-args: |
*.args.ROS_DISTRO=${{ needs.load-env.outputs.rosdistro }}
*.args.BASE_IMAGE=${{ needs.load-env.outputs.base_image }}
tag-prefix: ${{ needs.load-env.outputs.rosdistro }}
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"
}

0 comments on commit 07265c7

Please sign in to comment.