brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 9c5d504 Raw
115 lines · plain
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-exception6#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 Docker19# 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:latest24#25# The environment variables in `<secrets>` should be the ones necessary26# to run a BuildKite agent:27#28#   BUILDKITE_AGENT_TOKEN=<token>29 30ARG BASE_IMAGE_VERSION31FROM ghcr.io/llvm/libcxx-linux-builder-base:${BASE_IMAGE_VERSION}32 33ARG ANDROID_CLANG_VERSION34ARG ANDROID_CLANG_PREBUILTS_COMMIT35ARG ANDROID_SYSROOT_COMMIT36 37# Install the Android platform tools (e.g. adb) into /opt/android/sdk.38RUN <<EOF39  set -e40  mkdir -p /opt/android/sdk41  cd /opt/android/sdk42  curl -LO https://dl.google.com/android/repository/platform-tools-latest-linux.zip43  unzip platform-tools-latest-linux.zip44  rm platform-tools-latest-linux.zip45EOF46 47# Install the current Android compiler. Specify the prebuilts commit to retrieve48# this compiler version even after it's removed from HEAD.49ENV ANDROID_CLANG_VERSION=$ANDROID_CLANG_VERSION50ENV ANDROID_CLANG_PREBUILTS_COMMIT=$ANDROID_CLANG_PREBUILTS_COMMIT51RUN <<EOF52    set -e53    git clone --filter=blob:none --sparse \54        https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86 \55        /opt/android/clang56    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/.git59    ln -sf /opt/android/clang/clang-${ANDROID_CLANG_VERSION} /opt/android/clang/clang-current60    # The "git sparse-checkout" and "ln" commands succeed even if nothing was61    # checked out, so use this "ls" command to fix that.62    ls /opt/android/clang/clang-current/bin/clang63EOF64 65# Install an Android sysroot. New Android sysroots are available at66# https://android.googlesource.com/platform/prebuilts/ndk/+/refs/heads/mirror-goog-main-ndk/platform/sysroot.67ENV ANDROID_SYSROOT_COMMIT=$ANDROID_SYSROOT_COMMIT68RUN <<EOF69  set -e70  mkdir -p /opt/android/ndk71  cd /opt/android/ndk72  git clone --filter=blob:none https://android.googlesource.com/platform/prebuilts/ndk tmp73  git -C tmp checkout ${ANDROID_SYSROOT_COMMIT}74  mv tmp/platform/sysroot .75  rm -rf tmp76EOF77 78# Create the libcxx-builder user79RUN sudo useradd --create-home libcxx-builder80WORKDIR /home/libcxx-builder81 82# Install the Buildkite agent and dependencies. This must be done as non-root83# 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 configuration86# is passed via the environment.87RUN <<EOF88  set -e89  cd /home/libcxx-builder90  curl -sL https://raw.githubusercontent.com/buildkite/agent/main/install.sh -o /tmp/install-agent.sh91  bash /tmp/install-agent.sh92  rm /tmp/install-agent.sh93EOF94ENV PATH="${PATH}:/home/libcxx-builder/.buildkite-agent/bin"95 96# Install Docker97RUN <<EOF98  set -e99  curl -fsSL https://get.docker.com -o /tmp/get-docker.sh100  sh /tmp/get-docker.sh101  rm /tmp/get-docker.sh102 103  # Install Docker. Mark the binary setuid so it can be run without prefixing it104  # with sudo. Adding the container user to the docker group doesn't work because105  # /var/run/docker.sock is owned by the host's docker GID, not the container's106  # docker GID.107  chmod u+s /usr/bin/docker108EOF109 110# Setup the Buildkite agent command line to do Android setup stuff first.111USER libcxx-builder112COPY libcxx/utils/ci/vendor/android/container-setup.sh /opt/android/container-setup.sh113ENV PATH="/opt/android/sdk/platform-tools:${PATH}"114CMD /opt/android/container-setup.sh && buildkite-agent start115