Debian Codegraph @

libcxx/utils/ci/docker/android-builder.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 image we use to run Android testing on Buildkite.
10 # From the root of the monorepo, this image can be built with:
11 #
12 # $ docker build --file libcxx/utils/ci/docker/android-builder.dockerfile \
13 # --build-arg BASE_IMAGE_VERSION=<sha> \
14 # --build-arg ANDROID_CLANG_VERSION=<version> \
15 # --build-arg ANDROID_CLANG_PREBUILTS_COMMIT=<sha> \
16 # --build-arg ANDROID_SYSROOT_COMMIT=<sha> .
17 #
18 # This image also gets built on every push to `main` that modifies these Docker
19 # files, and can be found at ghcr.io/llvm/libcxx-android-builder.
20 #
21 # To run the image and start a Buildkite Agent, run it as:
22 #
23 # $ docker run --env-file <secrets> -it ghcr.io/llvm/libcxx-android-builder:latest
24 #
25 # The environment variables in `<secrets>` should be the ones necessary
26 # to run a BuildKite agent:
27 #
28 # BUILDKITE_AGENT_TOKEN=<token>
29
30 ARG BASE_IMAGE_VERSION
31 FROM ghcr.io/llvm/libcxx-linux-builder-base:${BASE_IMAGE_VERSION}
32
33 ARG ANDROID_CLANG_VERSION
34 ARG ANDROID_CLANG_PREBUILTS_COMMIT
35 ARG ANDROID_SYSROOT_COMMIT
36
37 # Install the Android platform tools (e.g. adb) into /opt/android/sdk.
38 RUN <<EOF
39 set -e
40 mkdir -p /opt/android/sdk
41 cd /opt/android/sdk
42 curl -LO https://dl.google.com/android/repository/platform-tools-latest-linux.zip
43 unzip platform-tools-latest-linux.zip
44 rm platform-tools-latest-linux.zip
45 EOF
46
47 # Install the current Android compiler. Specify the prebuilts commit to retrieve
48 # this compiler version even after it's removed from HEAD.
49 ENV ANDROID_CLANG_VERSION=$ANDROID_CLANG_VERSION
50 ENV ANDROID_CLANG_PREBUILTS_COMMIT=$ANDROID_CLANG_PREBUILTS_COMMIT
51 RUN <<EOF
52 set -e
53 git clone --filter=blob:none --sparse \
54 https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86 \
55 /opt/android/clang
56 git -C /opt/android/clang checkout ${ANDROID_CLANG_PREBUILTS_COMMIT}
57 git -C /opt/android/clang sparse-checkout add clang-${ANDROID_CLANG_VERSION}
58 rm -fr /opt/android/clang/.git
59 ln -sf /opt/android/clang/clang-${ANDROID_CLANG_VERSION} /opt/android/clang/clang-current
60 # The "git sparse-checkout" and "ln" commands succeed even if nothing was
61 # checked out, so use this "ls" command to fix that.
62 ls /opt/android/clang/clang-current/bin/clang
63 EOF
64
65 # Install an Android sysroot. New Android sysroots are available at
66 # https://android.googlesource.com/platform/prebuilts/ndk/+/refs/heads/mirror-goog-main-ndk/platform/sysroot.
67 ENV ANDROID_SYSROOT_COMMIT=$ANDROID_SYSROOT_COMMIT
68 RUN <<EOF
69 set -e
70 mkdir -p /opt/android/ndk
71 cd /opt/android/ndk
72 git clone --filter=blob:none https://android.googlesource.com/platform/prebuilts/ndk tmp
73 git -C tmp checkout ${ANDROID_SYSROOT_COMMIT}
74 mv tmp/platform/sysroot .
75 rm -rf tmp
76 EOF
77
78 # Create the libcxx-builder user
79 RUN sudo useradd --create-home libcxx-builder
80 WORKDIR /home/libcxx-builder
81
82 # Install the Buildkite agent and dependencies. This must be done as non-root
83 # for the Buildkite agent to be installed in a path where we can find it.
84 #
85 # Note that we don't set up the configuration file here, since the configuration
86 # is passed via the environment.
87 RUN <<EOF
88 set -e
89 cd /home/libcxx-builder
90 curl -sL https://raw.githubusercontent.com/buildkite/agent/main/install.sh -o /tmp/install-agent.sh
91 bash /tmp/install-agent.sh
92 rm /tmp/install-agent.sh
93 EOF
94 ENV PATH="${PATH}:/home/libcxx-builder/.buildkite-agent/bin"
95
96 # Install Docker
97 RUN <<EOF
98 set -e
99 curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
100 sh /tmp/get-docker.sh
101 rm /tmp/get-docker.sh
102
103 # Install Docker. Mark the binary setuid so it can be run without prefixing it
104 # with sudo. Adding the container user to the docker group doesn't work because
105 # /var/run/docker.sock is owned by the host's docker GID, not the container's
106 # docker GID.
107 chmod u+s /usr/bin/docker
108 EOF
109
110 # Setup the Buildkite agent command line to do Android setup stuff first.
111 USER libcxx-builder
112 COPY libcxx/utils/ci/vendor/android/container-setup.sh /opt/android/container-setup.sh
113 ENV PATH="/opt/android/sdk/platform-tools:${PATH}"
114 CMD /opt/android/container-setup.sh && buildkite-agent start