Skip to content

Commit

Permalink
Handle workspace path has spaces, is symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru committed Jan 20, 2025
1 parent 6167248 commit 6e637c2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ReleaseNotes-v4.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Geodesic v4.0.0 Release Notes
# Geodesic v4.0.0 Release Notes

### Highlights

Expand Down
23 changes: 22 additions & 1 deletion rootfs/etc/profile.d/_20-mounts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,29 @@ function _map_mounts() {
done
}

function _add_symlinks() {
local links dest src
IFS='|' read -ra links <<<"${GEODESIC_HOST_SYMLINK}"
for l in "${links[@]}"; do
[[ -z "$l" ]] && continue
local src dest
IFS='>' read -r dest src <<<"$l"
if [[ -z $src ]] || [[ -z $dest ]]; then
red "# ERROR: Invalid symlink definition: $l"
continue
fi
mkdir -p "$(dirname "$dest")"
if [[ -e $dest ]]; then
red "# ERROR: Symlink destination already exists: '$dest'"
continue
fi
ln -sT "$src" "$dest" && yellow symlinking "'$src' -> '$dest'" || red "# ERROR: Failed to create symlink: '$src' -> '$dest'"
done
}

if [[ $SHLVL == 1 ]]; then
_map_mounts
_add_symlinks

# Ensure we do not have paths that match everything
paths=("${GEODESIC_HOST_PATHS[@]}")
Expand All @@ -177,4 +198,4 @@ if [[ $SHLVL == 1 ]]; then
done
fi

unset -f _map_mounts _map_owner _map_host _ensure_dest paths
unset -f _map_mounts _map_owner _map_host _ensure_dest paths _add_symlinks
28 changes: 16 additions & 12 deletions rootfs/templates/wrapper-body.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
homedir_default_mounts=".aws,.config,.emacs.d,.geodesic,.kube,.ssh,.terraform.d"

function require_installed() {
if ! command -v $1 >/dev/null 2>&1; then
echo "Cannot find $1 installed on this system. Please install and try again."
if ! command -v "$1" >/dev/null 2>&1; then
echo "Cannot find '$1' installed on this system. Please install and try again."
exit 1
fi
}
Expand Down Expand Up @@ -188,13 +188,15 @@ function options_to_env() {
local v

for option in "${options[@]}"; do
kv=(${option/=/ })
k=${kv[0]} # Take first element as key
k=${k#--} # Strip leading --
k=${k//-/_} # Convert dashes to underscores
k=$(echo $k | tr '[:lower:]' '[:upper:]') # Convert to uppercase (bash3 compat)

v="${kv[@]:1}" # Treat remaining elements as value
# Safely split on '='
IFS='=' read -r -a kv <<< "$option"
k=${kv[0]} # Take first element as key
k=${k#--} # Strip leading --
k=${k//-/_} # Convert dashes to underscores
k=$(echo "$k" | tr '[:lower:]' '[:upper:]') # Convert to uppercase (bash3 compat)
# Treat remaining elements as value, restoring the '=' separator
# This preserves multiple consecutive whitespace characters
v="$(IFS='='; echo "${kv[*]:1}")"
v="${v:-true}" # Set it to true for boolean flags

export $k="$v"
Expand Down Expand Up @@ -437,6 +439,7 @@ function use() {
fi
if [ "$configured_wfhd" != "$WORKSPACE_FOLDER_HOST_DIR" ]; then
echo "# Resolved ${configured_wfhd} to '${WORKSPACE_FOLDER_HOST_DIR}'"
export GEODESIC_HOST_SYMLINK+="${configured_wfhd}>${WORKSPACE_FOLDER_HOST_DIR}|"
fi

echo "# Mounting '${WORKSPACE_MOUNT_HOST_DIR}' into container at '${WORKSPACE_MOUNT}'"
Expand All @@ -448,6 +451,7 @@ function use() {
--env WORKSPACE_MOUNT="${WORKSPACE_MOUNT}"
--env WORKSPACE_FOLDER="${WORKSPACE_FOLDER}"
)
[ -n "${GEODESIC_HOST_SYMLINK}" ] && DOCKER_ARGS+=(--env GEODESIC_HOST_SYMLINK)

# Mount the host mounts wherever the users asks for them to be mounted.
# However, if file ownership mapping is enabled,
Expand Down Expand Up @@ -526,17 +530,17 @@ _polite_stop() {
return
fi

printf "# Signalling ${name} to stop..."
printf "# Signalling '%s' to stop..." "${name}"
docker kill -s TERM "${name}" >/dev/null
for i in {1..9}; do
if [ $i -eq 9 ] || [ $(docker ps -q --filter "name=${name}" | wc -l | tr -d " ") -eq 0 ]; then
printf " ${name} stopped gracefully.\n\n"
printf " '%s' stopped gracefully.\n\n" "${name}"
return 0
fi
[ $i -lt 8 ] && sleep 1
done

printf " ${name} did not stop gracefully. Killing it.\n\n"
printf " '%s' did not stop gracefully. Killing it.\n\n" "${name}"
docker kill -s TERM "${name}" >/dev/null
return 138
}
Expand Down

0 comments on commit 6e637c2

Please sign in to comment.