make the hooks usable by the whole catalogue
- hooks load the _stack files of every directory between the stack path root and the stack, outermost first: make included both $(dir)/*.mk and $(dir)/*/*.mk, so a stack in a subdirectory saw its parent's settings - a group may be declared in <group>/<group>.env, where the stack lives - MYOS_STACK_DIR lets a hook read a file it ships next to itself - myos_filter no longer confuses a literal * in a make pattern with a wildcard, and the list helpers no longer let the shell expand a * into filenames - MACHINE, SYSTEM, HOST and DOMAINNAME join the framework variables a hook sees - the make shim gains $(call myos-var,NAME), so a .mk target can read a setting that now lives in a hook, and it picks up the .mk of every stack directory rather than only the project's
This commit is contained in:
+54
-15
@@ -1,30 +1,69 @@
|
||||
#shellcheck shell=sh
|
||||
# shellcheck disable=SC1090 # hooks are sourced by a path built at run time
|
||||
# hooks: the per-stack settings that used to live in a .mk file.
|
||||
#
|
||||
# A stack may ship, next to its compose files:
|
||||
# A stack directory may ship, next to its compose files:
|
||||
# _stack.env settings shared by every stack of the directory
|
||||
# _stack.sh the same, computed
|
||||
# <name>.env dotenv, for plain values
|
||||
# <name>.env settings of one stack
|
||||
# <name>.env.<env> the same, for one environment
|
||||
# <name>.sh shell, for values that have to be computed (fabio tags, JWTs)
|
||||
# <name>.sh computed settings of one stack
|
||||
# <name>.mk the legacy make snippet, still read for its groups
|
||||
#
|
||||
# A .sh hook runs with the myos helpers available (myos_tagprefix, myos_uri,
|
||||
# myos_var) and sets variables directly. This is what lets a stack of the
|
||||
# catalogue work on a machine that has no make.
|
||||
# A .sh hook declares lazy defaults (see lib/var.sh): functions named
|
||||
# myos_default_<VARIABLE>, called only when the variable has no value and
|
||||
# called again at each reference. That is a make `?=` on a recursive variable,
|
||||
# and it is what lets a stack of the catalogue work without make installed.
|
||||
#
|
||||
# The _stack hooks of every directory between the stack path root and the stack
|
||||
# itself are loaded, outermost first: make included both $(dir)/*.mk and
|
||||
# $(dir)/*/*.mk, so a stack in a subdirectory saw its parent's settings.
|
||||
|
||||
# myos_stack_hooks DIR NAME load the hooks of one stack, most specific last
|
||||
# myos_stack_hooks DIR NAME load the hooks that apply to one stack
|
||||
myos_stack_hooks() {
|
||||
_hdir=$1; _hname=$2
|
||||
for _h in "$_hdir/_stack.env" "$_hdir/$_hname.env" "$_hdir/$_hname.env.$ENV"; do
|
||||
[ -f "$_h" ] && myos_dotenv_load "$_h"
|
||||
|
||||
# the stack path entry this directory belongs to
|
||||
_root=
|
||||
_IFS=$IFS; IFS=:
|
||||
for _r in $(myos_path); do
|
||||
IFS=$_IFS
|
||||
case $_hdir in "$_r"|"$_r"/*) _root=$_r; break ;; esac
|
||||
IFS=:
|
||||
done
|
||||
for _h in "$_hdir/_stack.sh" "$_hdir/$_hname.sh" "$_hdir/$_hname.$ENV.sh"; do
|
||||
if [ -f "$_h" ]; then
|
||||
myos_debug "hook $_h"
|
||||
# shellcheck source=/dev/null
|
||||
. "$_h"
|
||||
fi
|
||||
IFS=$_IFS
|
||||
|
||||
# every directory from the root down to the stack, outermost first
|
||||
_chain=$_hdir
|
||||
if [ -n "$_root" ]; then
|
||||
_d=$_hdir
|
||||
while [ "$_d" != "$_root" ] && [ "$_d" != "/" ] && [ -n "$_d" ]; do
|
||||
_d=$(dirname "$_d")
|
||||
_chain="$_d
|
||||
$_chain"
|
||||
done
|
||||
fi
|
||||
|
||||
for _d in $_chain; do
|
||||
myos_hook_load "$_d/_stack.env" dotenv
|
||||
myos_hook_load "$_d/_stack.sh" shell
|
||||
done
|
||||
myos_hook_load "$_hdir/$_hname.env" dotenv
|
||||
myos_hook_load "$_hdir/$_hname.env.$ENV" dotenv
|
||||
myos_hook_load "$_hdir/$_hname.sh" shell
|
||||
myos_hook_load "$_hdir/$_hname.$ENV.sh" shell
|
||||
return 0
|
||||
}
|
||||
|
||||
# myos_hook_load FILE KIND
|
||||
myos_hook_load() {
|
||||
[ -f "$1" ] || return 0
|
||||
myos_debug "hook $1"
|
||||
# a hook may need to read a file it ships next to itself
|
||||
# shellcheck disable=SC2034 # read by the hooks sourced below
|
||||
MYOS_STACK_DIR=$(dirname "$1")
|
||||
case $2 in
|
||||
dotenv) myos_dotenv_load "$1" ;;
|
||||
shell) . "$1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user