mirror of
https://github.com/armbian/build.git
synced 2025-09-15 10:41:12 +02:00
> tl-dr: > - maximize OCI cache hit ratio across nightlies/releases/PRs/etc; > - publish simple `Version:`'s that don't include a crazy hash in repo and images > - introduce `output/packages-hashed` directory > - radically change the `output/debs` directory structure - simplify artifact's `prepare_version()` method for `deb` and `deb-tar` artifacts: - `artifact_base_dir` and `artifact_final_file` will now be auto-calculated; thus removed from each artifact (except `rootfs`) - `artifact_deb_repo` ("global", "jammy", "bookworm") is now required; "global" means common across all RELEASES - `artifact_deb_arch` is now required, "all" is arch-independent, otherwise use `${ARCH}` - `artifact_map_debs` is now auto-calculated based on the above, and shouldn't be specified manually - `artifact_final_version_reversioned` is optional, and can force the final version of the artifact (specific for the `base-files` case) - artifacts that need special handling for reversioning can add function names to `artifact_debs_reversion_functions` array (`base-files` and `bsp-cli` cases) - artifacts `prepare_version()` should set `artifact_version`, but _never_ include it in other variables; `artifact_version` is now changed by framework after `prepare_version()` returns - no longer use/refer/mention `${REVISION}` when building packages. All packages should be `${REVISION}`-agnostic. - `${REVISION}` (actually, `artifact_final_version_reversioned`) will be automatically swapped in the `control` file during reversioning - `fakeroot_dpkg_deb_build()` now takes exactly two arguments: the directory to pack, and the deb ID (key of `artifact_map_packages` dict); add this change in all the artifact's code for this - `obtain_complete_artifact()`: - automatically adds `-Rxxxx` "revisioning-hash" to `artifact_version`, by hashing the revisioning functions and any `artifact_debs_reversion_functions` set - calculates more complex subdirectory paths for both the `output/packages-hashed` and `output/debs`/`output/debs-beta` directories - with the new subdirectories we can be sure a re-version is already done correctly and can skip it (eg, for partial `download-debs` re-runs) - in the future we can automatically clean/remove old versions that are no longer relevant based on the dir structure - exports a lot more information to JSON, including the new subdirectory paths - comment-out code that implemented `skip_unpack_if_found_in_caches`, I'm very unsure why we had this in the first place - `obtain_artifact_from_remote_cache()` - for `deb` type artifacts, OCI won't preserve the subdirectory structure, so move downloaded files to the correct subdirectory manually - this is not needed for `deb-tar`, since that can preserve the dir structure itself - introduce `artifacts-reversion.sh` and its main function `artifact_reversion_for_deployment()` - this has the logic for reversioning .deb's, by `ar`-unpacking them, changing `control.tar` (and possibly `data.tar`), handling `.xz` compression, etc. - also handles hashing those functions, for consistency. Any changes in reversioning code actually change the artifact itself so we're not caught by surprise - by default, it changes `control` file only: - replace `Version:` (which is the hash-version originally) with `artifact_final_version_reversioned` (which is mostly just `${REVISION}`) - add a custom field `Armbian-Original-Hash:` with the original hash-version - `artifact_reversion_for_deployment()` is called by - new CLI wrapper `cli_obtain_complete_artifact()`, used for CLI building of specific artifact, but also for `download-artifact` - `build_artifact_for_image()` used during image build - `armbian-bsp-cli-deb.sh`: move `${REVISION}` related stuff from the main package build to new reversioning functions. - `artifact-armbian-base-files.sh`: move `${REVISION}` related stuff from the main package build to new reversioning functions. - `kernel`: - add some custom fields to `DEBIAN/control`: - `Armbian-Kernel-Version:` / `Armbian-Kernel-Version-Family:` (for future use: cleanup of usage of `Source: ` field which should be removed) - declutter the `Description:` field, moving long description out of the first line - obtain `IMAGE_INSTALLED_KERNEL_VERSION` from the reversioned deb (this is still a hack and has not been fixed) - `uboot`: - declutter the `Description:` field, moving long description out of the first line - use the reversioned .deb when deploying u-boot to the image - `main_default_build_packages()` now stores reversioned values and complete paths to reversioned .deb's - `list_installed_packages()` now compares custom field `Armbian-Original-Hash: `, and not the `Version:` to make sure debs in the image are the ones we want - `install_artifact_deb_chroot()` is a new wrapper around `install_deb_chroot()` for easy handling of reversioned debs - use it everywhere `install_deb_chroot()` was used in `distro-agnostic.sh` and `distro-specific.sh`
123 lines
6.3 KiB
Bash
123 lines
6.3 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
|
|
#
|
|
# This file is a part of the Armbian Build Framework
|
|
# https://github.com/armbian/build/
|
|
|
|
function apt_purge_unneeded_packages_and_clean_apt_caches() {
|
|
# remove packages that are no longer needed. rootfs cache + uninstall might have leftovers.
|
|
display_alert "No longer needed packages" "purge" "info"
|
|
chroot_sdcard_apt_get autoremove
|
|
|
|
declare dir_var_lib_apt_lists="/var/lib/apt/lists"
|
|
declare dir_var_cache_apt="/var/cache/apt"
|
|
declare -i dir_var_cache_apt_file_count dir_var_lib_apt_lists_file_count
|
|
|
|
# Now, let's list what is under ${SDCARD}/var/cache/apt -- it should be empty. If it isn't, warn, and clean it up.
|
|
dir_var_cache_apt_file_count="$(find "${SDCARD}${dir_var_cache_apt}" -type f | wc -l)"
|
|
if [[ "${dir_var_cache_apt_file_count}" -gt 1 ]]; then # there is sometimes at least one file, the lock file
|
|
display_alert "SDCARD ${dir_var_cache_apt} is not empty" "${dir_var_cache_apt} :: ${dir_var_cache_apt_file_count} files" "wrn"
|
|
run_host_command_logged ls -lahtR "${SDCARD}${dir_var_cache_apt}"
|
|
wait_for_disk_sync "after listing ${SDCARD}${dir_var_cache_apt}"
|
|
else
|
|
display_alert "SDCARD ${dir_var_cache_apt} is empty" "${dir_var_cache_apt} :: ${dir_var_cache_apt_file_count} files" "debug"
|
|
fi
|
|
|
|
# attention: this is _very different_ from `chroot_sdcard_apt_get clean` (which would clean the cache)
|
|
chroot_sdcard apt-get clean
|
|
wait_for_disk_sync "after apt-get clean"
|
|
|
|
# Also clean ${SDCARD}/var/lib/apt/lists; this is where the package lists are stored.
|
|
dir_var_lib_apt_lists_file_count="$(find "${SDCARD}${dir_var_lib_apt_lists}" -type f | wc -l)"
|
|
if [[ "${dir_var_lib_apt_lists_file_count}" -gt 1 ]]; then # there is sometimes at least one file, the lock file
|
|
display_alert "SDCARD ${dir_var_lib_apt_lists} is not empty" "${dir_var_lib_apt_lists} :: ${dir_var_lib_apt_lists_file_count} files" "wrn"
|
|
run_host_command_logged ls -lahtR "${SDCARD}${dir_var_lib_apt_lists}"
|
|
wait_for_disk_sync "after listing ${SDCARD}${dir_var_cache_apt}"
|
|
else
|
|
display_alert "SDCARD ${dir_var_lib_apt_lists} is empty" "${dir_var_lib_apt_lists} :: ${dir_var_lib_apt_lists_file_count} files" "debug"
|
|
fi
|
|
|
|
# Either way, clean it away, we don't wanna ship those lists on images or rootfs.
|
|
run_host_command_logged rm -rf "${SDCARD}${dir_var_lib_apt_lists}"
|
|
wait_for_disk_sync "after cleaning ${SDCARD}${dir_var_lib_apt_lists}"
|
|
}
|
|
|
|
function apt_lists_copy_from_host_to_image_and_update() {
|
|
display_alert "Copying host-side apt list cache into image" "apt-get update and clean image-side" "info"
|
|
|
|
declare -i local_apt_cache_lists_count
|
|
if [[ "${LOCAL_APT_CACHE_INFO[USE]}" == "yes" ]]; then
|
|
# If using a host-side local cache, copy the lists into the image...
|
|
run_host_command_logged mkdir -pv "${LOCAL_APT_CACHE_INFO[SDCARD_LISTS_DIR]}"
|
|
display_alert "Copying host-side local apt list cache dir" "${LOCAL_APT_CACHE_INFO[SDCARD_LISTS_DIR]}" "debug"
|
|
run_host_command_logged cp -pr "${LOCAL_APT_CACHE_INFO[HOST_LISTS_DIR]}"/* "${LOCAL_APT_CACHE_INFO[SDCARD_LISTS_DIR]}"/
|
|
|
|
# Count how many files we have in the lists dir.
|
|
local_apt_cache_lists_count="$(ls -1 "${LOCAL_APT_CACHE_INFO[SDCARD_LISTS_DIR]}" | wc -l)"
|
|
display_alert "After copying host-side cache into image" "${local_apt_cache_lists_count} files" "info"
|
|
fi
|
|
|
|
# ...and update the lists in the image; this makes sure we're not shipping stale lists. also clean.
|
|
# Attention: this is NOT using `chroot_sdcard_apt_get_update` or any `chroot_sdcard_apt_get` variant,
|
|
# since would actually mount the lists from the host, which is not what we want.
|
|
display_alert "Updating apt lists in image" "apt-get update and clean" "info"
|
|
chroot_sdcard apt-get -y -o "APT::Get::List-Cleanup=1" -o "APT::Clean-Installed=1" update
|
|
chroot_sdcard apt-get -y -o "APT::Get::List-Cleanup=1" -o "APT::Clean-Installed=1" clean
|
|
|
|
local_apt_cache_lists_count="$(ls -1 "${LOCAL_APT_CACHE_INFO[SDCARD_LISTS_DIR]}" | wc -l)"
|
|
display_alert "After updating and cleaning image apt list cache" "${local_apt_cache_lists_count} files" "info"
|
|
}
|
|
|
|
# this is called:
|
|
# 1) install_deb_chroot "${DEB_STORAGE}/somethingsomething.deb" (yes, it's always ${DEB_STORAGE})
|
|
function install_deb_chroot() {
|
|
local package="$1"
|
|
local variant="$2"
|
|
local transfer="$3"
|
|
local install_target="${package}"
|
|
local log_extra=" from repository"
|
|
local package_filename
|
|
package_filename="$(basename "${package}")"
|
|
|
|
# For the local case.
|
|
if [[ "${variant}" != "remote" ]]; then
|
|
log_extra=""
|
|
fi
|
|
display_alert "Installing${log_extra}: ${package}" "${package_filename}" "debinstall" # This needs its own level
|
|
|
|
if [[ "${variant}" != "remote" ]]; then
|
|
# @TODO: this can be sped up significantly by mounting debs readonly directly in chroot /root/debs and installing from there
|
|
# also won't require cleanup later
|
|
|
|
install_target="/root/${package_filename}"
|
|
if [[ ! -f "${SDCARD}${install_target}" ]]; then
|
|
display_alert "Copying ${package_filename}" "'${package}' -> '${SDCARD}${install_target}'" "debug"
|
|
run_host_command_logged cp -pv "${package}" "${SDCARD}${install_target}"
|
|
fi
|
|
fi
|
|
|
|
# install in chroot via apt-get, not dpkg, so dependencies are also installed from repo if needed.
|
|
declare -g if_error_detail_message="Installation of $install_target failed ${BOARD} ${RELEASE} ${BUILD_DESKTOP} ${LINUXFAMILY}"
|
|
declare -a extra_apt_envs=()
|
|
extra_apt_envs+=("ARMBIAN_IMAGE_BUILD_BOOTFS_TYPE=${BOOTFS_TYPE:-"unset"}") # used by package postinst scripts to bevahe
|
|
DONT_MAINTAIN_APT_CACHE="yes" chroot_sdcard_apt_get --no-install-recommends install "${install_target}" # don't auto-maintain apt cache when installing from packages.
|
|
unset extra_apt_envs
|
|
|
|
# IMPORTANT! Do not use short-circuit above as last statement in a function, since it determines the result of the function.
|
|
return 0
|
|
}
|
|
|
|
function install_artifact_deb_chroot() {
|
|
declare deb_name="$1"
|
|
declare -A -g image_artifacts_debs_reversioned # global associative array
|
|
declare revisioned_deb_rel_path="${image_artifacts_debs_reversioned["${deb_name}"]}"
|
|
if [[ -z "${revisioned_deb_rel_path}" ]]; then
|
|
exit_with_error "No revisioned deb path found for '${deb_name}'"
|
|
fi
|
|
display_alert "Installing artifact deb" "${deb_name} :: ${revisioned_deb_rel_path}" "debug"
|
|
install_deb_chroot "${DEB_STORAGE}/${revisioned_deb_rel_path}"
|
|
}
|