Optimize Alpine packaging workflow
Build Alpine Packages / build-and-publish (v3.24, 3.24) (push) Successful in 2h16m43s
Build Alpine Packages / build-and-publish (v3.24, 3.24) (push) Successful in 2h16m43s
This commit is contained in:
+24
-11
@@ -19,6 +19,8 @@ if [[ "${builder_gid}" == "0" ]]; then
|
||||
builder_gid=1000
|
||||
fi
|
||||
|
||||
image_name="${ALPINE_APK_BUILDER_IMAGE:-alpine-apk-builder:${alpine_version}-${builder_uid}-${builder_gid}}"
|
||||
|
||||
cache_scope_from_remote() {
|
||||
local remote
|
||||
local path
|
||||
@@ -63,7 +65,6 @@ run_for_arch() {
|
||||
local arch="$1"
|
||||
local subcommand="$2"
|
||||
local package_dir="$3"
|
||||
local image_name
|
||||
local container_package_dir
|
||||
local package_name
|
||||
local cache_scope
|
||||
@@ -73,19 +74,9 @@ run_for_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}" \
|
||||
--build-arg "ALPINE_VERSION=${alpine_version}" \
|
||||
--build-arg "BUILDER_UID=${builder_uid}" \
|
||||
--build-arg "BUILDER_GID=${builder_gid}" \
|
||||
-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)
|
||||
@@ -111,11 +102,33 @@ run_for_arch() {
|
||||
"${subcommand}"
|
||||
}
|
||||
|
||||
build_builder_image() {
|
||||
docker build \
|
||||
--platform "${build_platform}" \
|
||||
--build-arg "ALPINE_VERSION=${alpine_version}" \
|
||||
--build-arg "BUILDER_UID=${builder_uid}" \
|
||||
--build-arg "BUILDER_GID=${builder_gid}" \
|
||||
-f "${repo_root}/scripts/apk/Dockerfile" \
|
||||
-t "${image_name}" \
|
||||
"${repo_root}"
|
||||
}
|
||||
|
||||
mkdir -p \
|
||||
"${repo_root}/.cache/abuild" \
|
||||
"${repo_root}/.cache/apk-distfiles" \
|
||||
"${repo_root}/packages"
|
||||
|
||||
case "${command_name}" in
|
||||
build-all|build|checksum|lint|shell) ;;
|
||||
*)
|
||||
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
|
||||
|
||||
build_builder_image
|
||||
|
||||
case "${command_name}" in
|
||||
build-all)
|
||||
while IFS= read -r package_dir; do
|
||||
|
||||
@@ -72,10 +72,8 @@ while IFS= read -r package_dir; do
|
||||
|
||||
printf 'Building %s for %s\n' "$(basename "${package_dir}")" "${arch}"
|
||||
(
|
||||
export ALPINE_ARCH="${arch}"
|
||||
export CARCH="${arch}"
|
||||
cd "${package_dir}"
|
||||
abuild -r
|
||||
ALPINE_ARCH="${arch}" CARCH="${arch}" abuild -r
|
||||
)
|
||||
|
||||
mkdir -p "${REPODEST}/${repo_name}/${arch}"
|
||||
|
||||
@@ -70,7 +70,7 @@ changed_packages() {
|
||||
mark_all_packages "shared build logic changed"
|
||||
return
|
||||
;;
|
||||
packaging/alpine/local/*/APKBUILD)
|
||||
packaging/alpine/local/*)
|
||||
package="${changed_path#packaging/alpine/local/}"
|
||||
package="${package%%/*}"
|
||||
selected["${package}"]=1
|
||||
@@ -231,8 +231,7 @@ sync_cache() {
|
||||
|
||||
prune_stale_apks
|
||||
mkdir -p "${cache_root}"
|
||||
find "${cache_root}" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
|
||||
cp -a "${repo_dest}/." "${cache_root}/"
|
||||
rsync -a --delete "${repo_dest}/" "${cache_root}/"
|
||||
printf 'Updated Alpine package repository cache at %s\n' "${cache_root}"
|
||||
}
|
||||
|
||||
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
|
||||
shellcheck \
|
||||
"${repo_root}"/scripts/apk/*.sh \
|
||||
"${repo_root}"/packaging/alpine/local/*/scripts/*.sh
|
||||
@@ -107,7 +107,7 @@ apk_package_apk_names() {
|
||||
local subpackage
|
||||
local subpackages
|
||||
export CARCH="${arch}"
|
||||
cd "${package_dir}"
|
||||
cd "${package_dir}" || exit 1
|
||||
# shellcheck source=/dev/null
|
||||
. ./APKBUILD
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
cd "${repo_root}"
|
||||
mise run apk:outdated
|
||||
mise run apk:lint
|
||||
mise run apk:lint-shell
|
||||
mise run apk:build-all
|
||||
mise run apk:packages
|
||||
mise run apk:smoke
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
ARG ALPINE_VERSION=3.24
|
||||
FROM alpine:${ALPINE_VERSION}
|
||||
|
||||
RUN apk add --no-cache bash openrc
|
||||
@@ -10,6 +10,7 @@ arch="${ALPINE_ARCH:-x86_64}"
|
||||
platform="${ALPINE_TEST_PLATFORM:-linux/amd64}"
|
||||
repo_dir="${repo_root}/packages/${repo_name}/${arch}"
|
||||
runtime_mode="${ALPINE_RUNTIME_TEST_MODE:-auto}"
|
||||
runtime_image="${ALPINE_RUNTIME_TEST_IMAGE:-alpine-apk-runtime-test:${alpine_version}}"
|
||||
|
||||
validate_repo() {
|
||||
if [[ ! -d "${repo_dir}" ]]; then
|
||||
@@ -66,10 +67,9 @@ run_hook_docker() {
|
||||
-e "PACKAGE_NAME=${package_name}" \
|
||||
-v "${repo_root}:/work:ro" \
|
||||
-v "${repo_root}/packages/${repo_name}:/repo:ro" \
|
||||
"alpine:${alpine_version}" \
|
||||
"${runtime_image}" \
|
||||
sh -lc '
|
||||
set -e
|
||||
apk add --no-cache bash openrc >/dev/null
|
||||
cp "/repo/${ALPINE_ARCH}"/*.rsa.pub /etc/apk/keys/
|
||||
printf "%s\n" /repo >> /etc/apk/repositories
|
||||
apk update
|
||||
@@ -79,6 +79,15 @@ run_hook_docker() {
|
||||
'
|
||||
}
|
||||
|
||||
build_runtime_image() {
|
||||
docker build \
|
||||
--platform "${platform}" \
|
||||
--build-arg "ALPINE_VERSION=${alpine_version}" \
|
||||
-f "${repo_root}/scripts/apk/runtime-test.Dockerfile" \
|
||||
-t "${runtime_image}" \
|
||||
"${repo_root}"
|
||||
}
|
||||
|
||||
validate_repo
|
||||
|
||||
case "${runtime_mode}" in
|
||||
@@ -99,6 +108,8 @@ esac
|
||||
|
||||
if [[ "${runtime_mode}" == "direct" ]]; then
|
||||
prepare_direct_runtime
|
||||
else
|
||||
build_runtime_image
|
||||
fi
|
||||
|
||||
while IFS= read -r package_dir; do
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
apk_test_install_run() {
|
||||
local repo_root="$1"
|
||||
local package_name="$2"
|
||||
local package_version="$3"
|
||||
local alpine_version="${ALPINE_VERSION:-3.24}"
|
||||
local arch="${ALPINE_ARCH:-x86_64}"
|
||||
local repository_url="${ALPINE_REPOSITORY_URL:-}"
|
||||
local repository_key_url="${ALPINE_REPOSITORY_KEY_URL:-}"
|
||||
local platform
|
||||
local test_command
|
||||
|
||||
case "${arch}" in
|
||||
x86_64) platform="${ALPINE_TEST_PLATFORM:-linux/amd64}" ;;
|
||||
aarch64) platform="${ALPINE_TEST_PLATFORM:-linux/arm64}" ;;
|
||||
*)
|
||||
printf 'unsupported Alpine architecture: %s\n' "${arch}" >&2
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -z "${repository_url}" && "${SKIP_BUILD:-0}" != "1" ]]; then
|
||||
ALPINE_PACKAGE="${package_name}" "${repo_root}/scripts/apk/build.sh" build "${arch}"
|
||||
fi
|
||||
|
||||
if [[ -z "${repository_url}" && ! -d "${repo_root}/packages/local/${arch}" ]]; then
|
||||
printf 'missing local repository: packages/local/%s\n' "${arch}" >&2
|
||||
printf 'run: ALPINE_PACKAGE=%s mise run apk:build\n' "${package_name}" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
test_command="$(cat)"
|
||||
docker run --rm --platform "${platform}" \
|
||||
-e "ALPINE_ARCH=${arch}" \
|
||||
-e "PACKAGE_NAME=${package_name}" \
|
||||
-e "PACKAGE_VERSION=${package_version}" \
|
||||
-e "ALPINE_REPOSITORY_URL=${repository_url}" \
|
||||
-e "ALPINE_REPOSITORY_KEY_URL=${repository_key_url}" \
|
||||
-v "${repo_root}/packages/local:/repo:ro" \
|
||||
"alpine:${alpine_version}" \
|
||||
sh -lc "${test_command}"
|
||||
}
|
||||
Reference in New Issue
Block a user