ci: move downloads cache to S3
PATCH v2 1/1 ci: move downloads cache to S3
The runner's native S3 cache fails for uploads larger than 5G as multipart upload is not support by default. As sts access requires a change for each fork/runner we stay for now with self implemented upload script.
Replace the GitLab cache: for build/downloads with a single tar.zst per arch/kernel stored in S3, restored before and saved after the build.
---
Changes v2:
- clean update remove unnecessary code
- add comment to multipart upload in commit message
Tested with https://gitlab.com/Xenomai/xenomai-images/-/jobs/18136100219
and https://gitlab.com/Xenomai/xenomai-images/-/jobs/18136323078
.gitignore | 1 + ci/lib/gitlab-ci-base.yml | 14 +++++--- scripts/s3-cache.sh | 75 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 4 deletions(-) create mode 100755 scripts/s3-cache.sh
.gitignore +1 -0
@@ -1,3 +1,4 @@ build isar .config.yaml* +.s3-cache/
ci/lib/gitlab-ci-base.yml +10 -4
@@ -54,6 +54,14 @@ default: - ./isar/scripts/isar-sstate upload "build/sstate-cache" "${SSTATE_LOCATION}" - ./isar/scripts/isar-sstate info -v "${SSTATE_LOCATION}" +.s3-cache-restore: + script: + - scripts/s3-cache.sh restore + +.s3-cache-save: + script: + - scripts/s3-cache.sh save + .common-config: script: - if [ -n "$ALT_DNS_SERVER" ]; then
@@ -71,6 +79,7 @@ default: - build before_script: - !reference [.common-config, script] + - !reference [.s3-cache-restore, script] - !reference [.sstate-prepare, script] script: - echo "Building kas.yaml:kas/board/${TARGET}.yaml${XENOMAI_BUILD_OPTION}${LINUX_BUILD_OPTION}${BUILD_OPTIONS}:kas/opt/ci.yaml"
@@ -80,10 +89,7 @@ default: after_script: - !reference [.sstate-lint, script] - !reference [.sstate-upload, script] - cache: - - key: downloads-${CACHE_ARCH}-${CACHE_KERNEL} - paths: - - build/downloads + - !reference [.s3-cache-save, script] .build-qemu-rules: &build-qemu-rules - if: '$KERNEL_VERSION == $KERNEL_VERSION_WITH_QEMU'
scripts/s3-cache.sh new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.56.0
Jan Kiszka
AppliedQuoted 145 lines · Quirin Gylstorff
The runner's native S3 cache fails for uploads larger than 5G as multipart upload is not support by default. As sts access requires a change for each fork/runner we stay for now with self implemented upload script.
Replace the GitLab cache: for build/downloads with a single tar.zst per
arch/kernelstored in S3, restored before and saved after the build.Signed-off-by Quirin Gylstorff <[email protected]>---
Changes v2:
- clean update remove unnecessary code
- add comment to multipart upload in commit messageTested with https://gitlab.com/Xenomai/xenomai-images/-/jobs/18136100219
and https://gitlab.com/Xenomai/xenomai-images/-/jobs/18136323078.gitignore | 1 + ci/lib/gitlab-ci-base.yml | 14 +++++--- scripts/s3-cache.sh | 75 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 4 deletions(-) create mode 100755 scripts/s3-cache.sh.gitignore +1
-0@@ -1,3 +1,4 @@ build isar .config.yaml* +.s3-cache/ci/lib/gitlab-ci-base.yml +10
-4@@ -54,6 +54,14 @@ default: - ./isar/scripts/isar-sstate upload "build/sstate-cache" "${SSTATE_LOCATION}" - ./isar/scripts/isar-sstate info -v "${SSTATE_LOCATION}" +.s3-cache-restore: + script: + - scripts/s3-cache.sh restore + +.s3-cache-save: + script: + - scripts/s3-cache.sh save + .common-config: script: - if [ -n "$ALT_DNS_SERVER" ]; then@@ -71,6 +79,7 @@ default: - build before_script: - !reference [.common-config, script] + - !reference [.s3-cache-restore, script] - !reference [.sstate-prepare, script] script: - echo "Building kas.yaml:kas/board/${TARGET}.yaml${XENOMAI_BUILD_OPTION}${LINUX_BUILD_OPTION}${BUILD_OPTIONS}:kas/opt/ci.yaml"@@ -80,10 +89,7 @@ default: after_script: - !reference [.sstate-lint, script] - !reference [.sstate-upload, script] - cache: - - key: downloads-${CACHE_ARCH}-${CACHE_KERNEL} - paths: - - build/downloads + - !reference [.s3-cache-save, script] .build-qemu-rules: &build-qemu-rules - if: '$KERNEL_VERSION == $KERNEL_VERSION_WITH_QEMU'scripts/s3-cache.sh new file +65
-0@@ -0,0 +1,75 @@ +#!/bin/bash + +# +# Xenomai Real-Time System +# +# Copyright (c) Siemens AG, 2026 +# +# SPDX-License-Identifier: MIT +# +# Best-effort build/downloads cache in S3, authenticated with the static +# AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY CI/CD variables. +# Usage: s3-cache.sh restore|save +# +# Defaults are built in; each can be overridden by a CI/CD variable: +# AWS_CACHE_BUCKET, AWS_REGION +# Provided by the job: CACHE_ARCH, CACHE_KERNEL +# Any failure only warns: the cache must never fail a build. +set -o pipefail + +action="$1" +downloads_dir="${CACHE_DOWNLOADS_DIR:-build/downloads}" +state_dir="${CI_PROJECT_DIR:-.}/.s3-cache" + +warn() { echo "s3-cache: $*" >&2; } + +AWS_CACHE_BUCKET="${AWS_CACHE_BUCKET:-siemens-xenomai-gitlab-cache}" +AWS_REGION="${AWS_REGION:-eu-central-1}" + +for t in aws zstd tar; do + command -v "${t}" >/dev/null || { warn "${t} not found - cache disabled"; exit 0; } +done + +key="xenomai-cache/project/${CI_PROJECT_ID}/downloads-${CACHE_ARCH}-${CACHE_KERNEL}.tar.zst" +object="s3://${AWS_CACHE_BUCKET}/${key}" + +fingerprint() { + (cd "${downloads_dir}" 2>/dev/null && + find . -type f ! -name '*.lock' -printf '%P %s\n' | LC_ALL=C sort | sha256sum | cut -d' ' -f1) +} + +case "${action}" in +restore) + if ! aws s3api head-object --bucket "${AWS_CACHE_BUCKET}" --key "${key}" >/dev/null 2>&1; then + warn "no cache object ${object} - cold start" + exit 0 + fi + mkdir -p "${downloads_dir}" "${state_dir}" + echo "s3-cache: restoring ${object}" + if aws s3 cp "${object}" - --only-show-errors | + zstd -d -T0 | tar -x -C "$(dirname "${downloads_dir}")"; then + fingerprint > "${state_dir}/fingerprint" 2>/dev/null + else + warn "restore failed - continuing with a possibly partial downloads dir" + rm -f "${state_dir}/fingerprint" + fi + ;; +save) + [ -d "${downloads_dir}" ] || { warn "no ${downloads_dir} - not saving"; exit 0; } + new=$(fingerprint) + if [ -f "${state_dir}/fingerprint" ] && [ "${new}" = "$(cat "${state_dir}/fingerprint")" ]; then + warn "downloads unchanged - not saving" + exit 0 + fi + echo "s3-cache: saving ${object}" + tar -c -C "$(dirname "${downloads_dir}")" --exclude='*.lock' "$(basename "${downloads_dir}")" |
scripts/s3-cache.sh line 75
Quoted 10 lines
scripts/s3-cache.sh new file +10
-0+ zstd -T0 -3 | + aws s3 cp - "${object}" --only-show-errors || + warn "upload failed" + ;; +*) + echo "usage: $0 restore|save" >&2 + exit 1 + ;; +esac +exit 0
Thanks, applied.
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Quoted 150 lines · Jan Kiszka
Quoted 149 lines · Quirin Gylstorff
The runner's native S3 cache fails for uploads larger than 5G as multipart upload is not support by default. As sts access requires a change for each fork/runner we stay for now with self implemented upload script.
Replace the GitLab cache: for build/downloads with a single tar.zst per
arch/kernelstored in S3, restored before and saved after the build.Signed-off-by Quirin Gylstorff <[email protected]>---
Changes v2:
- clean update remove unnecessary code
- add comment to multipart upload in commit messageTested with https://gitlab.com/Xenomai/xenomai-images/-/jobs/18136100219
and https://gitlab.com/Xenomai/xenomai-images/-/jobs/18136323078.gitignore | 1 + ci/lib/gitlab-ci-base.yml | 14 +++++--- scripts/s3-cache.sh | 75 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 4 deletions(-) create mode 100755 scripts/s3-cache.sh.gitignore +1
-0@@ -1,3 +1,4 @@ build isar .config.yaml* +.s3-cache/ci/lib/gitlab-ci-base.yml +10
-4@@ -54,6 +54,14 @@ default: - ./isar/scripts/isar-sstate upload "build/sstate-cache" "${SSTATE_LOCATION}" - ./isar/scripts/isar-sstate info -v "${SSTATE_LOCATION}" +.s3-cache-restore: + script: + - scripts/s3-cache.sh restore + +.s3-cache-save: + script: + - scripts/s3-cache.sh save + .common-config: script: - if [ -n "$ALT_DNS_SERVER" ]; then@@ -71,6 +79,7 @@ default: - build before_script: - !reference [.common-config, script] + - !reference [.s3-cache-restore, script] - !reference [.sstate-prepare, script] script: - echo "Building kas.yaml:kas/board/${TARGET}.yaml${XENOMAI_BUILD_OPTION}${LINUX_BUILD_OPTION}${BUILD_OPTIONS}:kas/opt/ci.yaml"@@ -80,10 +89,7 @@ default: after_script: - !reference [.sstate-lint, script] - !reference [.sstate-upload, script] - cache: - - key: downloads-${CACHE_ARCH}-${CACHE_KERNEL} - paths: - - build/downloads + - !reference [.s3-cache-save, script] .build-qemu-rules: &build-qemu-rules - if: '$KERNEL_VERSION == $KERNEL_VERSION_WITH_QEMU'scripts/s3-cache.sh new file +69
-0@@ -0,0 +1,75 @@ +#!/bin/bash + +# +# Xenomai Real-Time System +# +# Copyright (c) Siemens AG, 2026 +# +# SPDX-License-Identifier: MIT +# +# Best-effort build/downloads cache in S3, authenticated with the static +# AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY CI/CD variables. +# Usage: s3-cache.sh restore|save +# +# Defaults are built in; each can be overridden by a CI/CD variable: +# AWS_CACHE_BUCKET, AWS_REGION +# Provided by the job: CACHE_ARCH, CACHE_KERNEL +# Any failure only warns: the cache must never fail a build. +set -o pipefail + +action="$1" +downloads_dir="${CACHE_DOWNLOADS_DIR:-build/downloads}" +state_dir="${CI_PROJECT_DIR:-.}/.s3-cache" + +warn() { echo "s3-cache: $*" >&2; } + +AWS_CACHE_BUCKET="${AWS_CACHE_BUCKET:-siemens-xenomai-gitlab-cache}" +AWS_REGION="${AWS_REGION:-eu-central-1}" + +for t in aws zstd tar; do + command -v "${t}" >/dev/null || { warn "${t} not found - cache disabled"; exit 0; } +done + +key="xenomai-cache/project/${CI_PROJECT_ID}/downloads-${CACHE_ARCH}-${CACHE_KERNEL}.tar.zst" +object="s3://${AWS_CACHE_BUCKET}/${key}" + +fingerprint() { + (cd "${downloads_dir}" 2>/dev/null && + find . -type f ! -name '*.lock' -printf '%P %s\n' | LC_ALL=C sort | sha256sum | cut -d' ' -f1) +} + +case "${action}" in +restore) + if ! aws s3api head-object --bucket "${AWS_CACHE_BUCKET}" --key "${key}" >/dev/null 2>&1; then + warn "no cache object ${object} - cold start" + exit 0 + fi + mkdir -p "${downloads_dir}" "${state_dir}" + echo "s3-cache: restoring ${object}" + if aws s3 cp "${object}" - --only-show-errors | + zstd -d -T0 | tar -x -C "$(dirname "${downloads_dir}")"; then + fingerprint > "${state_dir}/fingerprint" 2>/dev/null + else + warn "restore failed - continuing with a possibly partial downloads dir" + rm -f "${state_dir}/fingerprint" + fi + ;; +save) + [ -d "${downloads_dir}" ] || { warn "no ${downloads_dir} - not saving"; exit 0; } + new=$(fingerprint) + if [ -f "${state_dir}/fingerprint" ] && [ "${new}" = "$(cat "${state_dir}/fingerprint")" ]; then + warn "downloads unchanged - not saving" + exit 0 + fi + echo "s3-cache: saving ${object}" + tar -c -C "$(dirname "${downloads_dir}")" --exclude='*.lock' "$(basename "${downloads_dir}")" | + zstd -T0 -3 | + aws s3 cp - "${object}" --only-show-errors || + warn "upload failed" + ;;
Quoted 9 lines
scripts/s3-cache.sh line 75
Quoted 6 lines
scripts/s3-cache.sh new file +6
-0+*) + echo "usage: $0 restore|save" >&2 + exit 1 + ;; +esac +exit 0Thanks, applied.
BTW, the artifacts pushed the old way, those are purged automatically? Just to avoid storing now useless bits infinitely.
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center