diff --git a/.gitea/RELEASING.md b/.gitea/RELEASING.md index f13b447..ee09ae8 100644 --- a/.gitea/RELEASING.md +++ b/.gitea/RELEASING.md @@ -31,11 +31,11 @@ services: Leave `container.docker_host` at its generated default (`""`) so `act_runner` passes the detected Docker endpoint to job containers. Do not set it to `-`, which explicitly prevents that endpoint from being mounted. Restart the runner -after changing its configuration. `scripts/release.sh` detects when it is -running inside the job container and translates the checked-out workspace -through that container's Docker mount table. This is required because bind -mount paths passed to the socket are resolved by the runner host daemon, not -inside the Actions job container. +after changing its configuration. `scripts/lib/docker-daemon-path.sh` detects +when commands run inside the job container and translates checked-out paths +through that container's Docker mount table. The release wrapper and +control-plane tests both use it because bind mount paths passed to the socket +are resolved by the runner host daemon, not inside the Actions job container. The SSH checkout steps pin the current `git.faumaray.ru` RSA host key. Its verified fingerprint is diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 4903f9b..402d038 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -41,16 +41,19 @@ jobs: scripts/release.sh --version "$CI_VERSION" - name: Test release control-plane scripts + shell: bash run: | set -eu bash scripts/tests/test-gitea-tag-verification.sh + . scripts/lib/docker-daemon-path.sh + docker_workspace=$(docker_daemon_path "$PWD") docker run --rm --network none \ - --volume "$PWD:/workspace:ro" \ + --volume "$docker_workspace:/workspace:ro" \ --workdir /workspace \ echoion-release-builder:gcc-16.1.0 \ python3 scripts/tests/test_aggregate_update_feed.py docker run --rm --network none \ - --volume "$PWD:/workspace:ro" \ + --volume "$docker_workspace:/workspace:ro" \ --workdir /workspace \ echoion-release-builder:gcc-16.1.0 \ python3 scripts/tests/test_gitea_release.py diff --git a/scripts/lib/docker-daemon-path.sh b/scripts/lib/docker-daemon-path.sh new file mode 100644 index 0000000..e336d26 --- /dev/null +++ b/scripts/lib/docker-daemon-path.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# Translate a path visible inside a containerized CI job into the source path +# understood by the Docker daemon. On a regular host this returns the input +# unchanged. +docker_daemon_path() { + local path=$1 + local container_reference=${ECHOION_DOCKER_CONTAINER_ID:-} + local mount_data= + local mount_source mount_destination + local best_source='' best_destination='' + + if [[ -z $container_reference ]]; then + container_reference=${JOB_CONTAINER_NAME:-${HOSTNAME:-}} + fi + + if [[ -n ${ECHOION_DOCKER_CONTAINER_ID:-} || + -f /.dockerenv || -f /run/.containerenv ]]; then + if [[ -n $container_reference ]]; then + mount_data=$( + docker inspect \ + --format '{{range .Mounts}}{{printf "%s\t%s\n" .Source .Destination}}{{end}}' \ + "$container_reference" 2>/dev/null || true + ) + fi + fi + + while IFS=$'\t' read -r mount_source mount_destination; do + [[ -n $mount_source && -n $mount_destination ]] || continue + case $path in + "$mount_destination"|"$mount_destination"/*) + if ((${#mount_destination} > ${#best_destination})); then + best_source=$mount_source + best_destination=$mount_destination + fi + ;; + *) + if [[ $mount_destination == / && $path == /* ]]; then + best_source=$mount_source + best_destination=$mount_destination + fi + ;; + esac + done <<<"$mount_data" + + if [[ -z $best_destination ]]; then + printf '%s\n' "$path" + elif [[ $path == "$best_destination" ]]; then + printf '%s\n' "$best_source" + elif [[ $best_destination == / ]]; then + printf '%s/%s\n' "${best_source%/}" "${path#/}" + else + printf '%s/%s\n' \ + "${best_source%/}" "${path#"$best_destination"/}" + fi +} diff --git a/scripts/release.sh b/scripts/release.sh index 191cb13..e11f9e9 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -60,6 +60,9 @@ canonical_release_version() { script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P) source_dir=$(cd -- "$script_dir/.." && pwd -P) +# shellcheck source-path=SCRIPTDIR +# shellcheck source=lib/docker-daemon-path.sh +source "$script_dir/lib/docker-daemon-path.sh" version= build_dir="$source_dir/build-release" dist_dir="$source_dir/dist" @@ -205,63 +208,6 @@ container_path() { esac } -docker_daemon_path() { - local path=$1 - local container_reference=${ECHOION_DOCKER_CONTAINER_ID:-} - local mount_data= - local mount_source mount_destination - local best_source='' best_destination='' - - if [[ -z $container_reference ]]; then - container_reference=${JOB_CONTAINER_NAME:-${HOSTNAME:-}} - fi - - # A containerized CI job talks to the host Docker daemon through its - # socket. Bind-mount source paths are therefore interpreted in the daemon - # host namespace, not in this job container. Resolve the longest matching - # mount from the current container so nested release containers see the - # checked-out workspace instead of an empty host directory. - if [[ -n ${ECHOION_DOCKER_CONTAINER_ID:-} || - -f /.dockerenv || -f /run/.containerenv ]]; then - if [[ -n $container_reference ]]; then - mount_data=$( - docker inspect \ - --format '{{range .Mounts}}{{printf "%s\t%s\n" .Source .Destination}}{{end}}' \ - "$container_reference" 2>/dev/null || true - ) - fi - fi - - while IFS=$'\t' read -r mount_source mount_destination; do - [[ -n $mount_source && -n $mount_destination ]] || continue - case $path in - "$mount_destination"|"$mount_destination"/*) - if ((${#mount_destination} > ${#best_destination})); then - best_source=$mount_source - best_destination=$mount_destination - fi - ;; - *) - if [[ $mount_destination == / && $path == /* ]]; then - best_source=$mount_source - best_destination=$mount_destination - fi - ;; - esac - done <<<"$mount_data" - - if [[ -z $best_destination ]]; then - printf '%s\n' "$path" - elif [[ $path == "$best_destination" ]]; then - printf '%s\n' "$best_source" - elif [[ $best_destination == / ]]; then - printf '%s/%s\n' "${best_source%/}" "${path#/}" - else - printf '%s/%s\n' \ - "${best_source%/}" "${path#"$best_destination"/}" - fi -} - if ((use_container)); then command -v docker >/dev/null || die "docker is required for --container" container_build_dir=$(container_path "$build_dir")