• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#===----------------------------------------------------------------------===##
2#
3# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4# See https://llvm.org/LICENSE.txt for license information.
5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6#
7#===----------------------------------------------------------------------===##
8#
9# This file defines the buildkite and github actions builder images.
10# You can build & push both images using:
11#
12#   docker compose build
13#   docker compose push
14#
15# Or you can select a single image to build & push using:
16#
17#  docker compose build buildkite-builder
18#  docker compose push buildkite-builder
19#
20# The final images can be found at
21#
22#  ghcr.io/libcxx/buildkite-builder
23#  ghcr.io/libcxx/actions-builder
24#  ghcr.io/libcxx/android-buildkite-builder
25#
26# Members of the github.com/libcxx/ organizations have permissions required to push new images.
27#
28# ===----------------------------------------------------------------------===##
29#                     Running the buildkite image
30# ===----------------------------------------------------------------------===##
31#
32# To start a Buildkite Agent, run it as:
33#   $ docker run --env-file <secrets> -it $(docker build -q libcxx/utils/ci)
34#
35# The environment variables in `<secrets>` should be the ones necessary
36# to run a BuildKite agent:
37#
38#   BUILDKITE_AGENT_TOKEN=<token>
39#
40# If you're only looking to run the Docker image locally for debugging a
41# build bot, see the `run-buildbot-container` script located in this directory.
42
43
44# HACK: We set the base image in the docker-compose file depending on the final target (buildkite vs github actions).
45# This means we have a much slower container build, but we can use the same Dockerfile for both targets.
46ARG BASE_IMAGE
47FROM $BASE_IMAGE AS builder-base
48
49# Make sure apt-get doesn't try to prompt for stuff like our time zone, etc.
50ENV DEBIAN_FRONTEND=noninteractive
51
52# populated in the docker-compose file
53ARG GCC_LATEST_VERSION
54ENV GCC_LATEST_VERSION=${GCC_LATEST_VERSION}
55
56# populated in the docker-compose file
57ARG LLVM_HEAD_VERSION
58ENV LLVM_HEAD_VERSION=${LLVM_HEAD_VERSION}
59
60# HACK: The github actions runner image already has sudo and requires its use. The buildkite base image does not.
61# Reconcile this.
62RUN <<EOF
63  apt-get update || true
64  apt-get install -y sudo || true
65  echo "ALL ALL = (ALL) NOPASSWD: ALL" | tee /etc/sudoers || true
66EOF
67
68RUN sudo apt-get update \
69    && sudo apt-get install -y \
70        python3 \
71        python3-distutils \
72        python3-psutil \
73        git \
74        gdb \
75        ccache \
76        gpg \
77        wget \
78        bash \
79        curl \
80        python3 \
81        python3-dev \
82        libpython3-dev \
83        uuid-dev \
84        libncurses5-dev \
85        swig3.0 \
86        libxml2-dev \
87        libedit-dev \
88        language-pack-en \
89        language-pack-fr \
90        language-pack-ja \
91        language-pack-ru \
92        language-pack-zh-hans \
93        lsb-release \
94        wget \
95        unzip \
96        software-properties-common \
97    && sudo rm -rf /var/lib/apt/lists/*
98
99
100# Install various tools used by the build or the test suite
101#RUN apt-get update && apt-get install -y ninja-build python3 python3-distutils python3-psutil git gdb ccache
102# TODO add ninja-build once 1.11 is available in Ubuntu, also remove the manual installation.
103RUN <<EOF
104  wget -qO /tmp/ninja.gz https://github.com/ninja-build/ninja/releases/latest/download/ninja-linux.zip
105  gunzip /tmp/ninja.gz
106  chmod a+x /tmp/ninja
107  sudo mv /tmp/ninja /usr/local/bin/ninja
108EOF
109
110
111# These two locales are not enabled by default so generate them
112RUN <<EOF
113  printf "fr_CA ISO-8859-1\ncs_CZ ISO-8859-2" | sudo tee -a /etc/locale.gen
114  sudo mkdir /usr/local/share/i1en/
115  printf "fr_CA ISO-8859-1\ncs_CZ ISO-8859-2" | sudo tee -a /usr/local/share/i1en/SUPPORTED
116  sudo locale-gen
117EOF
118
119# Install Clang <latest>, <latest-1> and ToT, which are the ones we support.
120# We also install <latest-2> because we need to support the "latest-1" of the
121# current LLVM release branch, which is effectively the <latest-2> of the
122# tip-of-trunk LLVM. For example, after branching LLVM 14 but before branching
123# LLVM 15, we still need to have Clang 12 in this Docker image because the LLVM
124# 14 release branch CI uses it. The tip-of-trunk CI will never use Clang 12,
125# though.
126RUN <<EOF
127  sudo apt-get update
128  wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh
129  chmod +x /tmp/llvm.sh
130  sudo /tmp/llvm.sh $(($LLVM_HEAD_VERSION - 3)) all  # for CI transitions
131  sudo /tmp/llvm.sh $(($LLVM_HEAD_VERSION - 2)) all  # previous release
132  sudo /tmp/llvm.sh $(($LLVM_HEAD_VERSION - 1)) all  # latest release
133  sudo /tmp/llvm.sh $LLVM_HEAD_VERSION          all  # current ToT
134  sudo apt-get install -y libomp5-$LLVM_HEAD_VERSION
135  sudo rm -rf /var/lib/apt/lists/*
136EOF
137
138# Install the most recent GCC, like clang install the previous version as a transition.
139RUN <<EOF
140  sudo add-apt-repository ppa:ubuntu-toolchain-r/test
141  sudo apt-get update
142  sudo apt-get install -y \
143    gcc-$((GCC_LATEST_VERSION - 1)) \
144    g++-$((GCC_LATEST_VERSION - 1)) \
145    gcc-$GCC_LATEST_VERSION \
146    g++-$GCC_LATEST_VERSION
147  sudo rm -rf /var/lib/apt/lists/*
148EOF
149
150RUN <<EOF
151    # Install a recent CMake
152    wget https://github.com/Kitware/CMake/releases/download/v3.21.1/cmake-3.21.1-linux-x86_64.sh -O /tmp/install-cmake.sh
153    sudo bash /tmp/install-cmake.sh --prefix=/usr --exclude-subdir --skip-license
154    rm /tmp/install-cmake.sh
155
156    # Install a newer CMake for modules
157    # TODO Remove the duplicated installation when all runtimes can be build with CMake 3.28.
158    wget https://github.com/Kitware/CMake/releases/download/v3.27.1/cmake-3.27.1-linux-x86_64.sh -O /tmp/install-cmake.sh
159    sudo bash /tmp/install-cmake.sh --prefix=/opt --exclude-subdir --skip-license
160    rm /tmp/install-cmake.sh
161
162    wget https://github.com/Kitware/CMake/releases/download/v3.28.0-rc4/cmake-3.28.0-rc4-linux-x86_64.sh -O /tmp/install-cmake.sh
163    sudo mkdir /opt/cmake-3.28
164    sudo bash /tmp/install-cmake.sh --prefix=/opt/cmake-3.28 --exclude-subdir --skip-license
165    rm /tmp/install-cmake.sh
166EOF
167
168# ===----------------------------------------------------------------------===##
169#                       Android Buildkite Image
170# ===----------------------------------------------------------------------===##
171
172FROM ubuntu:jammy AS android-builder-base
173
174ARG ANDROID_CLANG_VERSION
175ARG ANDROID_CLANG_PREBUILTS_COMMIT
176ARG ANDROID_SYSROOT_BID
177
178RUN  apt-get update && apt-get install -y curl unzip git
179
180# Install the Android platform tools (e.g. adb) into /opt/android/sdk.
181RUN <<EOF
182  mkdir -p /opt/android/sdk
183  cd /opt/android/sdk
184  curl -LO https://dl.google.com/android/repository/platform-tools-latest-linux.zip
185  unzip platform-tools-latest-linux.zip
186  rm platform-tools-latest-linux.zip
187EOF
188
189# Install the current Android compiler. Specify the prebuilts commit to retrieve
190# this compiler version even after it's removed from HEAD.
191
192ENV ANDROID_CLANG_VERSION=$ANDROID_CLANG_VERSION
193ENV ANDROID_CLANG_PREBUILTS_COMMIT=$ANDROID_CLANG_PREBUILTS_COMMIT
194RUN <<EOF
195    git clone --filter=blob:none --sparse \
196        https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86 \
197        /opt/android/clang
198    git -C /opt/android/clang checkout ${ANDROID_CLANG_PREBUILTS_COMMIT}
199    git -C /opt/android/clang sparse-checkout add clang-${ANDROID_CLANG_VERSION}
200    rm -fr /opt/android/clang/.git
201    ln -sf /opt/android/clang/clang-${ANDROID_CLANG_VERSION} /opt/android/clang/clang-current
202    # The "git sparse-checkout" and "ln" commands succeed even if nothing was
203    # checked out, so use this "ls" command to fix that.
204    ls /opt/android/clang/clang-current/bin/clang
205EOF
206
207# Install an Android sysroot. New AOSP sysroots are available at
208# https://ci.android.com/builds/branches/aosp-main/grid, the "ndk" target. The
209# NDK also makes its sysroot prebuilt available at
210# https://android.googlesource.com/platform/prebuilts/ndk/+/refs/heads/dev/platform/sysroot.
211
212ENV ANDROID_SYSROOT_BID=$ANDROID_SYSROOT_BID
213RUN <<EOF
214  cd /opt/android
215  curl -L -o ndk_platform.tar.bz2 \
216      https://androidbuildinternal.googleapis.com/android/internal/build/v3/builds/${ANDROID_SYSROOT_BID}/ndk/attempts/latest/artifacts/ndk_platform.tar.bz2/url
217  tar xf ndk_platform.tar.bz2
218  rm ndk_platform.tar.bz2
219EOF
220
221# Install Docker
222RUN <<EOF
223  curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
224  sh /tmp/get-docker.sh
225  rm /tmp/get-docker.sh
226
227  # Install Docker. Mark the binary setuid so it can be run without prefixing it
228  # with sudo. Adding the container user to the docker group doesn't work because
229  # /var/run/docker.sock is owned by the host's docker GID, not the container's
230  # docker GID.
231  chmod u+s /usr/bin/docker
232EOF
233
234# ===----------------------------------------------------------------------===##
235#                    Buildkite Builder Image
236# ===----------------------------------------------------------------------===##
237#
238# IMAGE: ghcr.io/libcxx/buildkite-builder.
239#
240FROM builder-base AS buildkite-builder
241
242# Create the libcxx-builder user, regardless of if we use it or not
243RUN sudo useradd --create-home libcxx-builder
244
245USER libcxx-builder
246WORKDIR /home/libcxx-builder
247
248# Install the Buildkite agent and dependencies. This must be done as non-root
249# for the Buildkite agent to be installed in a path where we can find it.
250RUN <<EOF
251  cd /home/libcxx-builder
252  curl -sL https://raw.githubusercontent.com/buildkite/agent/main/install.sh -o /tmp/install-agent.sh
253  bash /tmp/install-agent.sh
254  rm /tmp/install-agent.sh
255  echo "tags=\"queue=libcxx-builders,arch=$(uname -m),os=linux\"" \
256    >> /home/libcxx-builder/.buildkite-agent/buildkite-agent.cfg
257EOF
258
259USER libcxx-builder
260WORKDIR /home/libcxx-builder
261
262ENV PATH="${PATH}:/home/libcxx-builder/.buildkite-agent/bin"
263
264CMD ["buildkite-agent", "start"]
265
266# ===----------------------------------------------------------------------===##
267#                    Android Buildkite Builder Image
268# ===----------------------------------------------------------------------===##
269#
270# IMAGE: ghcr.io/libcxx/android-buildkite-builder.
271#
272FROM buildkite-builder AS android-buildkite-builder
273
274COPY --from=android-builder-base /opt/android /opt/android
275COPY ./vendor/android/container-setup.sh /opt/android/container-setup.sh
276
277ENV PATH="/opt/android/sdk/platform-tools:${PATH}"
278
279USER libcxx-builder
280WORKDIR /home/libcxx-builder
281
282# Reset the configuration, we pass the configuration via the environment.
283RUN cp /home/libcxx-builder/.buildkite-agent/buildkite-agent.dist.cfg \
284       /home/libcxx-builder/.buildkite-agent/buildkite-agent.cfg
285
286# Modify the Buildkite agent cmdline to do Android setup stuff first.
287CMD /opt/android/container-setup.sh && buildkite-agent start
288
289# ===----------------------------------------------------------------------===##
290#                    Github Actions Builder Image
291# ===----------------------------------------------------------------------===##
292#
293# IMAGE: ghcr.io/libcxx/actions-builder.
294#
295FROM builder-base AS actions-builder
296
297# Install 'act' for running github actions locally. This provides an alternative to the run-buildbot script
298# while still providing reproducability.
299RUN curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
300
301WORKDIR /home/runner
302USER runner
303
304
305
306