xref: /llvm-project/.github/workflows/containers/github-action-ci/Dockerfile (revision d789915f35a976bb532441915249cd1b165c2fd5)
1FROM docker.io/library/ubuntu:22.04 as base
2ENV LLVM_SYSROOT=/opt/llvm
3
4FROM base as stage1-toolchain
5ENV LLVM_VERSION=19.1.5
6
7RUN apt-get update && \
8    apt-get install -y \
9    wget \
10    gcc \
11    g++ \
12    cmake \
13    ninja-build \
14    python3 \
15    git \
16    curl \
17    zlib1g-dev
18
19RUN curl -O -L https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-$LLVM_VERSION.tar.gz && tar -xf llvmorg-$LLVM_VERSION.tar.gz
20
21WORKDIR /llvm-project-llvmorg-$LLVM_VERSION
22
23# Patch to enable better PGO profile data.
24# TODO: Remove this for llvm 20
25ADD https://github.com/llvm/llvm-project/commit/738250989ce516f02f809bdfde474a039c77e81f.patch .
26
27RUN patch -p1 < 738250989ce516f02f809bdfde474a039c77e81f.patch
28
29RUN cmake -B ./build -G Ninja ./llvm \
30  -C ./clang/cmake/caches/BOLT-PGO.cmake \
31  -DBOOTSTRAP_LLVM_ENABLE_LLD=ON \
32  -DBOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LLD=ON \
33  -DPGO_INSTRUMENT_LTO=Thin \
34  -DLLVM_ENABLE_RUNTIMES="compiler-rt" \
35  -DCMAKE_INSTALL_PREFIX="$LLVM_SYSROOT" \
36  -DLLVM_ENABLE_PROJECTS="bolt;clang;lld;clang-tools-extra" \
37  -DLLVM_DISTRIBUTION_COMPONENTS="lld;compiler-rt;clang-format;scan-build" \
38  -DCLANG_DEFAULT_LINKER="lld"
39
40RUN ninja -C ./build stage2-clang-bolt stage2-install-distribution && ninja -C ./build install-distribution
41
42FROM base as ci-container
43
44COPY --from=stage1-toolchain $LLVM_SYSROOT $LLVM_SYSROOT
45
46# Need to install curl for hendrikmuhs/ccache-action
47# Need nodejs for some of the GitHub actions.
48# Need perl-modules for clang analyzer tests.
49# Need git for SPIRV-Tools tests.
50RUN apt-get update && \
51    DEBIAN_FRONTEND=noninteractive apt-get install -y \
52    binutils \
53    cmake \
54    curl \
55    git \
56    libstdc++-11-dev \
57    ninja-build \
58    nodejs \
59    perl-modules \
60    python3-psutil \
61    sudo \
62
63    # These are needed by the premerge pipeline. Pip is used to install
64    # dependent python packages and ccache is used for build caching. File and
65    # tzdata are used for tests.
66    python3-pip \
67    ccache \
68    file \
69    tzdata
70
71# Install sccache as it is needed by most of the project test workflows and
72# cannot be installed by the ccache action when executing as a non-root user.
73# TODO(boomanaiden154): This should be switched to being installed with apt
74# once we bump to Ubuntu 24.04.
75RUN curl -L 'https://github.com/mozilla/sccache/releases/download/v0.7.6/sccache-v0.7.6-x86_64-unknown-linux-musl.tar.gz' > /tmp/sccache.tar.gz && \
76    echo "2902a5e44c3342132f07b62e70cca75d9b23252922faf3b924f449808cc1ae58 /tmp/sccache.tar.gz" | sha256sum -c && \
77    tar xzf /tmp/sccache.tar.gz -O --wildcards '*/sccache' > '/usr/local/bin/sccache' && \
78    rm /tmp/sccache.tar.gz && \
79    chmod +x /usr/local/bin/sccache
80
81ENV LLVM_SYSROOT=$LLVM_SYSROOT
82ENV PATH=${LLVM_SYSROOT}/bin:${PATH}
83
84# Create a new user to avoid test failures related to a lack of expected
85# permissions issues in some tests. Set the user id to 1001 as that is the
86# user id that Github Actions uses to perform the checkout action.
87RUN useradd gha -u 1001 -m -s /bin/bash
88
89# Also add the user to passwordless sudoers so that we can install software
90# later on without having to rebuild the container.
91RUN adduser gha sudo
92RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
93
94USER gha
95WORKDIR /home/gha
96
97FROM ci-container as ci-container-agent
98
99ENV GITHUB_RUNNER_VERSION=2.322.0
100
101RUN mkdir actions-runner && \
102    cd actions-runner && \
103    curl -O -L https://github.com/actions/runner/releases/download/v$GITHUB_RUNNER_VERSION/actions-runner-linux-x64-$GITHUB_RUNNER_VERSION.tar.gz && \
104    tar xzf ./actions-runner-linux-x64-$GITHUB_RUNNER_VERSION.tar.gz && \
105    rm ./actions-runner-linux-x64-$GITHUB_RUNNER_VERSION.tar.gz
106
107