remove profile dependency
This commit is contained in:
@@ -70,19 +70,39 @@ load_config() {
|
||||
# Re-apply overrides now so PROFILE is the caller's before we pick the file.
|
||||
_config_restore "$saved"
|
||||
|
||||
local profile="${PROFILE:-minimal}"
|
||||
if [ ! -f "./env.d/${profile}.env" ]; then
|
||||
echo "no such profile: env.d/${profile}.env" >&2
|
||||
echo "available: $(ls env.d/*.env 2>/dev/null | xargs -n1 basename | sed 's/\.env$//' | tr '\n' ' ')" >&2
|
||||
exit 1
|
||||
# A profile is an optional overlay, never a prerequisite. rig assumes no
|
||||
# configuration: with no profile named — or no env.d/ at all — it runs on the
|
||||
# built-in defaults below. What IS an error is naming a profile that does not
|
||||
# exist, because a typo must not quietly fall back to something else.
|
||||
local profile="${PROFILE:-}"
|
||||
if [ -n "$profile" ] && [ "$profile" != default ]; then
|
||||
if [ ! -f "./env.d/${profile}.env" ]; then
|
||||
echo "no such profile: env.d/${profile}.env" >&2
|
||||
echo "available: $(config_profiles | tr '\n' ' ')" >&2
|
||||
exit 1
|
||||
fi
|
||||
set -a
|
||||
source "./env.d/${profile}.env"
|
||||
if [ -z "${RIG_PORTABLE:-}" ] && [ -f ./.env ]; then source ./.env; fi
|
||||
set +a
|
||||
_config_restore "$saved"
|
||||
fi
|
||||
|
||||
set -a
|
||||
source "./env.d/${profile}.env"
|
||||
if [ -z "${RIG_PORTABLE:-}" ] && [ -f ./.env ]; then source ./.env; fi
|
||||
set +a
|
||||
|
||||
_config_restore "$saved"
|
||||
# The defaults a profile would otherwise have to supply. Weakest of all: a
|
||||
# profile, ctrl/.env and the caller each override them.
|
||||
PROFILE_NAME="${PROFILE_NAME:-default}"
|
||||
ADDONS="${ADDONS-}"
|
||||
# local, not none: with no registry an unqualified image name means
|
||||
# docker.io/library/<name>, and a default must not make that disclosure.
|
||||
REGISTRY_MODE="${REGISTRY_MODE:-local}"
|
||||
INGRESS_MODE="${INGRESS_MODE:-hostport}"
|
||||
DNS_MODE="${DNS_MODE:-hosts}"
|
||||
# The newest node image versions.env pins, found rather than restated, so
|
||||
# bumping the pins moves the default with them.
|
||||
if [ -z "${K8S_VERSION:-}" ]; then
|
||||
K8S_VERSION=$(compgen -v NODE_IMAGE_v | sort -V | tail -1)
|
||||
K8S_VERSION="${K8S_VERSION#NODE_IMAGE_}"
|
||||
fi
|
||||
|
||||
# Identity follows the FOLDER, so copying this directory somewhere else and
|
||||
# renaming it yields a distinct environment with no further edits. Without
|
||||
@@ -188,24 +208,44 @@ _config_restore() {
|
||||
# layered and what is derived are this file's business and can change freely;
|
||||
# the generator only calls these.
|
||||
|
||||
# Every profile rig can be run as, one per line.
|
||||
# Every configuration rig can be run as, one per line: each profile file, or —
|
||||
# when there are none — `default`, the built-in configuration load_config uses
|
||||
# when no profile is named. Never empty, because rig never needs a profile.
|
||||
config_profiles() {
|
||||
local f
|
||||
local f found=""
|
||||
for f in ./env.d/*.env; do
|
||||
[ -e "$f" ] || continue
|
||||
f=${f##*/}; echo "${f%.env}"
|
||||
f=${f##*/}; echo "${f%.env}"; found=1
|
||||
done
|
||||
[ -n "$found" ] || echo default
|
||||
}
|
||||
|
||||
# The resolved configuration for one profile, as `declare -p` lines — exactly
|
||||
# what load_config leaves behind, minus the machine-local layer. A kit freezes
|
||||
# this in place of load_config, so it carries rig's decisions for that profile
|
||||
# and nothing about the machine it was generated on.
|
||||
# The resolved configuration, as `declare -p` lines — exactly what load_config
|
||||
# leaves behind, minus the machine-local layer. A kit freezes this in place of
|
||||
# load_config, so it carries rig's decisions and not this machine's secrets.
|
||||
#
|
||||
# config_snapshot <profile> that profile, as any machine would resolve it
|
||||
# config_snapshot --current what THIS machine runs: every overridable key as
|
||||
# resolved here, handed back in as if typed on the
|
||||
# command line, over the same portable resolution.
|
||||
# Values derived from those choices follow them;
|
||||
# anything else the local layer set — credentials —
|
||||
# is not carried. config_left_out names it.
|
||||
#
|
||||
# Found by difference, not by a list: whatever load_config sets today, it sets.
|
||||
# A list here would be one more place to forget a variable.
|
||||
config_snapshot() {
|
||||
local _rig_snap_profile="$1"
|
||||
local _rig_snap_choices
|
||||
if [ "$1" = --current ]; then
|
||||
_rig_snap_choices=$( (
|
||||
load_config >/dev/null || exit 1
|
||||
for _rig_snap_n in $CONFIG_OVERRIDABLE; do
|
||||
if [ -n "${!_rig_snap_n+x}" ]; then printf 'export %s=%q\n' "$_rig_snap_n" "${!_rig_snap_n}"; fi
|
||||
done
|
||||
) ) || return 1
|
||||
else
|
||||
_rig_snap_choices="export PROFILE=$(printf '%q' "$1")"
|
||||
fi
|
||||
(
|
||||
# Nothing from the caller's shell may leak into a kit.
|
||||
for _rig_snap_n in $CONFIG_OVERRIDABLE; do unset "$_rig_snap_n"; done
|
||||
@@ -213,7 +253,8 @@ config_snapshot() {
|
||||
for _rig_snap_n in $(compgen -v); do
|
||||
_rig_snap_was[$_rig_snap_n]="${!_rig_snap_n-}"
|
||||
done
|
||||
PROFILE="$_rig_snap_profile" RIG_PORTABLE=1 load_config >/dev/null
|
||||
eval "$_rig_snap_choices"
|
||||
RIG_PORTABLE=1 load_config >/dev/null
|
||||
for _rig_snap_n in $(compgen -v); do
|
||||
case "$_rig_snap_n" in
|
||||
_rig_snap_*|RIG_PORTABLE|BASH*|FUNCNAME|PIPESTATUS|LINENO|RANDOM|SRANDOM|\
|
||||
@@ -227,7 +268,26 @@ config_snapshot() {
|
||||
)
|
||||
}
|
||||
|
||||
# A replacement for load_config with one profile's resolution frozen in, printed
|
||||
# The profile this machine runs, as load_config resolves it here.
|
||||
config_current_profile() { ( load_config >/dev/null && echo "$PROFILE_NAME" ); }
|
||||
|
||||
# What an export of this machine's configuration does NOT carry, by name only:
|
||||
# keys the machine-local layer sets that are not choices a caller may override.
|
||||
# They are this machine's own — registry and mirror credentials, mostly — so the
|
||||
# target has to be told to supply them. Values are never printed.
|
||||
config_left_out() {
|
||||
[ -f ./.env ] || return 0
|
||||
local k
|
||||
for k in $(sed -nE 's/^[[:space:]]*(export[[:space:]]+)?([A-Za-z_][A-Za-z0-9_]*)=.*/\2/p' ./.env | sort -u); do
|
||||
case " $(echo $CONFIG_OVERRIDABLE) " in
|
||||
*" $k "*) ;;
|
||||
*) echo "$k" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# A replacement for load_config with a resolution frozen in (a profile, or
|
||||
# --current — see config_snapshot), printed
|
||||
# as a function definition for a standalone kit to carry. The generator embeds
|
||||
# whatever this prints and interprets none of it, so what "frozen" means stays
|
||||
# rig's decision.
|
||||
|
||||
Reference in New Issue
Block a user