[llvm] [workflows] Build a container for running CI on github actions (PR #75286)

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 22 21:20:50 PST 2023


https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/75286

>From 878aa8869dae85c4245fcc2b6ac65d37f33a2657 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Mon, 11 Dec 2023 14:28:09 -0800
Subject: [PATCH] [workflows] Build a container for running CI on github
 actions

Using a container will allow us to have similar testing environments
on both the GitHub hosted runners and the self-hosted runners.
---
 .github/workflows/build-ci-container.yml      | 52 +++++++++++++++++++
 .../containers/github-action-ci/Dockerfile    | 52 +++++++++++++++++++
 2 files changed, 104 insertions(+)
 create mode 100644 .github/workflows/build-ci-container.yml
 create mode 100644 .github/workflows/containers/github-action-ci/Dockerfile

diff --git a/.github/workflows/build-ci-container.yml b/.github/workflows/build-ci-container.yml
new file mode 100644
index 00000000000000..de2f2fce751371
--- /dev/null
+++ b/.github/workflows/build-ci-container.yml
@@ -0,0 +1,52 @@
+
+name: Build CI Container
+
+permissions:
+  contents: read
+
+on:
+  push:
+    branches:
+      - main
+    paths:
+      - .github/workflows/build-ci-container.yml
+      - '.github/workflows/containers/github-action-ci/**'
+  pull_request:
+    branches:
+      - main
+    paths:
+      - .github/workflows/build-ci-container.yml
+      - '.github/workflows/containers/github-action-ci/**'
+
+jobs:
+  build-ci-container:
+    if: github.repository_owner == 'llvm'
+    runs-on: ubuntu-latest
+    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 at v4
+
+      - name: Build Container
+        working-directory: ./.github/workflows/containers/github-action-ci/
+        run: |
+          podman build -t ${{ steps.vars.outputs.container-name-tag }} .
+          podman tag ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name }}:latest
+
+      - name: Push Container
+        if: github.event_name == 'push'
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          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
diff --git a/.github/workflows/containers/github-action-ci/Dockerfile b/.github/workflows/containers/github-action-ci/Dockerfile
new file mode 100644
index 00000000000000..1f34d7cd84a771
--- /dev/null
+++ b/.github/workflows/containers/github-action-ci/Dockerfile
@@ -0,0 +1,52 @@
+FROM docker.io/library/ubuntu:22.04 as base
+ENV LLVM_SYSROOT=/opt/llvm/
+
+FROM base as toolchain
+ENV LLVM_MAJOR=17
+ENV LLVM_VERSION=${LLVM_MAJOR}.0.6
+ENV LLVM_DIRNAME=clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-22.04
+ENV LLVM_FILENAME=${LLVM_DIRNAME}.tar.xz
+
+RUN apt-get update && \
+    apt-get install -y \
+    curl \
+    xz-utils
+
+RUN mkdir -p $LLVM_SYSROOT/bin/ $LLVM_SYSROOT/lib/
+
+RUN curl -O -L https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/$LLVM_FILENAME
+#COPY $LLVM_FILENAME .
+
+RUN tar -C $LLVM_SYSROOT --strip-components=1 -xJf $LLVM_FILENAME \
+    $LLVM_DIRNAME/bin/clang \
+    $LLVM_DIRNAME/bin/clang++ \
+    $LLVM_DIRNAME/bin/clang-cl \
+    $LLVM_DIRNAME/bin/clang-$LLVM_MAJOR \
+    $LLVM_DIRNAME/bin/lld \
+    $LLVM_DIRNAME/bin/ld.lld \
+    $LLVM_DIRNAME/lib/clang/
+
+
+FROM base
+
+COPY --from=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.
+RUN apt-get update && \
+    apt-get install -y \
+    binutils \
+    cmake \
+    curl \
+    libstdc++-11-dev \
+    ninja-build \
+    nodejs \
+    perl-modules \
+    python3-psutil
+
+ENV LLVM_SYSROOT=$LLVM_SYSROOT
+ENV PATH=${LLVM_SYSROOT}/bin:${PATH}
+
+# Test clang
+RUN printf '#include <iostream>\nint main(int argc, char **argv) { std::cout << "Hello\\n"; }' | clang++ -x c++ - && ./a.out | grep Hello



More information about the llvm-commits mailing list