Debian Codegraph @

libcxx/utils/ci/Dockerfile

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