armbian-build/lib/functions/cli/cli-requirements.sh
Igor Pecovnik 882d7e3dfd docker: add automatic image pull cronjob and cleanup system
- Add docker_cleanup_old_images() to remove dangling images and keep only 2 most recent per tag
- Add docker_pull_with_marker() to pull images and update marker files tracking last pull time
- Add docker_setup_auto_pull_cronjob() to create/update system cronjob and wrapper script via hash-based detection
- Add docker_ensure_auto_pull_cronjob() to ensure cronjob is installed and up-to-date
- Create self-contained wrapper script at /usr/local/bin/armbian-docker-pull for cron execution
- Store configuration hash in /var/lib/armbian/docker-pull.hash for smart update detection
- Install cronjob at /etc/cron.d/armbian-docker-pull to pull images every 12 hours
- Move cronjob setup from docker_cli_prepare() to requirements command
- Cronjob is now only installed when users explicitly run ./compile.sh requirements
- Prevents "12 hours since last pull, pulling again" delay during builds

Signed-off-by: Igor Pecovnik <igor@armbian.com>
2026-02-01 00:22:54 +01:00

57 lines
2.3 KiB
Bash

#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2013-2026 Igor Pecovnik, igor@armbian.com
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
function cli_requirements_pre_run() {
declare -g ARMBIAN_COMMAND_REQUIRE_BASIC_DEPS="yes" # Require prepare_host_basic to run before the command.
if [[ "$(uname)" != "Linux" ]]; then
display_alert "Not running on Linux" "refusing to run 'requirements'" "err"
exit 1
fi
if [[ "${EUID}" == "0" ]]; then # we're already root. Either running as real root, or already sudo'ed.
display_alert "Already running as root" "great" "debug"
else
# Fail, installing requirements is not allowed as non-root.
exit_with_error "This command requires root privileges - refusing to run"
fi
}
function cli_requirements_run() {
initialize_extension_manager # initialize the extension manager.
declare -a -g host_dependencies=()
obtain_and_check_host_release_and_arch # Sets HOSTRELEASE & validates it for sanity; also HOSTARCH
host_release="${HOSTRELEASE}" host_arch="${HOSTARCH}" early_prepare_host_dependencies
LOG_SECTION="install_host_dependencies" do_with_logging install_host_dependencies "for requirements command"
declare -i -g -r prepare_host_has_already_run=1 # global, readonly. fool the rest of the script into thinking we've already run prepare_host.
if [[ "${ARMBIAN_INSIDE_DOCKERFILE_BUILD}" == "yes" ]]; then
# Include python/pip packages in the Dockerfile build.
deploy_to_non_cache_dir="yes" prepare_python_and_pip
# During the Dockerfile build, we want to pre-download ORAS/shellcheck/shfmt so it's included in the image.
# We need to change the deployment directory to something not in ./cache, so it's baked into the image.
deploy_to_non_cache_dir="yes" run_tool_oras # download-only, to non-cache dir.
deploy_to_non_cache_dir="yes" run_tool_shellcheck # download-only, to non-cache dir.
deploy_to_non_cache_dir="yes" run_tool_batcat # download-only, to non-cache dir.
# @TODO: shfmt
fi
display_alert "Done with" "@host dependencies" "cachehit"
# Ensure Docker auto-pull cronjob is installed if Docker is available
if [[ -n "$(command -v docker)" ]]; then
display_alert "Docker" "ensuring auto-pull cronjob is installed" "info"
docker_ensure_auto_pull_cronjob
fi
}