Cache Rust build artifacts for Alpine packages
Some checks failed
Build Alpine Packages / build-and-publish (push) Has been cancelled

This commit is contained in:
Joachim Schlöffel
2026-06-09 10:47:17 +02:00
parent 11ef6456af
commit 50e8eaa62a
5 changed files with 69 additions and 5 deletions

View File

@@ -25,10 +25,15 @@ jobs:
PACKAGE_USER: "${{ secrets.PACKAGE_USER }}"
PACKAGE_TOKEN: "${{ secrets.PACKAGE_TOKEN }}"
PACKAGER: "Joachim Schlöffel <me@joachim-schloeffel.com>"
CARGO_HOME: "/cache/public-alpine-packages/greptimedb/cargo"
RUSTUP_HOME: "/cache/public-alpine-packages/greptimedb/rustup"
CARGO_TARGET_DIR: "/cache/public-alpine-packages/greptimedb/target"
steps:
- name: Prepare Environment
run: |
apk add --no-cache --update abuild-rootbld alpine-sdk atools-apkbuild-lint bash ca-certificates curl doas git nodejs sudo tar
mkdir -p "$CARGO_HOME" "$RUSTUP_HOME" "$CARGO_TARGET_DIR"
chown 1000:1000 /cache /cache/public-alpine-packages /cache/public-alpine-packages/greptimedb "$CARGO_HOME" "$RUSTUP_HOME" "$CARGO_TARGET_DIR"
- name: Checkout
uses: actions/checkout@v3

View File

@@ -241,6 +241,13 @@ ALPINE_PACKAGE=greptimedb mise run apk:build
ALPINE_PACKAGE=greptimedb SKIP_BUILD=1 mise run apk:test-install
```
Docker-backed build tasks keep Cargo registry, Rustup, and Cargo target caches in named Docker volumes. The default volume scope is derived from the Git remote owner/repository and is split by package and architecture. Override it when needed:
```sh
ALPINE_APK_CACHE_SCOPE=public-alpine-packages ALPINE_PACKAGE=greptimedb mise run apk:build
ALPINE_APK_CACHE_PREFIX=alpine-apk-ci ALPINE_PACKAGE=greptimedb mise run apk:build
```
Use the test shell to inspect the package in Alpine with the current build
installed:

View File

@@ -54,8 +54,9 @@ source="
_rust_toolchain="nightly-2026-03-21"
_cargo_profile="nightly"
export CARGO_HOME="$srcdir/cargo"
export RUSTUP_HOME="$srcdir/rustup"
export CARGO_HOME="${CARGO_HOME:-$srcdir/cargo}"
export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$builddir/target}"
export RUSTUP_HOME="${RUSTUP_HOME:-$srcdir/rustup}"
export CARGO_BUILD_JOBS="${CARGO_BUILD_JOBS:-2}"
export CARGO_PROFILE_NIGHTLY_CODEGEN_UNITS="${CARGO_PROFILE_NIGHTLY_CODEGEN_UNITS:-16}"
export CARGO_PROFILE_NIGHTLY_DEBUG="${CARGO_PROFILE_NIGHTLY_DEBUG:-false}"
@@ -80,11 +81,11 @@ build() {
}
check() {
"$builddir"/target/"$_cargo_profile"/greptime --version
"$CARGO_TARGET_DIR"/"$_cargo_profile"/greptime --version
}
package() {
install -Dm755 "$builddir"/target/"$_cargo_profile"/greptime \
install -Dm755 "$CARGO_TARGET_DIR"/"$_cargo_profile"/greptime \
"$pkgdir"/usr/bin/greptime
local _config
for _config in datanode flownode frontend metasrv standalone; do

View File

@@ -18,9 +18,15 @@ RUN addgroup -g "${BUILDER_GID}" builder \
&& adduser -D -u "${BUILDER_UID}" -G builder builder \
&& addgroup builder abuild \
&& addgroup builder wheel \
&& mkdir -p /var/cache/distfiles /home/builder/packages \
&& mkdir -p \
/var/cache/distfiles \
/home/builder/.cache/cargo \
/home/builder/.cache/cargo-target \
/home/builder/.cache/rustup \
/home/builder/packages \
&& chgrp abuild /var/cache/distfiles /home/builder/packages \
&& chmod g+w /var/cache/distfiles /home/builder/packages \
&& chown -R builder:builder /home/builder/.cache \
&& printf 'permit nopass :wheel\n' > /etc/doas.d/wheel.conf \
&& printf '%%wheel ALL=(ALL) NOPASSWD: ALL\n' > /etc/sudoers.d/wheel

View File

@@ -19,6 +19,39 @@ if [[ "${builder_gid}" == "0" ]]; then
builder_gid=1000
fi
cache_scope_from_remote() {
local remote
local path
local owner
local repo
remote="$(git -C "${repo_root}" remote get-url origin 2>/dev/null || true)"
remote="${remote%.git}"
case "${remote}" in
ssh://*/*/*)
path="${remote#ssh://*/}"
;;
http://*/*/*|https://*/*/*)
path="${remote#*://*/}"
;;
*:*)
path="${remote#*:}"
;;
*)
path="$(basename "${repo_root}")"
;;
esac
owner="$(basename "$(dirname "${path}")")"
repo="$(basename "${path}")"
if [[ -n "${owner}" && "${owner}" != "." && -n "${repo}" ]]; then
printf '%s-%s\n' "${owner}" "${repo}" | sed 's/[^A-Za-z0-9_.-]/-/g'
else
printf '%s\n' "$(basename "${repo_root}")" | sed 's/[^A-Za-z0-9_.-]/-/g'
fi
}
validate_arch() {
case "$1" in
x86_64|aarch64) ;;
@@ -32,11 +65,17 @@ run_for_arch() {
local package_dir="$3"
local image_name
local container_package_dir
local package_name
local cache_scope
local cache_prefix
validate_arch "${arch}"
apk_validate_package_dir "${package_dir}"
package_name="$(apk_package_name "${package_dir}")"
container_package_dir="$(apk_container_package_dir "${repo_root}" "${package_dir}")"
image_name="${ALPINE_APK_BUILDER_IMAGE:-alpine-apk-builder:${arch}}"
cache_scope="${ALPINE_APK_CACHE_SCOPE:-$(cache_scope_from_remote)}"
cache_prefix="${ALPINE_APK_CACHE_PREFIX:-alpine-apk}-${cache_scope}-${package_name}-${arch}"
docker build \
--platform "${build_platform}" \
@@ -57,7 +96,13 @@ run_for_arch() {
-e "CARCH=${arch}" \
-e "ALPINE_REPO_NAME=${repo_name}" \
-e "APKBUILD_DIR=${container_package_dir}" \
-e "CARGO_HOME=/home/builder/.cache/cargo" \
-e "CARGO_TARGET_DIR=/home/builder/.cache/cargo-target" \
-e "PACKAGER=${PACKAGER:-Joachim Schlöffel <me@joachim-schloeffel.com>}" \
-e "RUSTUP_HOME=/home/builder/.cache/rustup" \
-v "${cache_prefix}-cargo:/home/builder/.cache/cargo" \
-v "${cache_prefix}-cargo-target:/home/builder/.cache/cargo-target" \
-v "${cache_prefix}-rustup:/home/builder/.cache/rustup" \
-v "${repo_root}:/work" \
-v "${repo_root}/.cache/abuild:/home/builder/.abuild" \
-v "${repo_root}/.cache/apk-distfiles:/var/cache/distfiles" \