1
0

improve jinja2 template for env retention

This commit is contained in:
Konstantin Demin 2024-07-16 15:23:17 +03:00
parent c1e2d8d319
commit a747fbe080
Signed by: krd
GPG Key ID: 4D56F87A8BA65FD0
4 changed files with 33 additions and 38 deletions

View File

@ -1,3 +1,34 @@
{% for v in os.getenv('NGX_CORE_ENV', '').split(sep=' ') -%} {#- prologue -#}
{%- set penv = [] -%}
{%- if cfg.preserve_env -%}
{%- set penv = cfg.preserve_env -%}
{%- if penv is string -%}
{%- set penv = [penv] -%}
{%- elif penv is iterable -%}
{#- {%- set penv = penv -%} -#}
{%- else -%}
{%- set penv = [penv|string()] -%}
{%- endif -%}
{%- endif -%}
{%- set have = namespace() -%}
{%- set have.tz = false -%}
{%- set have.malloc_arena = false -%}
{#- scan -#}
{%- for v in penv -%}
{%- set have.tz = have.tz or re.match('TZ(=|$)', v|string()) -%}
{%- set have.malloc_arena = have.malloc_arena or re.match('MALLOC_ARENA_MAX(=|$)', v|string()) -%}
{%- endfor -%}
{#- main part -#}
{%- if not have.tz -%}
env TZ;
{% endif %}
{%- if not have.malloc_arena -%}
env MALLOC_ARENA_MAX;
{% endif %}
{%- for v in penv -%}
{%- if re.search("(\"|'|\\s)", v|string()) %}
env {{ (v|string()).__repr__() }};
{%- else %}
env {{ v }}; env {{ v }};
{% endfor -%} {%- endif %}
{%- endfor -%}

View File

@ -14,8 +14,6 @@ NGX_CORE_MODULES="${NGX_CORE_MODULES:-}"
NGX_CORE_EVENTS_SNIPPETS="${NGX_CORE_EVENTS_SNIPPETS:-}" NGX_CORE_EVENTS_SNIPPETS="${NGX_CORE_EVENTS_SNIPPETS:-}"
NGX_CORE_SNIPPETS="${NGX_CORE_SNIPPETS:-}" NGX_CORE_SNIPPETS="${NGX_CORE_SNIPPETS:-}"
NGX_CORE_ENV="${NGX_CORE_ENV:-}"
NGX_PROCESS_STATIC=$(gobool_to_int "${NGX_PROCESS_STATIC:-0}" 0) NGX_PROCESS_STATIC=$(gobool_to_int "${NGX_PROCESS_STATIC:-0}" 0)
set +a set +a

View File

@ -1,34 +0,0 @@
#!/bin/sh
if [ -z "${NGX_CORE_ENV:-}" ] ; then
NGX_CORE_ENV='TZ MALLOC_ARENA_MAX'
else
unset __set_f
__set_f=
case "${-}" in
*f* ) __set_f=1 ;;
esac
[ -n "${__set_f}" ] || set -f
unset __env __have_tz __have_malloc
for __env in ${NGX_CORE_ENV} ; do
case "${__env}" in
TZ | TZ=* )
__have_tz=1
;;
MALLOC_ARENA_MAX | MALLOC_ARENA_MAX=* )
__have_malloc=1
;;
esac
done
unset __env
[ -n "${__have_malloc}" ] || NGX_CORE_ENV="MALLOC_ARENA_MAX ${NGX_CORE_ENV}"
[ -n "${__have_tz}" ] || NGX_CORE_ENV="TZ ${NGX_CORE_ENV}"
unset __have_tz __have_malloc
[ -n "${__set_f}" ] || set +f
unset __set_f
fi
export NGX_CORE_ENV