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#
10# This Dockerfile describes the base image used to run the various libc++
11# build bots. By default, the image runs the Buildkite Agent, however one
12# can also just start the image with a shell to debug CI failures.
13#
14# To start a Buildkite Agent, run it as:
15#   $ docker run --env-file <secrets> -it $(docker build -q .)
16#
17# The environment variables in `<secrets>` should be the ones necessary
18# to run a BuildKite agent.
19#
20# If you're only looking to run the Docker image locally for debugging a
21# build bot, see the `run-buildbot-container` script located in this directory.
22#
23# A pre-built version of this image is maintained on DockerHub as ldionne/libcxx-builder.
24# To update the image, rebuild it and push it to ldionne/libcxx-builder (which
25# will obviously only work if you have permission to do so).
26#
27#   $ docker build -t ldionne/libcxx-builder .
28#   $ docker push ldionne/libcxx-builder
29#
30
31FROM ubuntu:bionic
32
33# Make sure apt-get doesn't try to prompt for stuff like our time zone, etc.
34ENV DEBIAN_FRONTEND=noninteractive
35
36RUN apt-get update && apt-get install -y bash curl
37
38# Install various tools used by the build or the test suite
39RUN apt-get update && apt-get install -y ninja-build python3 python3-sphinx python3-distutils git gdb
40RUN apt-get update && apt-get install -y libc6-dev-i386 # Required to cross-compile to 32 bits
41
42# Install Clang <latest>, <latest-1> and ToT, which are the ones we support.
43ENV LLVM_LATEST_VERSION=12
44RUN apt-get update && apt-get install -y lsb-release wget software-properties-common
45RUN wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh
46RUN bash /tmp/llvm.sh $(($LLVM_LATEST_VERSION - 1)) # previous release
47RUN bash /tmp/llvm.sh $LLVM_LATEST_VERSION          # latest release
48RUN bash /tmp/llvm.sh $(($LLVM_LATEST_VERSION + 1)) # current ToT
49
50# Make the ToT Clang the "default" compiler on the system
51RUN ln -fs /usr/bin/clang++-$(($LLVM_LATEST_VERSION + 1)) /usr/bin/c++ && [ -e $(readlink /usr/bin/c++) ]
52RUN ln -fs /usr/bin/clang-$(($LLVM_LATEST_VERSION + 1)) /usr/bin/cc && [ -e $(readlink /usr/bin/cc) ]
53
54# Install clang-format
55RUN apt-get install -y clang-format-$LLVM_LATEST_VERSION
56RUN ln -s /usr/bin/clang-format-$LLVM_LATEST_VERSION /usr/bin/clang-format && [ -e $(readlink /usr/bin/clang-format) ]
57RUN ln -s /usr/bin/git-clang-format-$LLVM_LATEST_VERSION /usr/bin/git-clang-format && [ -e $(readlink /usr/bin/git-clang-format) ]
58
59# Install the most recent GCC
60ENV GCC_LATEST_VERSION=11
61RUN add-apt-repository ppa:ubuntu-toolchain-r/test
62RUN apt-get update && apt install -y gcc-$GCC_LATEST_VERSION g++-$GCC_LATEST_VERSION
63
64# Install a recent CMake
65RUN wget https://github.com/Kitware/CMake/releases/download/v3.21.1/cmake-3.21.1-linux-x86_64.sh -O /tmp/install-cmake.sh
66RUN bash /tmp/install-cmake.sh --prefix=/usr --exclude-subdir --skip-license
67RUN rm /tmp/install-cmake.sh
68
69# Change the user to a non-root user, since some of the libc++ tests
70# (e.g. filesystem) require running as non-root. Also setup passwordless sudo.
71RUN apt-get update && apt-get install -y sudo
72RUN echo "ALL ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers
73RUN useradd --create-home libcxx-builder
74USER libcxx-builder
75WORKDIR /home/libcxx-builder
76
77# Install the Buildkite agent and dependencies. This must be done as non-root
78# for the Buildkite agent to be installed in a path where we can find it.
79RUN bash -c "$(curl -sL https://raw.githubusercontent.com/buildkite/agent/master/install.sh)"
80ENV PATH="${PATH}:/home/libcxx-builder/.buildkite-agent/bin"
81RUN echo "tags=\"queue=libcxx-builders,arch=$(uname -m),os=linux\"" >> "/home/libcxx-builder/.buildkite-agent/buildkite-agent.cfg"
82
83# By default, start the Buildkite agent (this requires a token).
84CMD buildkite-agent start
85