CI: map nested Docker workspace
Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
1 parent
2e8e1fc0ba
commit
523355a128
4 files changed
+69
-64
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user