Skip to content

Commit

Permalink
dcuc: fix file mounting in add_bind_mount
Browse files Browse the repository at this point in the history
add_bind_mount was run in subshell so changes to e.g. DOCKER_ARGS were
not visible after finishing

Signed-off-by: Michał Iwanicki <[email protected]>
  • Loading branch information
m-iwanicki committed Jan 8, 2025
1 parent 50e2aed commit 0ad48b4
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions dcuc
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ COMMAND_ARGS=()
# Function to add a bind mount for a file
add_bind_mount() {
local FILE_PATH=$1
local ABS_PATH=""
local DIR_PATH=""
local ABS_PATH
ABS_PATH=$(realpath "$FILE_PATH")
DIR_PATH=$(dirname "$ABS_PATH")
DOCKER_ARGS+=("-v" "$DIR_PATH:$DIR_PATH")
echo "$ABS_PATH"
FILENAME="$(basename "$ABS_PATH")"
DOCKER_ARGS+=( '-v' "$ABS_PATH":/"${FILENAME}" )
}

# Iterate over the command line arguments
for ARG in "$@"; do
if [[ -f "$ARG" ]]; then
# Convert the file path to an absolute path and add a bind mount
ABS_PATH=$(add_bind_mount "$ARG")
COMMAND_ARGS+=("$ABS_PATH")
add_bind_mount "$ARG"
COMMAND_ARGS+=("/$FILENAME")
else
COMMAND_ARGS+=("$ARG")
fi
Expand All @@ -38,4 +36,4 @@ if [[ -v CI ]]; then
../dcu "${COMMAND_ARGS[@]}"
else
docker run -t --rm -v "${SCRIPT_DIR}:${SCRIPT_DIR}" "${DOCKER_ARGS[@]}" -w "${SCRIPT_DIR}" $DOCKER_IMAGE ./dcu "${COMMAND_ARGS[@]}"
fi
fi

0 comments on commit 0ad48b4

Please sign in to comment.