Add SeaweedFS Alpine package build

This commit is contained in:
Joachim Schlöffel
2026-06-07 14:30:21 +02:00
commit ca2db8e206
29 changed files with 1578 additions and 0 deletions

32
scripts/apk/Dockerfile Normal file
View File

@@ -0,0 +1,32 @@
ARG ALPINE_VERSION=3.22
FROM alpine:${ALPINE_VERSION}
ARG BUILDER_UID=1000
ARG BUILDER_GID=1000
RUN apk add --no-cache \
abuild-rootbld \
alpine-sdk \
atools-apkbuild-lint \
bash \
ca-certificates \
doas \
git \
sudo
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 \
&& chgrp abuild /var/cache/distfiles /home/builder/packages \
&& chmod g+w /var/cache/distfiles /home/builder/packages \
&& printf 'permit nopass :wheel\n' > /etc/doas.d/wheel.conf \
&& printf '%%wheel ALL=(ALL) NOPASSWD: ALL\n' > /etc/sudoers.d/wheel
COPY scripts/apk/container-entrypoint.sh /usr/local/bin/alpine-package-entrypoint
RUN chmod +x /usr/local/bin/alpine-package-entrypoint
USER builder
WORKDIR /work
ENTRYPOINT ["/usr/local/bin/alpine-package-entrypoint"]

72
scripts/apk/build.sh Executable file
View File

@@ -0,0 +1,72 @@
#!/usr/bin/env bash
set -euo pipefail
command_name="${1:-build}"
requested_arch="${2:-${ALPINE_ARCH:-x86_64}}"
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
alpine_version="${ALPINE_VERSION:-3.22}"
repo_name="${ALPINE_REPO_NAME:-local}"
build_platform="${ALPINE_BUILD_PLATFORM:-linux/amd64}"
validate_arch() {
case "$1" in
x86_64|aarch64) ;;
*) printf 'unsupported Alpine architecture: %s\n' "$1" >&2; return 2 ;;
esac
}
run_for_arch() {
local arch="$1"
local subcommand="$2"
local image_name
validate_arch "${arch}"
image_name="${ALPINE_APK_BUILDER_IMAGE:-seaweedfs-apk-builder:${arch}}"
docker build \
--platform "${build_platform}" \
--build-arg "ALPINE_VERSION=${alpine_version}" \
--build-arg "BUILDER_UID=$(id -u)" \
--build-arg "BUILDER_GID=$(id -g)" \
-f "${repo_root}/scripts/apk/Dockerfile" \
-t "${image_name}" \
"${repo_root}"
docker_args=(--rm --platform "${build_platform}")
if [[ -t 0 && -t 1 ]]; then
docker_args+=(-it)
fi
docker run "${docker_args[@]}" \
-e "ALPINE_ARCH=${arch}" \
-e "CARCH=${arch}" \
-e "ALPINE_REPO_NAME=${repo_name}" \
-e "PACKAGER=${PACKAGER:-Local Builder <local@example.invalid>}" \
-v "${repo_root}:/work" \
-v "${repo_root}/.cache/abuild:/home/builder/.abuild" \
-v "${repo_root}/.cache/apk-distfiles:/var/cache/distfiles" \
-v "${repo_root}/packages:/home/builder/packages" \
"${image_name}" \
"${subcommand}"
}
mkdir -p \
"${repo_root}/.cache/abuild" \
"${repo_root}/.cache/apk-distfiles" \
"${repo_root}/packages"
case "${command_name}" in
build-all)
for arch in ${ALPINE_ARCHES:-x86_64 aarch64}; do
run_for_arch "${arch}" build
done
;;
build|checksum|lint|shell)
run_for_arch "${requested_arch}" "${command_name}"
;;
*)
printf 'unknown command: %s\n' "${command_name}" >&2
printf 'usage: %s [build|build-all|checksum|lint|shell] [x86_64|aarch64]\n' "$0" >&2
exit 2
;;
esac

9
scripts/apk/clean.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
rm -rf \
"${repo_root}/packages" \
"${repo_root}/packaging/alpine/local/seaweedfs/pkg" \
"${repo_root}/packaging/alpine/local/seaweedfs/src"

View File

@@ -0,0 +1,66 @@
#!/usr/bin/env bash
set -euo pipefail
command_name="${1:-build}"
package_dir="${APKBUILD_DIR:-/work/packaging/alpine/local/seaweedfs}"
repo_name="${ALPINE_REPO_NAME:-local}"
arch="${ALPINE_ARCH:-x86_64}"
export CARCH="${CARCH:-$arch}"
export PACKAGER="${PACKAGER:-Local Builder <local@example.invalid>}"
if [[ -n "${PACKAGER_PRIVKEY:-}" ]]; then
export PACKAGER_PRIVKEY
fi
git config --global --add safe.directory /work
mkdir -p /home/builder/.abuild /home/builder/packages "${package_dir}"
if [[ -n "${PACKAGER_PRIVKEY:-}" && ! -f "${PACKAGER_PRIVKEY}" ]]; then
abuild-keygen -a -n
elif ! compgen -G "/home/builder/.abuild/*.rsa" > /dev/null; then
abuild-keygen -a -n
fi
if [[ -z "${PACKAGER_PRIVKEY:-}" && -f /home/builder/.abuild/abuild.conf ]]; then
# shellcheck source=/dev/null
. /home/builder/.abuild/abuild.conf
fi
if [[ -n "${PACKAGER_PRIVKEY:-}" ]]; then
export PACKAGER_PRIVKEY
fi
if [[ -n "${PACKAGER_PRIVKEY:-}" && -f "${PACKAGER_PRIVKEY}.pub" ]]; then
doas cp "${PACKAGER_PRIVKEY}.pub" /etc/apk/keys/
elif compgen -G "/home/builder/.abuild/*.rsa.pub" > /dev/null; then
doas cp /home/builder/.abuild/*.rsa.pub /etc/apk/keys/
fi
case "${command_name}" in
build)
cd "${package_dir}"
abuild -r
mkdir -p "/home/builder/packages/${repo_name}/${arch}"
if [[ -n "${PACKAGER_PRIVKEY:-}" && -f "${PACKAGER_PRIVKEY}.pub" ]]; then
cp "${PACKAGER_PRIVKEY}.pub" "/home/builder/packages/${repo_name}/${arch}/"
elif compgen -G "/home/builder/.abuild/*.rsa.pub" > /dev/null; then
cp /home/builder/.abuild/*.rsa.pub "/home/builder/packages/${repo_name}/${arch}/"
fi
;;
checksum)
cd "${package_dir}"
abuild checksum
;;
lint)
cd "${package_dir}"
apkbuild-lint APKBUILD
;;
shell)
cd "${package_dir}"
exec bash
;;
*)
printf 'unknown command: %s\n' "${command_name}" >&2
printf 'usage: %s [build|checksum|lint|shell]\n' "$0" >&2
exit 2
;;
esac

36
scripts/apk/list-packages.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
repo_dir="${repo_root}/packages/local"
if [[ -n "${ALPINE_ARCH:-}" ]]; then
package_dirs=("${repo_dir}/${ALPINE_ARCH}")
else
package_dirs=("${repo_dir}"/*)
fi
if [[ ! -d "${repo_dir}" || ! -d "${package_dirs[0]}" ]]; then
printf 'missing local repository: packages/local\n' >&2
printf 'run: mise run apk:build-all\n' >&2
exit 1
fi
for package_dir in "${package_dirs[@]}"; do
[[ -d "${package_dir}" ]] || continue
shopt -s nullglob
apks=("${package_dir}"/*.apk)
shopt -u nullglob
if [[ "${#apks[@]}" -eq 0 ]]; then
continue
fi
printf '## %s\n' "$(basename "${package_dir}")"
for apk in "${apks[@]}"; do
printf '### %s\n' "$(basename "${apk}")"
tar -xOf "${apk}" .PKGINFO 2>/dev/null \
| sed -n '/^pkgname =/p;/^pkgver =/p;/^arch =/p;/^depend =/p;/^provides =/p;/^install_if =/p'
done
done

10
scripts/apk/publish-check.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd "${repo_root}"
mise run apk:lint
mise run apk:build-all
mise run apk:packages
mise run apk:smoke

30
scripts/apk/smoke.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
alpine_version="${ALPINE_VERSION:-3.22}"
platform="${ALPINE_BUILD_PLATFORM:-linux/amd64}"
arch="${ALPINE_ARCH:-x86_64}"
packages="${SMOKE_PACKAGES:-seaweedfs seaweedfs-master-openrc seaweedfs-filer-openrc seaweedfs-worker-openrc}"
if [[ ! -d "${repo_root}/packages/local/${arch}" ]]; then
printf 'missing local repository: packages/local/%s\n' "${arch}" >&2
printf 'run: mise run apk:build-all\n' >&2
exit 1
fi
docker run --rm --platform "${platform}" \
-v "${repo_root}/packages/local:/repo:ro" \
"alpine:${alpine_version}" \
sh -lc "
set -e
cp /repo/${arch}/*.rsa.pub /etc/apk/keys/
echo /repo >> /etc/apk/repositories
apk update >/dev/null
apk add ${packages} >/dev/null
weed version
ls -1 /etc/seaweedfs
if ls /etc/init.d/seaweedfs.* >/dev/null 2>&1; then
ls -1 /etc/init.d/seaweedfs.* | sort
fi
"