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

Support arm64 in cpubuilder dockerfile using multi-arch builds. #11

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Publish cpubuilder x86_64 images
name: Publish cpubuilder images
on:
workflow_dispatch:
push:
branches: ['main']
paths:
- dockerfiles/cpubuilder*_x86_64.Dockerfile
- .github/workflows/publish_cpubuilder_x86_64.yml
- dockerfiles/cpubuilder*.Dockerfile
- .github/workflows/publish_cpubuilder.yml

jobs:
build-cpubuilder-ubuntu-jammy:
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
IMAGE_NAME: iree-org/cpubuilder_ubuntu_jammy_x86_64
IMAGE_NAME: iree-org/cpubuilder_ubuntu_jammy
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
Expand All @@ -38,7 +38,8 @@ jobs:
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: dockerfiles/cpubuilder_ubuntu_jammy_x86_64.Dockerfile
file: dockerfiles/cpubuilder_ubuntu_jammy.Dockerfile
platforms: linux/amd64,linux/arm64
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/iree-org/base-docker-images/actions/runs/10949036140/job/30401394373#step:5:135

 ERROR: Multi-platform build is not supported for the docker driver.
Switch to a different driver, or turn on the containerd image store, and try again.
Learn more at https://docs.docker.com/go/build-multi-platform/
Error: buildx failed with: Learn more at https://docs.docker.com/go/build-multi-platform/

Aww... I hit the same error locally while developing. The recommended steps in those docs worked for me, but I need to see what the docker/build-push-action needs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, successful build and push. The workflow run time went up from 2 minutes to 20 minutes, in large part due to the ccache build from source.

Before: https://github.com/iree-org/base-docker-images/actions/runs/10948990985
After: https://github.com/iree-org/base-docker-images/actions/runs/10949139831

New package: https://github.com/iree-org/base-docker-images/pkgs/container/cpubuilder_ubuntu_jammy

push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand All @@ -47,7 +48,7 @@ jobs:
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
IMAGE_NAME: iree-org/cpubuilder_ubuntu_jammy_ghr_x86_64
IMAGE_NAME: iree-org/cpubuilder_ubuntu_jammy_ghr
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
Expand All @@ -73,7 +74,8 @@ jobs:
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: dockerfiles/cpubuilder_ubuntu_jammy_ghr_x86_64.Dockerfile
file: dockerfiles/cpubuilder_ubuntu_jammy_ghr.Dockerfile
platforms: linux/amd64,linux/arm64
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm expecting these multi-arch/platform builds to show up in github packages like so: https://github.com/myoung34/docker-github-actions-runner/pkgs/container/docker-github-actions-runner/275948281?tag=ubuntu-jammy

image

push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Image name | Description | Source Dockerfile
---------- | ----------- | -----------------
`iree-org/amdgpu_ubuntu_jammy_x86_64` | Ubuntu with AMDGPU deps | [Source](./dockerfiles/amdgpu_ubuntu_jammy_x86_64.Dockerfile)
`iree-org/amdgpu_ubuntu_jammy_ghr_x86_64` | Ubuntu with AMDGPU deps (GitHub runner) | [Source](./dockerfiles/amdgpu_ubuntu_jammy_ghr_x86_64.Dockerfile)
`iree-org/cpubuilder_ubuntu_jammy_x86_64` | CPU builder with IREE build deps | [Source](./dockerfiles/cpubuilder_ubuntu_jammy_x86_64.Dockerfile)
`iree-org/cpubuilder_ubuntu_jammy_ghr_x86_64` | CPU builder with IREE build deps (GitHub runner) | [Source](./dockerfiles/cpubuilder_ubuntu_jammy_ghr_x86_64.Dockerfile)
`iree-org/cpubuilder_ubuntu_jammy` | CPU builder with IREE build deps | [Source](./dockerfiles/cpubuilder_ubuntu_jammy.Dockerfile)
`iree-org/cpubuilder_ubuntu_jammy_ghr` | CPU builder with IREE build deps (GitHub runner) | [Source](./dockerfiles/cpubuilder_ubuntu_jammy_ghr.Dockerfile)
`iree-org/manylinux_x86_64` | Portable Linux release builder for Python packaging | [Source](./dockerfiles/manylinux_x86_64.Dockerfile)
`iree-org/manylinux_ghr_x86_64` | Portable Linux release builder for Python packaging (GitHub runner) | [Source](./dockerfiles/manylinux_ghr_x86_64.Dockerfile)

Expand Down Expand Up @@ -49,6 +49,39 @@ You can also
to avoid needing to copy the SHA each time:

```bash
sudo docker buildx build --file dockerfiles/cpubuilder_ubuntu_jammy_x86_64.Dockerfile . --tag cpubuilder:latest
sudo docker buildx build --file dockerfiles/cpubuilder_ubuntu_jammy.Dockerfile . --tag cpubuilder:latest
sudo docker run --rm --mount type=bind,source="$(realpath ~/iree)",target=/iree -it --entrypoint bash cpubuilder:latest
```

## Multi-arch and multi-platform builds

We publish images for multiple architectures, e.g. amd64 and arm64. See
the documentation for multi-arch and multi-platform builds here:

* https://www.docker.com/blog/multi-arch-build-and-images-the-simple-way/
* https://docs.docker.com/build/building/multi-platform/
* https://docs.docker.com/build/ci/github-actions/multi-platform/

To build and use a multi-architecture image, pass `--platform`:

```bash
sudo docker buildx build --file dockerfiles/cpubuilder_ubuntu_jammy.Dockerfile --platform=linux/arm64,linux/amd64 . --tag cpubuilder:latest
```

* To run a multiplatform image on your host architecture, no changes are needed:

```bash
sudo docker run --rm -it --entrypoint bash cpubuilder:latest

root:/$ uname -m
x86_64
```

* To run a multiplatform image on a different architecture, pass `--platform`:

```bash
sudo docker run --rm -it --entrypoint bash --platform=linux/arm64 cpubuilder:latest

root:/$ uname -m
aarch64
```
19 changes: 14 additions & 5 deletions build_tools/install_ccache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ CCACHE_VERSION="$1"

ARCH="$(uname -m)"

curl --silent --fail --show-error --location \
"https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}-linux-${ARCH}.tar.xz" \
--output ccache.tar.xz
if [[ "${ARCH}" == "x86_64" ]]; then
curl --silent --fail --show-error --location \
"https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}-linux-${ARCH}.tar.xz" \
--output ccache.tar.xz

tar xf ccache.tar.xz
cp ccache-${CCACHE_VERSION}-linux-${ARCH}/ccache /usr/local/bin
tar xf ccache.tar.xz
cp ccache-${CCACHE_VERSION}-linux-${ARCH}/ccache /usr/local/bin
elif [[ "${ARCH}" == "aarch64" ]]; then
# Latest version of ccache is not released for arm64, built it
git clone --depth 1 --branch "v${CCACHE_VERSION}" https://github.com/ccache/ccache.git
mkdir -p ccache/build && cd "$_"
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release ..
ninja
cp ccache /usr/bin/
fi
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Stock Ubuntu Jammy (22.04) with IREE build dependencies.
FROM ubuntu:jammy

ARG TARGETARCH
ARG TARGETPLATFORM

######## Apt packages ########
RUN apt update && \
apt install -y wget git unzip curl gnupg2 lsb-release
Expand All @@ -26,16 +29,6 @@ RUN apt update && \
# Cleanup.
RUN apt clean && rm -rf /var/lib/apt/lists/*

######## CCache ########
WORKDIR /install-ccache
COPY build_tools/install_ccache.sh ./
RUN ./install_ccache.sh "4.10.2" && rm -rf /install-ccache

######## sccache ########
WORKDIR /install-sccache
COPY build_tools/install_sccache.sh ./
RUN ./install_sccache.sh "0.8.1" && rm -rf /install-sccache

######## CMake ########
WORKDIR /install-cmake
ENV CMAKE_VERSION="3.23.2"
Expand All @@ -52,4 +45,14 @@ RUN ln -s /usr/bin/lld-14 /usr/bin/lld && \
ENV CC=clang
ENV CXX=clang++

######## CCache ########
WORKDIR /install-ccache
COPY build_tools/install_ccache.sh ./
RUN ./install_ccache.sh "4.10.2" && rm -rf /install-ccache

######## sccache ########
WORKDIR /install-sccache
COPY build_tools/install_sccache.sh ./
RUN ./install_sccache.sh "0.8.1" && rm -rf /install-sccache

WORKDIR /
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# GitHub Actions Runner with IREE build deps.
FROM docker.io/myoung34/github-runner:ubuntu-jammy

ARG TARGETARCH
ARG TARGETPLATFORM

######## Apt packages ########
RUN apt update && \
apt install -y wget git unzip curl gnupg2 lsb-release
Expand All @@ -26,16 +29,6 @@ RUN apt update && \
# Cleanup.
RUN apt clean && rm -rf /var/lib/apt/lists/*

######## CCache ########
WORKDIR /install-ccache
COPY build_tools/install_ccache.sh ./
RUN ./install_ccache.sh "4.10.2" && rm -rf /install-ccache

######## sccache ########
WORKDIR /install-sccache
COPY build_tools/install_sccache.sh ./
RUN ./install_sccache.sh "0.8.1" && rm -rf /install-sccache

######## CMake ########
WORKDIR /install-cmake
ENV CMAKE_VERSION="3.23.2"
Expand All @@ -52,5 +45,15 @@ RUN ln -s /usr/bin/lld-14 /usr/bin/lld && \
ENV CC=clang
ENV CXX=clang++

######## CCache ########
WORKDIR /install-ccache
COPY build_tools/install_ccache.sh ./
RUN ./install_ccache.sh "4.10.2" && rm -rf /install-ccache

######## sccache ########
WORKDIR /install-sccache
COPY build_tools/install_sccache.sh ./
RUN ./install_sccache.sh "0.8.1" && rm -rf /install-sccache

# Switch back to the working directory upstream expects.
WORKDIR /actions-runner