mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
armbian-next: docker: pass down git info via env var, since Docker doesn't get ${SRC}/.git, yet we need that info in the Docker logs
This commit is contained in:
@@ -21,6 +21,11 @@ function cli_docker_pre_run() {
|
||||
}
|
||||
|
||||
function cli_docker_run() {
|
||||
# Docker won't have ${SRC}/.git, so precalculate the git-info header so it can be included in the inside-Docker logs.
|
||||
# It's gonna be picked up by export_ansi_logs() and included in the final log, if it exists.
|
||||
declare -g GIT_INFO_ANSI
|
||||
GIT_INFO_ANSI="$(prepare_ansi_git_info_log_header)"
|
||||
|
||||
LOG_SECTION="docker_cli_prepare" do_with_logging docker_cli_prepare
|
||||
|
||||
# @TODO: and can be very well said that in CI, we always want FAST_DOCKER=yes, unless we're building the Docker image itself.
|
||||
|
||||
@@ -395,6 +395,12 @@ function docker_cli_prepare_launch() {
|
||||
DOCKER_ARGS+=("--env" "ARMBIAN_ENABLE_CALL_TRACING=yes")
|
||||
fi
|
||||
|
||||
# If set, pass down git_info_ansi as an env var
|
||||
if [[ -n "${GIT_INFO_ANSI}" ]]; then
|
||||
display_alert "Git info" "Passing down GIT_INFO_ANSI as an env var..." "debug"
|
||||
DOCKER_ARGS+=("--env" "GIT_INFO_ANSI=${GIT_INFO_ANSI}")
|
||||
fi
|
||||
|
||||
if [[ "${DOCKER_PASS_SSH_AGENT}" == "yes" ]]; then
|
||||
declare ssh_socket_path="${SSH_AUTH_SOCK}"
|
||||
if [[ "${OSTYPE}" == "darwin"* ]]; then # but probably only Docker Inc, not Rancher...
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
function prepare_ansi_git_info_log_header() {
|
||||
# writes to stdout, ANSI format
|
||||
|
||||
declare prefix_sed_cmd="/^-->/!s/^/ /;" # some spacing in front of git info
|
||||
cat <<- GIT_ANSI_HEADER
|
||||
$(echo -e -n "${bright_blue_color:-}")# GIT revision$(echo -e -n "${ansi_reset_color:-}")
|
||||
$(LC_ALL=C LANG=C git --git-dir="${SRC}/.git" log -1 --color --format=short --decorate | sed -e "${prefix_sed_cmd}" || true)
|
||||
${dim_line_separator}
|
||||
$(echo -e -n "${bright_blue_color:-}")# GIT status$(echo -e -n "${ansi_reset_color:-}")
|
||||
$(LC_ALL=C LANG=C git -c color.status=always --work-tree="${SRC}" --git-dir="${SRC}/.git" status | sed -e "${prefix_sed_cmd}" || true)
|
||||
${dim_line_separator}
|
||||
$(echo -e -n "${bright_blue_color:-}")# GIT changes$(echo -e -n "${ansi_reset_color:-}")
|
||||
$(LC_ALL=C LANG=C git --work-tree="${SRC}" --git-dir="${SRC}/.git" diff -u --color | sed -e "${prefix_sed_cmd}" || true)
|
||||
${dim_line_separator}
|
||||
GIT_ANSI_HEADER
|
||||
}
|
||||
|
||||
# This only includes a header, and all the .md logfiles, nothing else.
|
||||
function export_markdown_logs() {
|
||||
# check target_file variable is not empty
|
||||
@@ -100,19 +117,13 @@ function export_ansi_logs() {
|
||||
${dim_line_separator}
|
||||
ANSI_HEADER
|
||||
|
||||
if [[ -n "$(command -v git)" && -d "${SRC}/.git" ]]; then
|
||||
if [[ -n "${GIT_INFO_ANSI}" ]]; then
|
||||
echo "${GIT_INFO_ANSI}" >> "${target_file}"
|
||||
elif [[ -n "$(command -v git)" && -d "${SRC}/.git" ]]; then # we don't have .git inside Docker...
|
||||
display_alert "Gathering git info for logs" "Processing git information, please wait..." "debug"
|
||||
cat <<- GIT_ANSI_HEADER >> "${target_file}"
|
||||
# Last revision:
|
||||
$(LC_ALL=C LANG=C git --git-dir="${SRC}/.git" log -1 --color --format=short --decorate || true)
|
||||
${dim_line_separator}
|
||||
# Git status:
|
||||
$(LC_ALL=C LANG=C git -c color.status=always --work-tree="${SRC}" --git-dir="${SRC}/.git" status || true)
|
||||
${dim_line_separator}
|
||||
# Git changes:
|
||||
$(LC_ALL=C LANG=C git --work-tree="${SRC}" --git-dir="${SRC}/.git" diff -u --color || true)
|
||||
${dim_line_separator}
|
||||
GIT_ANSI_HEADER
|
||||
prepare_ansi_git_info_log_header >> "${target_file}"
|
||||
else
|
||||
display_alert "Gathering git info for logs" "No git information available" "debug"
|
||||
fi
|
||||
|
||||
display_alert "Preparing ANSI logs..." "Processing log files..." "debug"
|
||||
@@ -121,6 +132,7 @@ function export_ansi_logs() {
|
||||
declare -a logfiles_array
|
||||
mapfile -t logfiles_array < <(find "${LOGDIR}" -type f | LC_ALL=C sort -h) # "human" sorting
|
||||
|
||||
declare prefix_sed_contents
|
||||
prefix_sed_contents=" $(echo -n -e "${ansi_reset_color}${tool_color:-}")" # spaces are significant
|
||||
declare prefix_sed_cmd="/^-->/!s/^/${prefix_sed_contents}/;"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user