1
0

Compare commits

..

2 Commits

Author SHA1 Message Date
1dda7066c9
fix inconsistences in j2cfg 2024-07-20 18:29:09 +03:00
288d27f9f2
misc minor fixes 2024-07-20 17:12:15 +03:00
8 changed files with 160 additions and 25 deletions

View File

@ -1,8 +1,8 @@
FROM docker.io/rockdrilla/angie-conv:deps-v1 as deps FROM docker.io/rockdrilla/angie-conv:deps-v1 AS deps
## --- ## ---
FROM deps as certs FROM deps AS certs
SHELL [ "/bin/sh", "-ec" ] SHELL [ "/bin/sh", "-ec" ]
COPY /scripts/* /usr/local/sbin/ COPY /scripts/* /usr/local/sbin/
@ -20,7 +20,7 @@ RUN pkg='curl' ; \
## --- ## ---
FROM deps as pycache FROM deps AS pycache
SHELL [ "/bin/sh", "-ec" ] SHELL [ "/bin/sh", "-ec" ]
COPY /scripts/* /usr/local/sbin/ COPY /scripts/* /usr/local/sbin/
@ -50,9 +50,9 @@ RUN libpython="${PYTHON_SITE_PACKAGES%/*}" ; \
python3 -m compileall -q -j 2 python3 -m compileall -q -j 2
## Python cache warmup ## Python cache warmup
RUN echo > /tmp/f.j2 ; \ RUN j2cfg-single /usr/local/lib/j2cfg/test.j2 /tmp/test ; \
j2cfg-single /tmp/f.j2 ; \ cat /tmp/test ; echo ; \
rm -f /tmp/f /tmp/f.j2 rm -f /tmp/test
## Python cache adjustments ## Python cache adjustments
RUN d="@$(date '+%s')" ; \ RUN d="@$(date '+%s')" ; \
@ -136,7 +136,7 @@ RUN install -d -o angie -g angie -m 03777 /angie /run/angie ; \
ln -sv /run/angie/lib /var/lib/angie ; \ ln -sv /run/angie/lib /var/lib/angie ; \
ln -sv /run/angie/log /var/log/angie ; \ ln -sv /run/angie/log /var/log/angie ; \
## adjust paths in config directory ## adjust paths in config directory
cd /etc/angie/ ; \ cd /etc/angie || exit 1 ; \
ln -sv /run/angie run ; \ ln -sv /run/angie run ; \
ln -sv /run/angie/lock lock.d ; \ ln -sv /run/angie/lock lock.d ; \
ln -sv ${ANGIE_MODULES_DIR} modules.dist ; \ ln -sv ${ANGIE_MODULES_DIR} modules.dist ; \
@ -161,7 +161,7 @@ RUN find /etc/angie/ -name .gitkeep -delete ; \
## preseed builtin modules list ## preseed builtin modules list
RUN x='angie-builtin-modules.sh' ; \ RUN x='angie-builtin-modules.sh' ; \
"$x" ; \ "$x" ; \
chmod a-x $(which "$x") chmod a-x "$(which "$x")"
## misc tools ## misc tools
RUN apt-install.sh \ RUN apt-install.sh \
@ -196,8 +196,7 @@ COPY /image-entry.d/ /image-entry.d/
## misc defaults ## misc defaults
ENV DUMB_INIT_SETSID=0 \ ENV DUMB_INIT_SETSID=0 \
MALLOC_ARENA_MAX=4 \ MALLOC_ARENA_MAX=4
GOMAXPROCS=4
STOPSIGNAL SIGQUIT STOPSIGNAL SIGQUIT

View File

@ -1,8 +1,8 @@
# FROM docker.io/debian:bookworm-slim as base-upstream # FROM docker.io/debian:bookworm-slim as base-upstream
ARG PYTHONTAG=3.11.9-slim-bookworm ARG PYTHONTAG=3.11.9-slim-bookworm
FROM docker.io/python:${PYTHONTAG} as base-upstream FROM docker.io/python:${PYTHONTAG} AS base-upstream
FROM base-upstream as base FROM base-upstream AS base
SHELL [ "/bin/sh", "-ec" ] SHELL [ "/bin/sh", "-ec" ]
COPY /Dockerfile.base /usr/local/share/ COPY /Dockerfile.base /usr/local/share/
@ -52,8 +52,8 @@ RUN apt-env.sh apt-get update ; \
## perl-base: hardlink->symlink ## perl-base: hardlink->symlink
RUN d=/usr/bin ; \ RUN d=/usr/bin ; \
find $d/ -wholename "$d/perl5*" -exec ln -fsv perl {} ';' ; \ find "$d/" -wholename "$d/perl5*" -exec ln -fsv perl {} ';' ; \
ls -li $d/perl* ls -li "$d/perl"*
## remove unwanted binaries ## remove unwanted binaries
RUN set -f ; \ RUN set -f ; \

View File

@ -1,8 +1,8 @@
FROM docker.io/rockdrilla/angie-conv:base-v1 as base FROM docker.io/rockdrilla/angie-conv:base-v1 AS base
## --- ## ---
FROM base as setup FROM base AS setup
SHELL [ "/bin/sh", "-ec" ] SHELL [ "/bin/sh", "-ec" ]
COPY /scripts/* /usr/local/sbin/ COPY /scripts/* /usr/local/sbin/
@ -29,7 +29,7 @@ ENV CIBUILDWHEEL=1
# pyyaml # pyyaml
ENV PYYAML_FORCE_CYTHON=1 ENV PYYAML_FORCE_CYTHON=1
RUN w=$(mktemp -d) ; \ RUN w=$(mktemp -d) ; : "${w:?}" ; \
{ apt-mark showauto ; apt-mark showmanual ; } | sort -uV > "$w/t0" ; \ { apt-mark showauto ; apt-mark showmanual ; } | sort -uV > "$w/t0" ; \
printf '%s\n' ${DEV_PACKAGES} | sort -uV > "$w/t1" ; \ printf '%s\n' ${DEV_PACKAGES} | sort -uV > "$w/t1" ; \
apt-install.sh ${DEV_PACKAGES} ; \ apt-install.sh ${DEV_PACKAGES} ; \
@ -61,7 +61,7 @@ RUN w=$(mktemp -d) ; \
## --- ## ---
FROM base as deps FROM base AS deps
SHELL [ "/bin/sh", "-ec" ] SHELL [ "/bin/sh", "-ec" ]
COPY /Dockerfile.deps /usr/local/share/ COPY /Dockerfile.deps /usr/local/share/

View File

@ -117,13 +117,14 @@ class J2cfg:
def merge_dict_default(): def merge_dict_default():
search_pattern = '|'.join(['*.' + ext for ext in J2CFG_CONFIG_EXT]) search_pattern = '|'.join(['*.' + ext for ext in J2CFG_CONFIG_EXT])
search_flags = wcmatch.wcmatch.RECURSIVE | wcmatch.wcmatch.SYMLINKS search_flags = wcmatch.wcmatch.SYMLINKS
for d in self.config_path: for d in self.config_path:
if not os.path.isdir(d): if not os.path.isdir(d):
continue continue
for f in wcmatch.wcmatch.WcMatch(d, search_pattern, m = wcmatch.wcmatch.WcMatch(d, search_pattern,
flags=search_flags).imatch(): flags=search_flags)
for f in sorted(m.match()):
merge_dict_from_file(f) merge_dict_from_file(f)
if self.config_file is None: if self.config_file is None:
@ -203,6 +204,9 @@ class J2cfg:
continue continue
self.ensure_fs_loader_for(d) self.ensure_fs_loader_for(d)
dirs.insert(0, d) dirs.insert(0, d)
if f_in.startswith('/'):
self.ensure_fs_loader_for('/')
dirs.append('/')
j2_environ = self.j2env.overlay(loader=jinja2.ChoiceLoader([ j2_environ = self.j2env.overlay(loader=jinja2.ChoiceLoader([
self.j2fs_loaders[d] for d in dirs self.j2fs_loaders[d] for d in dirs

View File

@ -74,7 +74,7 @@ def str_list_re_sub(a: list, pattern, repl, count=0, flags=0) -> list:
def sh_like_file_to_list(j2env, file_in: str) -> list: def sh_like_file_to_list(j2env, file_in: str) -> list:
tpl = j2env.get_template(file_in) tpl = j2env.get_template(file_in)
text = pathlib.Path(tpl.filename).read_text(encoding='utf-8') text = pathlib.Path(tpl.filename).read_text(encoding='utf-8')
lines = re.split(r'\r\n', text) lines = re.split(r'[\r\n]', text)
return list(itertools.filterfalse( return list(itertools.filterfalse(
lambda x: re.match(r'\s*#', x), lines lambda x: re.match(r'\s*#', x), lines
)) ))

View File

@ -1,9 +1,9 @@
J2CFG_TEMPLATE_EXT = '.j2' J2CFG_TEMPLATE_EXT = '.j2'
J2CFG_PATH = [ J2CFG_PATH = [
'/etc/angie/j2cfg.dist',
'/etc/angie/j2cfg',
'/angie/j2cfg', '/angie/j2cfg',
'/etc/angie/j2cfg',
'/etc/angie/j2cfg.dist',
] ]
J2CFG_PYTHON_MODULES = [ J2CFG_PYTHON_MODULES = [

132
j2cfg/test.j2 Normal file
View File

@ -0,0 +1,132 @@
j2cfg:
{{ j2cfg }}
{% set x = [2,3,1,2] %}
x = {{ x }}
uniq_list:
{{ x | uniq_list }}
{% set x = ['2',3,'1','2'] %}
x = {{ x }}
list_remove_non_str:
{{ x | list_remove_non_str }}
{% set x = ['2','','1','2'] %}
x = {{ x }}
list_remove_empty_str:
{{ x | list_remove_empty_str }}
{% set x = ['2','3','1','2'] %}
x = {{ x }}
uniq_str_list:
{{ x | uniq_str_list }}
{% set x = '2 3 1 2 ' %}
"x = {{ x }}"
str_split_to_list:
{{ x | str_split_to_list }}
{% set x = '2:3::1:2:' %}
"x = {{ x }}"
str_split_to_list(':'):
{{ x | str_split_to_list(':') }}
{% set x = [1,2,3,4] %}
x = {{ x }}
is_sequence:
{{ x | is_sequence }}
{% set x = {1:2,3:4} %}
x = {{ x }}
is_sequence:
{{ x | is_sequence }}
{% set x = [1,2,3,4] %}
x = {{ x }}
is_mapping:
{{ x | is_mapping }}
{% set x = {1:2,3:4} %}
x = {{ x }}
is_mapping:
{{ x | is_mapping }}
{% set x = '1 2 3 4' %}
"x = {{ x }}"
any_to_str_list:
{{ x | any_to_str_list }}
{% set x = [1,2,3,4] %}
x = {{ x }}
any_to_str_list:
{{ x | any_to_str_list }}
{% set x = 3.1415926 %}
x = {{ x }}
any_to_str_list:
{{ x | any_to_str_list }}
{% set x = ['a2','b3','c1','d2'] %}
x = {{ x }}
is_str_list_re_match('[ab]'):
{{ x | is_str_list_re_match('[ab]') }}
is_str_list_re_match('[mn]'):
{{ x | is_str_list_re_match('[mn]') }}
{% set x = ['a2','b3','c1','d2'] %}
x = {{ x }}
is_str_list_re_fullmatch('[ab]'):
{{ x | is_str_list_re_fullmatch('[ab]') }}
is_str_list_re_fullmatch('[ab][12]'):
{{ x | is_str_list_re_fullmatch('[ab][12]') }}
{% set x = ['a2','b3','c1','d2'] %}
x = {{ x }}
str_list_re_match('[ab]'):
{{ x | str_list_re_match('[ab]') }}
str_list_re_match('[mn]'):
{{ x | str_list_re_match('[mn]') }}
{% set x = ['a2','b3','c1','d2'] %}
x = {{ x }}
str_list_re_fullmatch('[ab]'):
{{ x | str_list_re_fullmatch('[ab]') }}
str_list_re_fullmatch('[ab][12]'):
{{ x | str_list_re_fullmatch('[ab][12]') }}
{% set x = ['a2b','b3b','c1f','d2g'] %}
x = {{ x }}
str_list_re_sub('[ab]', '_'):
{{ x | str_list_re_sub('[ab]', '_') }}
str_list_re_sub('[mn]', '_'):
{{ x | str_list_re_sub('[mn]', '_') }}
{% set x = 'j2cfg-multi.py' %}
x = {{ x }}
sh_like_file_to_list:
{{ 'j2cfg-multi.py' | sh_like_file_to_list }}
{% set x = 'Accept-Encoding' %}
x = {{ x }}
as_cgi_header:
{{ x | as_cgi_header }}
{% set x = '_Permissions-Policy--' %}
x = {{ x }}
as_cgi_header:
{{ x | as_cgi_header }}
{% set x = 'VAR1=Etc/UTC' %}
x = {{ x }}
env_any_to_str_list:
{{ x | env_any_to_str_list }}
{% set x = ['VAR1=Etc/UTC', 'VAR2=', 'VAR3', '4VAR4=yeah', 'VAR5=yeah', 'VAR5=not-yeah'] %}
x = {{ x }}
env_any_to_str_list:
{{ x | env_any_to_str_list }}
{% set x = { 'VAR1': 'Etc/UTC', 'VAR2': '', 'VAR3': None, '4VAR4': 'yeah', 'VAR5=not': 'yeah', 'VAR5=real yeah': None, 'VAR6': {'pi': 3.1415926}, 'VAR7': ['pi', 3.1415926] } %}
x = {{ x }}
env_any_to_str_list:
{{ x | env_any_to_str_list }}

View File

@ -5,7 +5,7 @@ conf_dir='/etc/angie'
conf_file="${conf_dir}/.none.conf" conf_file="${conf_dir}/.none.conf"
pid_file='/run/angie/none.pid' pid_file='/run/angie/none.pid'
angie -g "error_log /dev/stderr warn; pid ${pid_file};" -c "${conf_file}" -t angie -q -e /dev/stderr -g "error_log /dev/stderr warn; pid ${pid_file};" -c "${conf_file}" -t
r=$? r=$?
rm -f "${pid_file}" rm -f "${pid_file}"
[ $r -eq 0 ] || exit $r [ $r -eq 0 ] || exit $r