Skip to content

workflows: Rewrite build-ci-container to work on larger runners #117353

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

Merged
merged 20 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
105 changes: 40 additions & 65 deletions .github/workflows/build-ci-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,95 +18,70 @@ on:
- '.github/workflows/containers/github-action-ci/**'

jobs:
# TODO(boomanaiden154): Switch this back to a single stage build when we can
# run this on the self-hosted runners and don't have to do it this way to
# avoid timeouts.
build-ci-container-stage1:
build-ci-container:
if: github.repository_owner == 'llvm'
runs-on: ubuntu-latest
runs-on: depot-ubuntu-24.04-16
outputs:
container-name: ${{ steps.vars.outputs.container-name }}
container-name-tag: ${{ steps.vars.outputs.container-name-tag }}
container-filename: ${{ steps.vars.outputs.container-filename }}
steps:
- name: Checkout LLVM
uses: actions/checkout@v4
with:
sparse-checkout: .github/workflows/containers/github-action-ci/
- name: Change podman Root Direcotry
run: |
mkdir -p ~/.config/containers
sudo mkdir -p /mnt/podman
sudo chown `whoami`:`whoami` /mnt/podman
cp ./.github/workflows/containers/github-action-ci/storage.conf ~/.config/containers/storage.conf
podman info
- name: Build container stage1
working-directory: ./.github/workflows/containers/github-action-ci/
run: |
podman build -t stage1-toolchain --target stage1-toolchain -f stage1.Dockerfile .
- name: Save container image
run: |
podman save stage1-toolchain > stage1-toolchain.tar
- name: Upload container image
uses: actions/upload-artifact@v4
with:
name: stage1-toolchain
path: stage1-toolchain.tar
retention-days: 1
build-ci-container-stage2:
if: github.repository_owner == 'llvm'
runs-on: ubuntu-latest
needs: build-ci-container-stage1
permissions:
packages: write
steps:
- name: Write Variables
id: vars
run: |
tag=`date +%s`
container_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/ci-ubuntu-22.04"
echo "container-name=$container_name" >> $GITHUB_OUTPUT
echo "container-name-tag=$container_name:$tag" >> $GITHUB_OUTPUT

- name: Checkout LLVM
uses: actions/checkout@v4
with:
sparse-checkout: .github/workflows/containers/github-action-ci/

- name: Change podman Root Direcotry
echo "container-filename=$(echo $container_name:$tag | sed -e 's/\//-/g' -e 's/:/-/g').tar" >> $GITHUB_OUTPUT
- name: Build container
working-directory: ./.github/workflows/containers/github-action-ci/
run: |
mkdir -p ~/.config/containers
sudo mkdir -p /mnt/podman
sudo chown `whoami`:`whoami` /mnt/podman
cp ./.github/workflows/containers/github-action-ci/storage.conf ~/.config/containers/storage.conf
podman info
podman build -t ${{ steps.vars.outputs.container-name-tag }} -f stage1.Dockerfile .

# Download the container image into /mnt/podman rather than
# $GITHUB_WORKSPACE to avoid space limitations on the default drive
# and use the permissions setup for /mnt/podman.
- name: Download stage1-toolchain
uses: actions/download-artifact@v4
with:
name: stage1-toolchain
path: /mnt/podman

- name: Load stage1-toolchain
- name: Save container image
run: |
podman load -i /mnt/podman/stage1-toolchain.tar
podman save ${{ steps.vars.outputs.container-name-tag }} > ${{ steps.vars.outputs.container-filename }}

- name: Build Container
working-directory: ./.github/workflows/containers/github-action-ci/
run: |
podman build -t ${{ steps.vars.outputs.container-name-tag }} -f stage2.Dockerfile .
podman tag ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name }}:latest
# Upload the container so we have it in case the push fails. This also
# allows us to separate the push step into a separate job so we can
# maintain minimal permissions while building the container.
- name: Upload container image
uses: actions/upload-artifact@v4
with:
name: container
path: ${{ steps.vars.outputs.container-filename }}
retention-days: 14

- name: Test Container
run: |
for image in ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name }}; do
podman run --rm -it $image /usr/bin/bash -x -c 'printf '\''#include <iostream>\nint main(int argc, char **argv) { std::cout << "Hello\\n"; }'\'' | clang++ -x c++ - && ./a.out | grep Hello'
done

push-ci-container:
if: github.event_name == 'push'
needs:
- build-ci-container
permissions:
packages: write
runs-on: ubuntu-24.04
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Download container
uses: actions/download-artifact@v4
with:
name: container

- name: Push Container
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
podman load -i ${{ needs.build-ci-container.outptus.container-filename }}
podman tag ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name }}:latest
podman login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io
podman push ${{ steps.vars.outputs.container-name-tag }}
podman push ${{ steps.vars.outputs.container-name }}:latest
podman push ${{ needs.build-ci-container.outputs.container-name-tag }}
podman push ${{ needs.build-ci-container.outputs.container-name }}:latest
13 changes: 0 additions & 13 deletions .github/workflows/containers/github-action-ci/bootstrap.patch

This file was deleted.

38 changes: 29 additions & 9 deletions .github/workflows/containers/github-action-ci/stage1.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ RUN curl -O -L https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-$L

WORKDIR /llvm-project-llvmorg-$LLVM_VERSION

COPY bootstrap.patch /
# Patch to enable better PGO profile data.
# TODO: Remove this for llvm 20
ADD https://github.com/llvm/llvm-project/commit/738250989ce516f02f809bdfde474a039c77e81f.patch .

# TODO(boomanaiden154): Remove the bootstrap patch once we unsplit the build
# and no longer need to explicitly build the stage2 dependencies.
RUN cat /bootstrap.patch | patch -p1

RUN mkdir build
RUN patch -p1 < 738250989ce516f02f809bdfde474a039c77e81f.patch

RUN cmake -B ./build -G Ninja ./llvm \
-C ./clang/cmake/caches/BOLT-PGO.cmake \
Expand All @@ -36,7 +34,29 @@ RUN cmake -B ./build -G Ninja ./llvm \
-DCMAKE_INSTALL_PREFIX="$LLVM_SYSROOT" \
-DLLVM_ENABLE_PROJECTS="bolt;clang;lld;clang-tools-extra" \
-DLLVM_DISTRIBUTION_COMPONENTS="lld;compiler-rt;clang-format;scan-build" \
-DCLANG_DEFAULT_LINKER="lld" \
-DBOOTSTRAP_CLANG_PGO_TRAINING_DATA_SOURCE_DIR=/llvm-project-llvmorg-$LLVM_VERSION/llvm
-DCLANG_DEFAULT_LINKER="lld"

RUN ninja -C ./build stage2-clang-bolt stage2-install-distribution && ninja -C ./build install-distribution && rm -rf ./build
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment on why the rm -rf ./build is here? I believe it was originally to avoid out of disk space errors. Assuming the depot runners have enough disk, it would still be useful as it probably reduces checkpointing time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm inclined to drop it. I think this is a common pattern when doing something on the final image, but since this is just a builder image, I'm not sure if it makes sense to do. I don't have a strong opinion though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems reasonable enough to me.


FROM base

COPY --from=stage1-toolchain $LLVM_SYSROOT $LLVM_SYSROOT

# Need to install curl for hendrikmuhs/ccache-action
# Need nodejs for some of the GitHub actions.
# Need perl-modules for clang analyzer tests.
# Need git for SPIRV-Tools tests.
RUN apt-get update && \
apt-get install -y \
binutils \
cmake \
curl \
git \
libstdc++-11-dev \
ninja-build \
nodejs \
perl-modules \
python3-psutil

RUN ninja -C ./build stage2-instrumented-clang stage2-instrumented-lld
ENV LLVM_SYSROOT=$LLVM_SYSROOT
ENV PATH=${LLVM_SYSROOT}/bin:${PATH}
29 changes: 0 additions & 29 deletions .github/workflows/containers/github-action-ci/stage2.Dockerfile

This file was deleted.

4 changes: 0 additions & 4 deletions .github/workflows/containers/github-action-ci/storage.conf

This file was deleted.