armbian_build/lib/functions/cli/cli-artifact.sh
Ricardo Pardini 622ef30f3c adapt obtain_complete_artifact() and friends to new reversioned scheme; introduce UPLOAD_TO_OCI_ONLY=yes for deploying to remote cache
> tl-dr: only deploys to remote OCI if `UPLOAD_TO_OCI_ONLY=yes`; stop leaving junk behind in local cache in many situations

- simplify CLI artifact building parameters and behaviour
    - `ARTIFACT_USE_CACHE` is now deprecated, and its behaviour is the default
    - for _any_ uploading to OCI to occur, `UPLOAD_TO_OCI_ONLY=yes` **must** be present; in this case, reversioning is not done
    - `FORCE_ARTIFACTS_DOWNLOAD` is completely removed (use `download-artifact` instead)
    - `cli_obtain_complete_artifact()`'s and `build_artifact_for_image()`'s reversioning is now moved to common `obtain_complete_artifact()`
- `standard_artifact_reversion_for_deployment()`:
    - check for hashed deb existence only if reversioned does not exist
    - touch the reversioned file if it already exists; helps to clean up junk later
    - delete hashed version after reversioning, so we don't leave trash behind
        - unless in `download-artifact` mode, which `touch`es the hashed version
        - we can later delete old files from packages-hashed to keep junk under control
- refactor `obtain_complete_artifact()`
    - extract function `artifact_dump_json_info()` since obtain is large enough already
    - when deploying to remote, always ignore all local and remote caches
    - introduce `artifact_is_available_in_revisioned_local_cache()`
        - if not deploying to remote, and revisioned cache exists, use it directly
        - if deploying to remote, reversioned is not checked and not created
    - if deploying to remote, force `DEB_COMPRESS=xz`
    - if deploying to remote, completely remove the local cache base dir after upload is done (no more junk leftover)
2023-08-12 09:58:32 +02:00

70 lines
2.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 cli_artifact_pre_run() {
case "${ARMBIAN_COMMAND}" in
download-artifact)
display_alert "download-only mode:" "won't build '${WHAT}'" "info"
declare -g DONT_BUILD_ARTIFACTS="${WHAT}"
declare -g KEEP_HASHED_DEB_ARTIFACTS="yes"
;;
esac
initialize_artifact "${WHAT}"
# Run the pre run adapter
artifact_cli_adapter_pre_run
}
function cli_artifact_run() {
: "${chosen_artifact:?chosen_artifact is not set}"
: "${chosen_artifact_impl:?chosen_artifact_impl is not set}"
if [[ "${CONFIG_DEFS_ONLY}" != "yes" ]]; then
# Make sure ORAS tooling is installed before starting.
run_tool_oras
fi
display_alert "artifact" "${chosen_artifact}" "debug"
display_alert "artifact" "${chosen_artifact} :: ${chosen_artifact_impl}()" "debug"
declare -g artifact_version_requires_aggregation="no" # marker
artifact_cli_adapter_config_prep # only if in cli.
# if asked by _config_prep to aggregate, and HOSTRELEASE is not set, obtain it.
if [[ "${artifact_version_requires_aggregation}" == "yes" ]] && [[ -z "${HOSTRELEASE}" ]]; then
obtain_hostrelease_only # Sets HOSTRELEASE
fi
declare deploy_to_remote="no"
case "${ARMBIAN_COMMAND}" in
download-artifact)
display_alert "Running in download-artifact mode" "download-artifact" "ext"
;;
*)
# Warn of deprecation...
if [[ "${ARTIFACT_USE_CACHE}" == "yes" ]]; then
display_alert "deprecated!" "ARTIFACT_USE_CACHE=yes is deprecated, its behaviour is now the default." "warn"
fi
# If UPLOAD_TO_OCI_ONLY=yes is explicitly set; deploy to remote.
if [[ "${UPLOAD_TO_OCI_ONLY}" == "yes" ]]; then
display_alert "UPLOAD_TO_OCI_ONLY=yes is set" "UPLOAD_TO_OCI_ONLY=yes; ignoring local cache and deploying to remote" "info"
deploy_to_remote="yes"
fi
;;
esac
if [[ "${ARTIFACT_BUILD_INTERACTIVE}" == "yes" ]]; then # Set by `kernel-config`, `kernel-patch`, `uboot-config`, `uboot-patch`, etc.
display_alert "Running artifact build in interactive mode" "log file will be incomplete" "info"
do_with_default_build obtain_complete_artifact
else
do_with_default_build obtain_complete_artifact < /dev/null
fi
}