92 lines
1.9 KiB
Bash
Executable File
92 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
set -f
|
|
|
|
. /image-entry.d/00-common.envsh
|
|
|
|
## Angie: unset core variable
|
|
unset ANGIE ANGIE_BPF_MAPS
|
|
|
|
[ "${NGX_STRICT_LOAD}" = 0 ] || set -e
|
|
|
|
cd "${merged_root}/"
|
|
|
|
expand_error_delim() {
|
|
IEP_DEBUG=0 log_always ' ----------------------------------- '
|
|
}
|
|
unset expand_error_seen
|
|
expand_error() {
|
|
[ "${expand_error_seen:-}" != 1 ] || return
|
|
expand_error_seen=1
|
|
expand_error_delim
|
|
log_always 'template expansion has failed'
|
|
if [ "${NGX_STRICT_LOAD}" = 1 ] ; then
|
|
t=15
|
|
log_always "injecting delay for $t seconds"
|
|
expand_error_delim
|
|
sleep $t
|
|
exit 1
|
|
fi
|
|
expand_error_delim
|
|
}
|
|
|
|
merge_dirs=
|
|
for n in ${NGX_DIRS_MERGE} ; do
|
|
[ -n "$n" ] || continue
|
|
[ -d "$n" ] || continue
|
|
|
|
merge_dirs="${merge_dirs} $n/"
|
|
done
|
|
|
|
set -a
|
|
ENVSUBST_ARGS="${volume_root}/diag.envsubst.txt"
|
|
J2CFG_PATH="${merged_root}/j2cfg"
|
|
J2CFG_SEARCH_PATH="${merged_root}"
|
|
set +a
|
|
|
|
envsubst-args.sh > "${ENVSUBST_ARGS}"
|
|
|
|
## expand j2cfg templates first
|
|
|
|
expand_dir_envsubst j2cfg/ || expand_error
|
|
expand_dir_j2cfg j2cfg/ || expand_error
|
|
|
|
## expand other templates
|
|
|
|
expand_dir_envsubst ${merge_dirs} || expand_error
|
|
|
|
unset j2cfg_dump
|
|
j2cfg_dump="${volume_root}/diag.j2cfg.yml"
|
|
|
|
j2cfg-dump > "${j2cfg_dump}" || expand_error
|
|
|
|
export J2CFG_CONFIG="${j2cfg_dump}"
|
|
|
|
expand_dir_j2cfg ${merge_dirs} || expand_error
|
|
|
|
## remove template sources in order to avoid leaking sensitive data
|
|
if [ "${NGX_PROCESS_STATIC}" = 1 ] ; then
|
|
__template_list=$(mktemp)
|
|
|
|
find static/ -follow -type f -printf '%p\0' \
|
|
| grep -zE '\.(in|j2)$' \
|
|
| {
|
|
if [ -n "${NGX_TEMPLATE_EXCLUDE_REGEX:-}" ] ; then
|
|
grep -zEv -e "${NGX_TEMPLATE_EXCLUDE_REGEX}"
|
|
elif [ -n "${NGX_TEMPLATE_INCLUDE_REGEX:-}" ] ; then
|
|
grep -zE -e "${NGX_TEMPLATE_INCLUDE_REGEX}"
|
|
else
|
|
cat
|
|
fi
|
|
} \
|
|
| sort -zuV > "${__template_list}"
|
|
|
|
if [ -s "${__template_list}" ] ; then
|
|
xargs -0r -n 1000 -a "${__template_list}" \
|
|
rm -fv < /dev/null
|
|
fi
|
|
|
|
rm -f "${__template_list}" ; unset __template_list
|
|
fi
|
|
|
|
exit 0
|