forked from cloudposse/geodesic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start in host CWD, autoconfigure ATMOS_BASE_PATH (cloudposse#756)
- Loading branch information
Showing
9 changed files
with
167 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Files in the profile.d directory are executed by the lexicographical order of their file names. | ||
# This file sets the working directory inside Geodesic to match the host directory Geodesic | ||
# was launched from, if possible. If the host directory is not accessible, it sets the working directory to `/`. | ||
# | ||
# This file is named _workdir.sh. The leading underscore is needed to ensure this file executes before | ||
# other files that may depend on it. The "w" is needed to ensure it is loaded *after* _preferences.sh | ||
# | ||
|
||
function _file_device() { | ||
df --output=source "$1" | tail -1 | ||
} | ||
|
||
# file_on_host is true when the argument is a file or directory that appears to be on the Host file system. | ||
# Intended to support files on user-defined bind mounts in addition to `/localhost`. | ||
# This function is run by the command line prompt setup, so it should be very fast. | ||
# Therefore we cache some info in the environment. | ||
if df -a | grep -q /localhost; then | ||
export GEODESIC_LOCALHOST_DEVICE=$(_file_device /localhost) | ||
else | ||
export GEODESIC_LOCALHOST_MISSING=true | ||
fi | ||
|
||
function file_on_host() { | ||
[[ $GEODESIC_LOCALHOST_MISSING != "true" ]] && [[ $(_file_device "$1") == ${GEODESIC_LOCALHOST_DEVICE} ]] | ||
} | ||
|
||
function _default_initial_wd() { | ||
if [[ -d /stacks ]]; then | ||
# Newer default using `atmos` and stacks | ||
export GEODESIC_WORKDIR="/" | ||
else | ||
# Older default working directory | ||
export GEODESIC_WORKDIR="/conf" | ||
fi | ||
red "# Defaulting initial working directory to \"${GEODESIC_WORKDIR}\"" | ||
} | ||
|
||
# You can set GEODESIC_WORKDIR in your Geodesic preferences to have full control of your starting working directory | ||
if [[ -d $GEODESIC_WORKDIR ]]; then | ||
[[ $SHLVL == 1 ]] && green "# Initial working directory configured as ${GEODESIC_WORKDIR}" | ||
else | ||
if [[ -d $GEODESIC_HOST_CWD ]]; then | ||
if [[ -n $LOCAL_HOME ]] && $(file_on_host "$GEODESIC_HOST_CWD"); then | ||
export GEODESIC_WORKDIR=$(readlink -e "${GEODESIC_HOST_CWD}") | ||
green "# Initial working directory set from host CWD to ${GEODESIC_WORKDIR}" | ||
else | ||
red "# Host CWD \"${GEODESIC_HOST_CWD}\" does not appear to be accessible from this container" | ||
_default_initial_wd | ||
fi | ||
else | ||
red "# No configured working directory is accessible:" | ||
red "# GEODESIC_WORKDIR is \"$GEODESIC_WORKDIR\"" | ||
red "# GEODESIC_HOST_CWD is \"$GEODESIC_HOST_CWD\"" | ||
_default_initial_wd | ||
fi | ||
fi | ||
|
||
[[ $SHLVL == 1 ]] && cd "${GEODESIC_WORKDIR}" | ||
|
||
unset -f _default_initial_wd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
function _configure_atmos_base_path() { | ||
# Leave $ATMOS_BASE_PATH alone if it is already set | ||
if [[ -n $ATMOS_BASE_PATH ]]; then | ||
if [[ $SHLVL == 1 ]]; then | ||
green "# Using configured $ATMOS_BASE_PATH of \"$ATMOS_BASE_PATH\"" | ||
fi | ||
return | ||
fi | ||
|
||
# If $GEODESIC_WORKDIR contains both a "stacks" and "components" directory, | ||
# use it as the $ATMOS_BASE_PATH | ||
if [[ -d "${GEODESIC_WORKDIR}/stacks" ]] && [[ -d "${GEODESIC_WORKDIR}/components" ]]; then | ||
export ATMOS_BASE_PATH="${GEODESIC_WORKDIR}" | ||
green "# Setting ATMOS_BASE_PATH to \"$ATMOS_BASE_PATH\" based on children of workdir" | ||
return | ||
fi | ||
|
||
# If $GEODESIC_WORKDIR is a descendent of either a "stacks" or "components" directory, | ||
# use the parent of that directory as ATMOS_BASE_PATH | ||
if [[ "${GEODESIC_WORKDIR}" =~ /(stacks|components)/ ]]; then | ||
if [[ "${GEODESIC_WORKDIR}" =~ /stacks/ ]]; then | ||
export ATMOS_BASE_PATH="${GEODESIC_WORKDIR%/stacks/*}" | ||
else | ||
export ATMOS_BASE_PATH="${GEODESIC_WORKDIR%/components/*}" | ||
fi | ||
green "# Setting ATMOS_BASE_PATH to \"$ATMOS_BASE_PATH\" based on parent of workdir" | ||
return | ||
fi | ||
yellow "# No candidate for ATMOS_BASE_PATH found, leaving it unset" | ||
} | ||
|
||
# Only configure ATMOS_BASE_PATH if we find an `atmos` executable, | ||
# but otherwise leave the function available for the user to call explicitly. | ||
# NOTE: If we start shipping `atmos` with Geodesic by default, change this to | ||
# [[ -f /usr/local/etc/atmos/atmos.yaml ]] && _configure_atmos_base_path | ||
command -v atmos >/dev/null && _configure_atmos_base_path && unset -f _configure_atmos_base_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters