1
0

initial commit

This commit is contained in:
2025-06-05 11:01:19 +03:00
commit 48f13f97a3
297 changed files with 7136 additions and 0 deletions

View File

@@ -0,0 +1,114 @@
#!/bin/sh
set -f
. /run/ngx/iep/00-common.envsh
## Angie: unset core variables
unset ANGIE ANGIE_BPF_MAPS
[ "${NGX_STRICT_LOAD}" = 0 ] || set -e
cd "${target_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
}
set +e
## NB: j2cfg/ and static/ are handled separately
merge_dirs=$(find ./ -follow -mindepth 1 -maxdepth 1 -type d -printf '%P/\n' | grep -Fxv -e j2cfg/ -e static/ | sort -uV)
[ "${NGX_STRICT_LOAD}" = 0 ] || set -e
unset ENVSUBST_ARGS
ENVSUBST_ARGS="${volume_root}/diag.envsubst.txt"
envsubst-args.sh > "${ENVSUBST_ARGS}"
export ENVSUBST_ARGS
## envsubst is simple and fast
## expand j2cfg/ first, then other directories
expand_dir_envsubst j2cfg/ || expand_error
expand_dir_envsubst ${merge_dirs} || expand_error
## j2cfg is more complex
unset J2CFG_CONFIG
set -a
J2CFG_PATH="${target_root}/j2cfg"
J2CFG_SEARCH_PATH="${target_root}"
set +a
## expand j2cfg/ first
expand_dir_j2cfg j2cfg/ || expand_error
## dump [merged] j2cfg config
j2cfg_dump="${volume_root}/diag.j2cfg.yml"
j2cfg-dump > "${j2cfg_dump}" || expand_error
export J2CFG_CONFIG="${j2cfg_dump}"
## expand other directories
expand_dir_j2cfg ${merge_dirs} || expand_error
## expand static/
## remove template sources in order to avoid leaking sensitive data
if [ "${NGX_HTTP_STATIC_TEMPLATE}" = 1 ] ; then
template_list=$(mktemp)
find static/ -follow -name '*.in' -type f \
| {
set +e
if [ -n "${NGX_STATIC_EXCLUDE_REGEX:-}" ] ; then
grep -Ev -e "${NGX_STATIC_EXCLUDE_REGEX}"
elif [ -n "${NGX_STATIC_INCLUDE_REGEX:-}" ] ; then
grep -E -e "${NGX_STATIC_INCLUDE_REGEX}"
else
cat
fi
} \
| sort -uV > "${template_list}"
while read -r src ; do
[ -n "${src}" ] || continue
expand_file_envsubst "${src}" || expand_error
rm -fv "${src}"
done < "${template_list}"
find static/ -follow -name '*.j2' -type f -printf '%p\0' \
| {
set +e
if [ -n "${NGX_STATIC_EXCLUDE_REGEX:-}" ] ; then
grep -zEv -e "${NGX_STATIC_EXCLUDE_REGEX}"
elif [ -n "${NGX_STATIC_INCLUDE_REGEX:-}" ] ; then
grep -zE -e "${NGX_STATIC_INCLUDE_REGEX}"
else
cat
fi
} \
| sort -zuV > "${template_list}"
if [ -s "${template_list}" ] ; then
xargs -0r -n 1000 -a "${template_list}" \
j2cfg-multi < /dev/null || expand_error
xargs -0r -n 1000 -a "${template_list}" \
rm -fv < /dev/null
fi
rm -f "${template_list}"
fi
exit 0