From 55177548b0663c99ce9bc247239068c066668245 Mon Sep 17 00:00:00 2001 From: Mikhail Goncharov Date: Wed, 6 Sep 2023 14:39:09 +0200 Subject: [PATCH] sccache on linux + deployment sizes --- containers/buildkite-linux/Dockerfile | 2 +- containers/buildkite-linux/entrypoint.sh | 9 +++++++ containers/buildkite-linux/post-checkout | 26 ------------------- containers/buildkite-linux/pre-checkout | 33 ++++++++++++++++++++++-- kubernetes/buildkite/windows.yaml | 2 +- 5 files changed, 42 insertions(+), 30 deletions(-) delete mode 100755 containers/buildkite-linux/post-checkout diff --git a/containers/buildkite-linux/Dockerfile b/containers/buildkite-linux/Dockerfile index 3886a53..7066e68 100644 --- a/containers/buildkite-linux/Dockerfile +++ b/containers/buildkite-linux/Dockerfile @@ -78,7 +78,7 @@ RUN echo 'install buildkite' ;\ 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 +# COPY --chown=buildkite-agent:buildkite-agent post-checkout /etc/buildkite-agent/hooks # buildkite working directory VOLUME /var/lib/buildkite-agent diff --git a/containers/buildkite-linux/entrypoint.sh b/containers/buildkite-linux/entrypoint.sh index e0360cf..a0a3b6a 100755 --- a/containers/buildkite-linux/entrypoint.sh +++ b/containers/buildkite-linux/entrypoint.sh @@ -26,6 +26,14 @@ export CCACHE_MAXSIZE=20G mkdir -p "${CCACHE_DIR}" chown -R ${USER}:${USER} "${CCACHE_DIR}" +export SCCACHE_DIR="$BUILDKITE_BUILD_PATH/sccache" +export SCCACHE_IDLE_TIMEOUT="0" +rm -rf "$SCCACHE_DIR" +mkdir -p "${SCCACHE_DIR}" +chown -R ${USER}:${USER} "${SCCACHE_DIR}" +chmod oug+rw "${SCCACHE_DIR}" +gosu "$USER" bash -c 'env; whoami; SCCACHE_DIR="${SCCACHE_DIR}" SCCACHE_IDLE_TIMEOUT=0 SCCACHE_CACHE_SIZE=20G sccache --start-server' + # /mnt/ssh should contain known_hosts, id_rsa and id_rsa.pub . mkdir -p /var/lib/buildkite-agent/.ssh if [ -d /mnt/ssh ]; then @@ -36,4 +44,5 @@ if [ -d /mnt/ssh ]; then else echo "/mnt/ssh is not mounted" fi +# Run with tini to correctly pass exit codes. exec /usr/bin/tini -g -- $@ diff --git a/containers/buildkite-linux/post-checkout b/containers/buildkite-linux/post-checkout deleted file mode 100755 index 9a61431..0000000 --- a/containers/buildkite-linux/post-checkout +++ /dev/null @@ -1,26 +0,0 @@ -# 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/buildkite-linux/pre-checkout b/containers/buildkite-linux/pre-checkout index 1949014..0ce2562 100755 --- a/containers/buildkite-linux/pre-checkout +++ b/containers/buildkite-linux/pre-checkout @@ -16,8 +16,37 @@ # The `pre-checkout` hook will run just before your pipelines source code is # checked out from your SCM provider -set -e +set -eu +set -o pipefail # 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 +BUILDKITE_BUILD_CHECKOUT_PATH="${BUILDKITE_BUILD_PATH}/$(echo $BUILDKITE_REPO | sed -E "s#.*/([^/]*)#\1#" | sed "s/.git$//")" +gc_counter="$BUILDKITE_BUILD_PATH/git_gc_counter" +echo "BUILDKITE_REPO: $BUILDKITE_REPO" +if [ -d "$BUILDKITE_BUILD_CHECKOUT_PATH" ]; then + cd "$BUILDKITE_BUILD_CHECKOUT_PATH" || exit + remoteUrl=$(git remote get-url origin) + echo "current remote URL: $remoteUrl" + if [ "$remoteUrl" != "$BUILDKITE_REPO" ]; then + echo "Remote URL does not match. Deleting and recreating the directory." + cd /c/ + rm -rf "$BUILDKITE_BUILD_CHECKOUT_PATH" + rm -rf "$gc_counter" + else + # Run git gc from time to time to prevent repo from growing. + echo -n "x" >> "$gc_counter" + echo "GC counter $(wc -c < "$gc_counter")/20" + if [ "$(wc -c < "$gc_counter")" -gt 20 ]; then + echo "Running 'git gc'..." + git gc + git prune + if [ -f ".git/gc.log" ]; then + echo ".git/gc.log exist" + cat ./.git/gc.log + rm -f ./.git/gc.log + fi + rm -rf "$gc_counter" + fi + fi +fi diff --git a/kubernetes/buildkite/windows.yaml b/kubernetes/buildkite/windows.yaml index 7eca1db..5f636a7 100644 --- a/kubernetes/buildkite/windows.yaml +++ b/kubernetes/buildkite/windows.yaml @@ -17,7 +17,7 @@ kind: Deployment metadata: name: windows-buildkite spec: - replicas: 8 + replicas: 6 strategy: type: Recreate selector: