From 52710b33630fc95de7043b5ba50143155a265288 Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Wed, 24 May 2023 16:32:31 +0200 Subject: [PATCH] git/docker: bsp-cli: fix `BUILD_REPOSITORY_URL` and `BUILD_REPOSITORY_COMMIT` under Docker; fixes AR-1750 --- lib/functions/bsp/armbian-bsp-cli-deb.sh | 4 ++++ lib/functions/cli/cli-docker.sh | 5 +++++ lib/functions/configuration/main-config.sh | 17 ++++++++++++++--- lib/functions/host/docker.sh | 10 ++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/functions/bsp/armbian-bsp-cli-deb.sh b/lib/functions/bsp/armbian-bsp-cli-deb.sh index 6629b0cb9..acfed97f0 100644 --- a/lib/functions/bsp/armbian-bsp-cli-deb.sh +++ b/lib/functions/bsp/armbian-bsp-cli-deb.sh @@ -179,6 +179,10 @@ function compile_armbian-bsp-cli() { find "${destination}" -print0 2> /dev/null | xargs -0r chown --no-dereference 0:0 find "${destination}" ! -type l -print0 2> /dev/null | xargs -0r chmod 'go=rX,u+rw,a-s' + if [[ "${SHOW_DEBUG}" == "yes" ]]; then + run_tool_batcat --file-name "/etc/armbian-release.sh" "${destination}"/etc/armbian-release + fi + # Build / close the package. This will run shellcheck / show the generated files if debugging fakeroot_dpkg_deb_build "${destination}" "${DEB_STORAGE}/" diff --git a/lib/functions/cli/cli-docker.sh b/lib/functions/cli/cli-docker.sh index 33b6bb850..854bda4f3 100644 --- a/lib/functions/cli/cli-docker.sh +++ b/lib/functions/cli/cli-docker.sh @@ -35,6 +35,11 @@ function cli_docker_run() { declare -g GIT_INFO_ANSI GIT_INFO_ANSI="$(prepare_ansi_git_info_log_header)" + # Same stuff for BUILD_REPOSITORY_URL and BUILD_REPOSITORY_COMMIT. + if [[ -d "${SRC}/.git" && "${CONFIG_DEFS_ONLY}" != "yes" ]]; then # don't waste time if only gathering config defs + set_git_build_repo_url_and_commit_vars "docker launcher" + fi + 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. diff --git a/lib/functions/configuration/main-config.sh b/lib/functions/configuration/main-config.sh index 50b7c179d..470b7d1ce 100644 --- a/lib/functions/configuration/main-config.sh +++ b/lib/functions/configuration/main-config.sh @@ -70,9 +70,10 @@ function do_main_configuration() { [[ -z "${CHROOT_CACHE_VERSION}" ]] && CHROOT_CACHE_VERSION=7 if [[ -d "${SRC}/.git" && "${CONFIG_DEFS_ONLY}" != "yes" ]]; then # don't waste time if only gathering config defs - display_alert "Getting git info for repo" "${SRC}" "debug" - BUILD_REPOSITORY_URL="$(git remote get-url "$(git remote | grep origin || true)" || true)" # ignore all errors - BUILD_REPOSITORY_COMMIT="$(git describe --match=d_e_a_d_b_e_e_f --always --dirty || true)" # ignore error + # The docker launcher will have passed these as environment variables. If not, try again here. + if [[ -z "${BUILD_REPOSITORY_URL}" || -z "${BUILD_REPOSITORY_COMMIT}" ]]; then + set_git_build_repo_url_and_commit_vars "main configuration" + fi fi ROOTFS_CACHE_MAX=200 # max number of rootfs cache, older ones will be cleaned up @@ -500,3 +501,13 @@ function source_family_config_and_arch() { return 0 } + +function set_git_build_repo_url_and_commit_vars() { + display_alert "Getting git info for repo, during ${1}..." "${SRC}" "debug" + declare -g BUILD_REPOSITORY_URL BUILD_REPOSITORY_COMMIT + BUILD_REPOSITORY_URL="$(git -C "${SRC}" remote get-url "$(git -C "${SRC}" remote | grep origin || true)" || true)" # ignore all errors + BUILD_REPOSITORY_COMMIT="$(git -C "${SRC}" describe --match=d_e_a_d_b_e_e_f --always --dirty || true)" # ignore error + display_alert "BUILD_REPOSITORY_URL set during ${1}" "${BUILD_REPOSITORY_URL}" "debug" + display_alert "BUILD_REPOSITORY_COMMIT set during ${1}" "${BUILD_REPOSITORY_COMMIT}" "debug" + return 0 +} diff --git a/lib/functions/host/docker.sh b/lib/functions/host/docker.sh index 8a1c357e2..faaa3f768 100644 --- a/lib/functions/host/docker.sh +++ b/lib/functions/host/docker.sh @@ -420,6 +420,16 @@ function docker_cli_prepare_launch() { DOCKER_ARGS+=("--env" "GIT_INFO_ANSI=${GIT_INFO_ANSI}") fi + if [[ -n "${BUILD_REPOSITORY_URL}" ]]; then + display_alert "Git info" "Passing down BUILD_REPOSITORY_URL as an env var..." "debug" + DOCKER_ARGS+=("--env" "BUILD_REPOSITORY_URL=${BUILD_REPOSITORY_URL}") + fi + + if [[ -n "${BUILD_REPOSITORY_COMMIT}" ]]; then + display_alert "Git info" "Passing down BUILD_REPOSITORY_COMMIT as an env var..." "debug" + DOCKER_ARGS+=("--env" "BUILD_REPOSITORY_COMMIT=${BUILD_REPOSITORY_COMMIT}") + 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...