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 libcxx/utils/ci)
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 libcxx/utils/ci
28#   $ docker push ldionne/libcxx-builder
29#
30
31FROM ubuntu:jammy
32
33# Make sure apt-get doesn't try to prompt for stuff like our time zone, etc.
34ENV DEBIAN_FRONTEND=noninteractive
35
36# This dummy command is meant to be edited from time to time, which causes the
37# CI builders to rebuild their copy of the Docker image. This is not a great
38# solution, however without that, the CI builders will keep the same cached
39# Docker image forever.
40RUN echo 6
41
42RUN apt-get update && apt-get install -y bash curl
43
44# Install various tools used by the build or the test suite
45RUN apt-get update && apt-get install -y ninja-build python3 python3-sphinx python3-distutils python3-psutil git gdb
46
47# Locales for gdb and localization tests
48RUN apt-get update && apt-get install -y language-pack-en language-pack-fr \
49                                         language-pack-ja language-pack-ru \
50                                         language-pack-zh-hans
51# These two are not enabled by default so generate them
52RUN printf "fr_CA ISO-8859-1\ncs_CZ ISO-8859-2" >> /etc/locale.gen
53RUN mkdir /usr/local/share/i1en/
54RUN printf "fr_CA ISO-8859-1\ncs_CZ ISO-8859-2" >> /usr/local/share/i1en/SUPPORTED
55RUN locale-gen
56
57# Install Clang <latest>, <latest-1> and ToT, which are the ones we support.
58# We also install <latest-2> because we need to support the "latest-1" of the
59# current LLVM release branch, which is effectively the <latest-2> of the
60# tip-of-trunk LLVM. For example, after branching LLVM 14 but before branching
61# LLVM 15, we still need to have Clang 12 in this Docker image because the LLVM
62# 14 release branch CI uses it. The tip-of-trunk CI will never use Clang 12,
63# though.
64ENV LLVM_LATEST_VERSION=14
65RUN apt-get update && apt-get install -y lsb-release wget software-properties-common
66RUN wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh
67# TODO Use the apt.llvm.org version after branching to LLVM 15
68RUN apt-get update && apt-get install -y clang-$(($LLVM_LATEST_VERSION - 2))
69#RUN bash /tmp/llvm.sh $(($LLVM_LATEST_VERSION - 2)) # for CI transitions
70RUN bash /tmp/llvm.sh $(($LLVM_LATEST_VERSION - 1)) # previous release
71RUN bash /tmp/llvm.sh $LLVM_LATEST_VERSION          # latest release
72RUN bash /tmp/llvm.sh $(($LLVM_LATEST_VERSION + 1)) # current ToT
73
74# Make the latest version of Clang the "default" compiler on the system
75# TODO: In the future, all jobs should be using an explicitly-versioned version of Clang instead,
76#       and we can get rid of this entirely.
77RUN ln -fs /usr/bin/clang++-$LLVM_LATEST_VERSION /usr/bin/c++ && [ -e $(readlink /usr/bin/c++) ]
78RUN ln -fs /usr/bin/clang-$LLVM_LATEST_VERSION /usr/bin/cc && [ -e $(readlink /usr/bin/cc) ]
79
80# Install clang-format
81RUN apt-get install -y clang-format-$LLVM_LATEST_VERSION
82RUN ln -s /usr/bin/clang-format-$LLVM_LATEST_VERSION /usr/bin/clang-format && [ -e $(readlink /usr/bin/clang-format) ]
83RUN ln -s /usr/bin/git-clang-format-$LLVM_LATEST_VERSION /usr/bin/git-clang-format && [ -e $(readlink /usr/bin/git-clang-format) ]
84
85# Install clang-tidy
86RUN apt-get install -y clang-tidy-$LLVM_LATEST_VERSION
87RUN ln -s /usr/bin/clang-tidy-$LLVM_LATEST_VERSION /usr/bin/clang-tidy && [ -e $(readlink /usr/bin/clang-tidy) ]
88
89# Install the most recent GCC, like clang install the previous version as a transition.
90ENV GCC_LATEST_VERSION=12
91RUN apt-get update && apt install -y gcc-$((GCC_LATEST_VERSION - 1)) g++-$((GCC_LATEST_VERSION - 1))
92RUN apt-get update && apt install -y gcc-$GCC_LATEST_VERSION g++-$GCC_LATEST_VERSION
93
94# Install a recent CMake
95RUN wget https://github.com/Kitware/CMake/releases/download/v3.21.1/cmake-3.21.1-linux-x86_64.sh -O /tmp/install-cmake.sh
96RUN bash /tmp/install-cmake.sh --prefix=/usr --exclude-subdir --skip-license
97RUN rm /tmp/install-cmake.sh
98
99# Change the user to a non-root user, since some of the libc++ tests
100# (e.g. filesystem) require running as non-root. Also setup passwordless sudo.
101RUN apt-get update && apt-get install -y sudo
102RUN echo "ALL ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers
103RUN useradd --create-home libcxx-builder
104USER libcxx-builder
105WORKDIR /home/libcxx-builder
106
107# Install the Buildkite agent and dependencies. This must be done as non-root
108# for the Buildkite agent to be installed in a path where we can find it.
109RUN bash -c "$(curl -sL https://raw.githubusercontent.com/buildkite/agent/main/install.sh)"
110ENV PATH="${PATH}:/home/libcxx-builder/.buildkite-agent/bin"
111RUN echo "tags=\"queue=libcxx-builders,arch=$(uname -m),os=linux\"" >> "/home/libcxx-builder/.buildkite-agent/buildkite-agent.cfg"
112
113# By default, start the Buildkite agent (this requires a token).
114CMD buildkite-agent start
115