diff --git a/containers/bazel/.dockerignore b/containers/bazel/.dockerignore new file mode 100644 index 0000000..74bf493 --- /dev/null +++ b/containers/bazel/.dockerignore @@ -0,0 +1 @@ +cloudbuild.yaml \ No newline at end of file diff --git a/containers/bazel/Dockerfile b/containers/bazel/Dockerfile new file mode 100644 index 0000000..5324a11 --- /dev/null +++ b/containers/bazel/Dockerfile @@ -0,0 +1,80 @@ +FROM debian:stable + +RUN echo 'intall packages'; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + locales openssh-client gnupg ca-certificates \ + zip wget git \ + gdb build-essential \ + ninja-build \ + libelf-dev libffi-dev gcc-multilib \ + # for llvm-libc tests that build mpfr and gmp from source + autoconf automake libtool \ + ccache \ + python3 python3-psutil \ + python3-pip python3-setuptools \ + lsb-release software-properties-common \ + swig python3-dev libedit-dev libncurses5-dev libxml2-dev liblzma-dev golang rsync jq \ + # for llvm installation script + sudo; + +# debian stable cmake is 3.18, we need to install a more recent version. +RUN wget --no-verbose -O /cmake.sh https://github.com/Kitware/CMake/releases/download/v3.23.3/cmake-3.23.3-linux-x86_64.sh; \ + chmod +x /cmake.sh; \ + mkdir -p /etc/cmake; \ + /cmake.sh --prefix=/etc/cmake --skip-license; \ + ln -s /etc/cmake/bin/cmake /usr/bin/cmake; \ + cmake --version; \ + rm /cmake.sh + +# LLVM must be installed after prerequsite packages. +ENV LLVM_VERSION=16 +RUN echo 'install llvm ${LLVM_VERSION}'; \ + wget --no-verbose https://apt.llvm.org/llvm.sh; \ + chmod +x llvm.sh; \ + ./llvm.sh ${LLVM_VERSION};\ + apt-get update; \ + apt install -y clang-${LLVM_VERSION} clang-format-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} lld-${LLVM_VERSION}; \ + ln -s /usr/bin/clang-${LLVM_VERSION} /usr/bin/clang;\ + ln -s /usr/bin/clang++-${LLVM_VERSION} /usr/bin/clang++;\ + ln -s /usr/bin/clang-tidy-${LLVM_VERSION} /usr/bin/clang-tidy;\ + ln -s /usr/bin/clang-tidy-diff-${LLVM_VERSION}.py /usr/bin/clang-tidy-diff;\ + ln -s /usr/bin/clang-format-${LLVM_VERSION} /usr/bin/clang-format;\ + ln -s /usr/bin/clang-format-diff-${LLVM_VERSION} /usr/bin/clang-format-diff;\ + ln -s /usr/bin/lld-${LLVM_VERSION} /usr/bin/lld;\ + ln -s /usr/bin/lldb-${LLVM_VERSION} /usr/bin/lldb;\ + ln -s /usr/bin/ld.lld-${LLVM_VERSION} /usr/bin/ld.lld + +RUN echo 'configure locale'; \ + sed --in-place '/en_US.UTF-8/s/^#//' /etc/locale.gen ;\ + locale-gen ;\ + echo 'make python 3 default'; \ + rm -f /usr/bin/python && ln -s /usr/bin/python3 /usr/bin/python; \ + pip3 install wheel + +# Configure locale +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +RUN wget --no-verbose -O /usr/bin/bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.17.0/bazelisk-linux-amd64; \ + chmod +x /usr/bin/bazelisk; \ + bazelisk --version + +RUN echo 'install buildkite' ;\ + apt-get install -y apt-transport-https gnupg;\ + sh -c 'echo deb https://apt.buildkite.com/buildkite-agent stable main > /etc/apt/sources.list.d/buildkite-agent.list' ;\ + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 32A37959C2FA5C3C99EFBC32A79206696452D198 ;\ + apt-get update ;\ + apt-get install -y buildkite-agent tini gosu; \ + apt-get clean; +COPY *.sh /usr/local/bin/ +RUN chmod og+rx /usr/local/bin/*.sh +COPY --chown=buildkite-agent:buildkite-agent pre-checkout /etc/buildkite-agent/hooks +COPY --chown=buildkite-agent:buildkite-agent post-checkout /etc/buildkite-agent/hooks + +# buildkite working directory +VOLUME /var/lib/buildkite-agent + +ENTRYPOINT ["entrypoint.sh"] +CMD ["gosu", "buildkite-agent", "buildkite-agent", "start", "--no-color"] diff --git a/containers/bazel/entrypoint.sh b/containers/bazel/entrypoint.sh new file mode 100755 index 0000000..e0360cf --- /dev/null +++ b/containers/bazel/entrypoint.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Copyright 2021 Google LLC +# +# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -eo pipefail + +USER=buildkite-agent +P="${BUILDKITE_BUILD_PATH:-/var/lib/buildkite-agent}" +set -u +mkdir -p "$P" +chown -R ${USER}:${USER} "$P" + +export CCACHE_DIR="${P}"/ccache +export CCACHE_MAXSIZE=20G +mkdir -p "${CCACHE_DIR}" +chown -R ${USER}:${USER} "${CCACHE_DIR}" + +# /mnt/ssh should contain known_hosts, id_rsa and id_rsa.pub . +mkdir -p /var/lib/buildkite-agent/.ssh +if [ -d /mnt/ssh ]; then + cp /mnt/ssh/* /var/lib/buildkite-agent/.ssh || echo "no " + chmod 700 /var/lib/buildkite-agent/.ssh + chmod 600 /var/lib/buildkite-agent/.ssh/* + chown -R buildkite-agent:buildkite-agent /var/lib/buildkite-agent/.ssh/ +else + echo "/mnt/ssh is not mounted" +fi +exec /usr/bin/tini -g -- $@ diff --git a/containers/bazel/post-checkout b/containers/bazel/post-checkout new file mode 100755 index 0000000..9a61431 --- /dev/null +++ b/containers/bazel/post-checkout @@ -0,0 +1,26 @@ +# Copyright 2021 Google LLC +# +# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# The `post-checkout` hook runs after checkout. + +set -eu + +# Run prune as git will start to complain "warning: There are too many unreachable loose objects; run 'git prune' to remove them.". +# That happens as we routinely drop old branches. +git prune +if [ -f ".git/gc.log" ]; then + echo ".git/gc.log exist" + cat ./.git/gc.log + rm -f ./.git/gc.log +fi diff --git a/containers/bazel/pre-checkout b/containers/bazel/pre-checkout new file mode 100755 index 0000000..1949014 --- /dev/null +++ b/containers/bazel/pre-checkout @@ -0,0 +1,23 @@ +#!/bin/bash +# Copyright 2020 Google LLC +# +# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# The `pre-checkout` hook will run just before your pipelines source code is +# checked out from your SCM provider + +set -e + +# Convert https://github.com/llvm-premerge-tests/llvm-project.git -> llvm-project +# to use the same directory for fork and origin. +BUILDKITE_BUILD_CHECKOUT_PATH="${BUILDKITE_BUILD_PATH}/$(echo $BUILDKITE_REPO | sed -E "s#.*/([^/]*)#\1#" | sed "s/.git$//")" \ No newline at end of file