diff --git a/.github/actions/docker-build-and-push-base/action.yaml b/.github/actions/docker-build-and-push-base/action.yaml new file mode 100644 index 0000000000..8a5a779904 --- /dev/null +++ b/.github/actions/docker-build-and-push-base/action.yaml @@ -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 }} diff --git a/.github/workflows/autoware-base.yaml b/.github/workflows/autoware-base.yaml new file mode 100644 index 0000000000..c4a3f2a89a --- /dev/null +++ b/.github/workflows/autoware-base.yaml @@ -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 }} diff --git a/docker/Dockerfile b/docker/Dockerfile index 2a9047076c..8a82503b6d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base new file mode 100644 index 0000000000..dca6fb8a0f --- /dev/null +++ b/docker/Dockerfile.base @@ -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 diff --git a/docker/docker-bake-base.hcl b/docker/docker-bake-base.hcl new file mode 100644 index 0000000000..43cb7facc0 --- /dev/null +++ b/docker/docker-bake-base.hcl @@ -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" +}