diff --git a/Dockerfile b/Dockerfile index b0965a1..a7c96ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -138,7 +138,8 @@ RUN install -d -o angie -g angie -m 03777 /angie /run/angie ; \ ## adjust paths in config directory cd /etc/angie || exit 1 ; \ ln -sv /run/angie run ; \ - ln -sv /run/angie/lock lock.d ; \ + ln -sv /run/angie/load load ; \ + ln -sv /run/angie/lock lock ; \ ln -sv ${ANGIE_MODULES_DIR} modules.dist ; \ ## hyper-modular paths: data='conf j2cfg mod modules site snip static' ; \ diff --git a/angie/angie.conf b/angie/angie.conf index 7122434..9303fb3 100644 --- a/angie/angie.conf +++ b/angie/angie.conf @@ -1,23 +1,22 @@ daemon off; pid run/angie.pid; -lock_file lock.d/angie.lock; ## almost useless -include mod.d/core-*.load; +include load/mod-core-*.conf; -# mod-http.conf.in -# mod-mail.conf.in -# mod-stream.conf.in +# mod-http.conf +# mod-mail.conf +# mod-stream.conf include run/mod-*.conf; events { include conf.d/core_ev-*.conf; - include snip.d/core_ev-*.load; + include load/core_ev-*.conf; } include conf.d/core-*.conf; -include snip.d/core-*.load; +include load/core-*.conf; -# ctx-http.conf.in -# ctx-mail.conf.in -# ctx-stream.conf.in +# ctx-http.conf +# ctx-mail.conf +# ctx-stream.conf include run/ctx-*.conf; \ No newline at end of file diff --git a/angie/conf.dist/core-lock-file.conf b/angie/conf.dist/core-lock-file.conf new file mode 100644 index 0000000..c458950 --- /dev/null +++ b/angie/conf.dist/core-lock-file.conf @@ -0,0 +1 @@ +lock_file lock/angie.lock; \ No newline at end of file diff --git a/angie/conf.dist/core-user.conf.in b/angie/conf.dist/core-user.conf.in index 33929d2..86558e3 100644 --- a/angie/conf.dist/core-user.conf.in +++ b/angie/conf.dist/core-user.conf.in @@ -1 +1,3 @@ +## if container is running in non-privileged mode, +## then this file is going to be removed by /image-entry.d/76-adjust-core-user.sh user ${NGX_USER} ${NGX_GROUP}; \ No newline at end of file diff --git a/angie/ctx-http.conf b/angie/ctx-http.conf index aea7f06..5099ae4 100644 --- a/angie/ctx-http.conf +++ b/angie/ctx-http.conf @@ -1,5 +1,5 @@ http { include conf.d/http-*.conf; - include snip.d/http-*.load; + include load/http-*.conf; include site.d/http-*.conf; } \ No newline at end of file diff --git a/angie/ctx-mail.conf b/angie/ctx-mail.conf index 49903a7..6fce075 100644 --- a/angie/ctx-mail.conf +++ b/angie/ctx-mail.conf @@ -1,5 +1,5 @@ mail { include conf.d/mail-*.conf; - include snip.d/mail-*.load; + include load/mail-*.conf; include site.d/mail-*.conf; } \ No newline at end of file diff --git a/angie/ctx-stream.conf b/angie/ctx-stream.conf index 324b691..d45bdc8 100644 --- a/angie/ctx-stream.conf +++ b/angie/ctx-stream.conf @@ -1,5 +1,5 @@ stream { include conf.d/stream-*.conf; - include snip.d/stream-*.load; + include load/stream-*.conf; include site.d/stream-*.conf; } \ No newline at end of file diff --git a/angie/mod-http.conf b/angie/mod-http.conf index d18a01d..e1f2f3a 100644 --- a/angie/mod-http.conf +++ b/angie/mod-http.conf @@ -1 +1 @@ -include mod.d/http-*.load; \ No newline at end of file +include load/mod-http-*.conf; \ No newline at end of file diff --git a/angie/mod-mail.conf b/angie/mod-mail.conf index 015317b..67c6775 100644 --- a/angie/mod-mail.conf +++ b/angie/mod-mail.conf @@ -1 +1 @@ -include mod.d/mail-*.load; \ No newline at end of file +include load/mod-mail-*.conf; \ No newline at end of file diff --git a/angie/mod-stream.conf b/angie/mod-stream.conf index 2eba682..2807adb 100644 --- a/angie/mod-stream.conf +++ b/angie/mod-stream.conf @@ -1 +1 @@ -include mod.d/stream-*.load; \ No newline at end of file +include load/mod-stream-*.conf; \ No newline at end of file diff --git a/image-entry.d/01-defaults.envsh b/image-entry.d/01-defaults.envsh index a975b42..1daecf4 100755 --- a/image-entry.d/01-defaults.envsh +++ b/image-entry.d/01-defaults.envsh @@ -34,3 +34,23 @@ NGX_DIRS_LINK=$(sort_dedup_list "${default_dirs_link} ${NGX_DIRS_LINK:-}") set +a unset default_dirs_merge default_dirs_link + +unset i dirs_link +dirs_link= +for i in ${NGX_DIRS_LINK:-} ; do + [ -n "$i" ] || continue + + ## naive deduplication + case " ${NGX_DIRS_MERGE} " in + *" $i "* ) + log "$i is already specified in NGX_DIRS_MERGE - removing from NGX_DIRS_LINK" + continue + ;; + esac + + dirs_link="${dirs_link}${dirs_link:+ }$i" +done +unset i + +export NGX_DIRS_LINK="${dirs_link}" +unset dirs_link diff --git a/image-entry.d/10-core.envsh b/image-entry.d/10-core.envsh index a4efb06..8c61f75 100755 --- a/image-entry.d/10-core.envsh +++ b/image-entry.d/10-core.envsh @@ -3,7 +3,7 @@ set -a NGX_CORE_MODULES="${NGX_CORE_MODULES:-}" -NGX_CORE_EVENTS_SNIPPETS="${NGX_CORE_EVENTS_SNIPPETS:-}" -NGX_CORE_SNIPPETS="${NGX_CORE_SNIPPETS:-}" +NGX_CORE_CONFLOAD="${NGX_CORE_CONFLOAD:-}" +NGX_CORE_EVENTS_CONFLOAD="${NGX_CORE_EVENTS_CONFLOAD:-}" set +a diff --git a/image-entry.d/11-core-modules.envsh b/image-entry.d/11-core-modules.envsh index 81cd1f9..4edfda1 100755 --- a/image-entry.d/11-core-modules.envsh +++ b/image-entry.d/11-core-modules.envsh @@ -1,8 +1,8 @@ #!/bin/sh -unset core_modules core_snippets +unset core_modules core_confload core_modules= -core_snippets="${NGX_CORE_SNIPPETS:-}" +core_confload="${NGX_CORE_CONFLOAD:-}" ## filter out builtin core modules unset i @@ -10,8 +10,8 @@ for i in ${NGX_CORE_MODULES:-} ; do [ -n "$i" ] || continue if is_builtin_module core "$i" ; then - log "$i is builtin module, moving to snippets" - core_snippets="${core_snippets} $i" + log "$i is builtin module, moving to confload" + core_confload="${core_confload} $i" continue fi @@ -29,8 +29,8 @@ unset i set -a NGX_CORE_MODULES="${core_modules}" -NGX_CORE_SNIPPETS=$(sort_dedup_list "${core_snippets}") -NGX_CORE_EVENTS_SNIPPETS=$(sort_dedup_list "${NGX_CORE_EVENTS_SNIPPETS}") +NGX_CORE_CONFLOAD=$(sort_dedup_list "${core_confload}") +NGX_CORE_EVENTS_CONFLOAD=$(sort_dedup_list "${NGX_CORE_EVENTS_CONFLOAD}") set +a -unset core_modules core_snippets +unset core_modules core_confload diff --git a/image-entry.d/20-http.envsh b/image-entry.d/20-http.envsh index 218f0cd..045b75d 100755 --- a/image-entry.d/20-http.envsh +++ b/image-entry.d/20-http.envsh @@ -1,10 +1,10 @@ #!/bin/sh if [ "${NGX_HTTP}" = 0 ] ; then - unset NGX_HTTP_MODULES NGX_HTTP_SNIPPETS + unset NGX_HTTP_MODULES NGX_HTTP_CONFLOAD else set -a NGX_HTTP_MODULES="${NGX_HTTP_MODULES:-}" - NGX_HTTP_SNIPPETS="${NGX_HTTP_SNIPPETS:-}" + NGX_HTTP_CONFLOAD="${NGX_HTTP_CONFLOAD:-}" set +a fi diff --git a/image-entry.d/21-http-modules.envsh b/image-entry.d/21-http-modules.envsh index e085766..4c024cf 100755 --- a/image-entry.d/21-http-modules.envsh +++ b/image-entry.d/21-http-modules.envsh @@ -1,9 +1,9 @@ #!/bin/sh if [ "${NGX_HTTP}" = 1 ] ; then - unset http_modules http_snippets + unset http_modules http_confload http_modules= - http_snippets="${NGX_HTTP_SNIPPETS:-}" + http_confload="${NGX_HTTP_CONFLOAD:-}" if [ -n "${NGX_HTTP_MODULES}" ] ; then ## angie-module-lua: depends on angie-module-ndk @@ -20,8 +20,8 @@ if [ "${NGX_HTTP}" = 1 ] ; then [ -n "$i" ] || continue if is_builtin_module http "$i" ; then - log "$i is builtin module, moving to snippets" - http_snippets="${http_snippets} $i" + log "$i is builtin module, moving to confload" + http_confload="${http_confload} $i" continue fi @@ -39,8 +39,8 @@ if [ "${NGX_HTTP}" = 1 ] ; then set -a NGX_HTTP_MODULES="${http_modules}" - NGX_HTTP_SNIPPETS=$(sort_dedup_list "${http_snippets}") + NGX_HTTP_CONFLOAD=$(sort_dedup_list "${http_confload}") set +a - unset http_modules http_snippets + unset http_modules http_confload fi diff --git a/image-entry.d/30-mail.envsh b/image-entry.d/30-mail.envsh index a4f2782..9f84dc6 100755 --- a/image-entry.d/30-mail.envsh +++ b/image-entry.d/30-mail.envsh @@ -1,10 +1,10 @@ #!/bin/sh if [ "${NGX_MAIL}" = 0 ] ; then - unset NGX_MAIL_MODULES NGX_MAIL_SNIPPETS + unset NGX_MAIL_MODULES NGX_MAIL_CONFLOAD else set -a NGX_MAIL_MODULES="${NGX_MAIL_MODULES:-}" - NGX_MAIL_SNIPPETS="${NGX_MAIL_SNIPPETS:-}" + NGX_MAIL_CONFLOAD="${NGX_MAIL_CONFLOAD:-}" set +a fi diff --git a/image-entry.d/31-mail-modules.envsh b/image-entry.d/31-mail-modules.envsh index 84bdc27..9f6c4af 100755 --- a/image-entry.d/31-mail-modules.envsh +++ b/image-entry.d/31-mail-modules.envsh @@ -1,9 +1,9 @@ #!/bin/sh if [ "${NGX_MAIL}" = 1 ] ; then - unset mail_modules mail_snippets + unset mail_modules mail_confload mail_modules= - mail_snippets="${NGX_MAIL_SNIPPETS:-}" + mail_confload="${NGX_MAIL_CONFLOAD:-}" ## filter out builtin mail modules unset i @@ -11,8 +11,8 @@ if [ "${NGX_MAIL}" = 1 ] ; then [ -n "$i" ] || continue if is_builtin_module mail "$i" ; then - log "$i is builtin module, moving to snippets" - mail_snippets="${mail_snippets} $i" + log "$i is builtin module, moving to confload" + mail_confload="${mail_confload} $i" continue fi @@ -30,8 +30,8 @@ if [ "${NGX_MAIL}" = 1 ] ; then set -a NGX_MAIL_MODULES="${mail_modules}" - NGX_MAIL_SNIPPETS=$(sort_dedup_list "${mail_snippets}") + NGX_MAIL_CONFLOAD=$(sort_dedup_list "${mail_confload}") set +a - unset mail_modules mail_snippets + unset mail_modules mail_confload fi diff --git a/image-entry.d/40-stream.envsh b/image-entry.d/40-stream.envsh index f800bd3..e1e90e7 100755 --- a/image-entry.d/40-stream.envsh +++ b/image-entry.d/40-stream.envsh @@ -1,10 +1,10 @@ #!/bin/sh if [ "${NGX_STREAM}" = 0 ] ; then - unset NGX_STREAM_MODULES NGX_STREAM_SNIPPETS + unset NGX_STREAM_MODULES NGX_STREAM_CONFLOAD else set -a NGX_STREAM_MODULES="${NGX_STREAM_MODULES:-}" - NGX_STREAM_SNIPPETS="${NGX_STREAM_SNIPPETS:-}" + NGX_STREAM_CONFLOAD="${NGX_STREAM_CONFLOAD:-}" set +a fi diff --git a/image-entry.d/41-stream-modules.envsh b/image-entry.d/41-stream-modules.envsh index 076d148..3156a45 100755 --- a/image-entry.d/41-stream-modules.envsh +++ b/image-entry.d/41-stream-modules.envsh @@ -1,9 +1,9 @@ #!/bin/sh if [ "${NGX_STREAM}" = 1 ] ; then - unset stream_modules stream_snippets + unset stream_modules stream_confload stream_modules= - stream_snippets="${NGX_STREAM_SNIPPETS:-}" + stream_confload="${NGX_STREAM_CONFLOAD:-}" ## filter out builtin stream modules unset i @@ -11,8 +11,8 @@ if [ "${NGX_STREAM}" = 1 ] ; then [ -n "$i" ] || continue if is_builtin_module stream "$i" ; then - log "$i is builtin module, moving to snippets" - stream_snippets="${stream_snippets} $i" + log "$i is builtin module, moving to confload" + stream_confload="${stream_confload} $i" continue fi @@ -30,8 +30,8 @@ if [ "${NGX_STREAM}" = 1 ] ; then set -a NGX_STREAM_MODULES="${stream_modules}" - NGX_STREAM_SNIPPETS=$(sort_dedup_list "${stream_snippets}") + NGX_STREAM_CONFLOAD=$(sort_dedup_list "${stream_confload}") set +a - unset stream_modules stream_snippets + unset stream_modules stream_confload fi diff --git a/image-entry.d/50-flush-run-volume.sh b/image-entry.d/60-flush-run-volume.sh similarity index 100% rename from image-entry.d/50-flush-run-volume.sh rename to image-entry.d/60-flush-run-volume.sh diff --git a/image-entry.d/51-topmost-configs.sh b/image-entry.d/61-topmost-configs.sh similarity index 100% rename from image-entry.d/51-topmost-configs.sh rename to image-entry.d/61-topmost-configs.sh diff --git a/image-entry.d/52-merge-tree.sh b/image-entry.d/62-merge-tree.sh similarity index 100% rename from image-entry.d/52-merge-tree.sh rename to image-entry.d/62-merge-tree.sh diff --git a/image-entry.d/53-expand-templates.sh b/image-entry.d/63-expand-templates.sh similarity index 100% rename from image-entry.d/53-expand-templates.sh rename to image-entry.d/63-expand-templates.sh diff --git a/image-entry.d/54-combine-tree.sh b/image-entry.d/64-combine-tree.sh similarity index 51% rename from image-entry.d/54-combine-tree.sh rename to image-entry.d/64-combine-tree.sh index 07cae8d..82ff37a 100755 --- a/image-entry.d/54-combine-tree.sh +++ b/image-entry.d/64-combine-tree.sh @@ -3,22 +3,6 @@ set -f . /image-entry.d/00-common.envsh -## sanity check -t=$(mktemp) || exit 1 - -for n in mod snip ; do - [ -d "${merged_root}/$n" ] || continue - find "${merged_root}/$n/" ! -type d -done \ -| grep -E "^${merged_root}/(mod|snip)/.+\.load\$" \ -| sort -V > "$t" - -if [ -s "$t" ] ; then - log_always 'these files will be EXPLICITLY skipped:' - log_file "$t" -fi -rm -f "$t" ; unset t - [ "${NGX_STRICT_LOAD}" = 0 ] || set -e load_error_delim() { @@ -54,7 +38,7 @@ done ## provide same symlinks as upstream (both Angie and nginx) docker images do d="${target_root}/log" [ -e "$d/access.log" ] || ln_s /dev/stdout "$d/access.log" || load_error -[ -e "$d/error.log" ] || ln_s /dev/stderr "$d/error.log" || load_error +[ -e "$d/error.log" ] || ln_s /dev/stderr "$d/error.log" || load_error ## NB: if any error occurs above then configuration is merely empty and/or broken @@ -78,7 +62,6 @@ $( find "${merged_root}/$n/" ! -type d done \ | grep -Ev \ - -e "^${merged_root}/(mod|snip)/.+\.load\$" \ -e "^${merged_root}/mod/[^/]+\.preseed\$" \ | sort -V ) @@ -102,87 +85,119 @@ done ## Angie modules are loaded in [strict] order! combine_modules() { [ -n "$1" ] || return 1 + local n n="$1" ; shift [ $# -ne 0 ] || return 0 - old_dir="${merged_root}/mod" - new_dir="${target_root}/mod" + local i m src_dir dst_dir src_name dst_name src_path dst_path dst_dir + src_dir="${merged_root}/mod" + dst_dir="${volume_root}/load" i=0 for m ; do [ -n "$m" ] || continue - old_name="$n-$m.conf" - old_path="${old_dir}/${old_name}" - if ! [ -f "${old_path}" ] ; then - log_always "file ${old_name} is not found in ${old_dir}/" + case "$m" in + /* | */../* | *\** | *\?* ) + log_always "module name '$m' is not legal, skipping" + continue + ;; + esac + + case "$m" in + */* ) src_name="$m.conf" ;; + * ) src_name="$n-$m.conf" ;; + esac + dst_name=$(printf 'mod-%s-%02d-%s.conf' "$n" "$i" "$m" | tr -s '/_' '_') + + src_path="${src_dir}/${src_name}" + if ! [ -f "${src_path}" ] ; then + log_always "file ${src_name} is not found in ${src_dir}/" load_error - log "file ${old_name} is skipped" + log "file ${src_name} is skipped" continue fi - new_name=$(printf "%s-%02d-%s.load" "$n" "$i" "$m") - new_path="${new_dir}/${new_name}" + dst_path="${dst_dir}/${dst_name}" - ln_cp "${old_path}" "${new_path}" + ln_cp "${src_path}" "${dst_path}" i=$((i+1)) - done ; unset m + done } -combine_snippets() { +combine_confload() { [ -n "$1" ] || return 1 + local n n="$1" ; shift [ $# -ne 0 ] || return 0 - old_dir="${merged_root}/snip" - new_dir="${target_root}/snip" + local s src_dir dst_dir src_name dst_name src_path dst_path + src_dir="${merged_root}/snip" + dst_dir="${volume_root}/load" for s ; do [ -n "$s" ] || continue - new_path="${new_dir}/$n-$s.load" - if [ -e "${new_path}" ] ; then - log "${new_path} already exists, skipping" + case "$s" in + /* | */../* | *\** | *\?* ) + log_always "snippet name '$s' is not legal, skipping" + continue + ;; + esac + + case "$s" in + */* ) src_name="$s.conf" ;; + * ) src_name="$n-$s.conf" ;; + esac + dst_name=$(printf '%s-%s.conf' "$n" "$s" | tr -s '/_' '_') + + dst_path="${dst_dir}/${dst_name}" + if [ -e "${dst_path}" ] ; then + log "${dst_path} already exists, skipping" continue fi - old_name="$n-$s.conf" - old_path="${old_dir}/${old_name}" - if ! [ -f "${old_path}" ] ; then - log_always "file ${old_name} is not found in ${old_dir}/" - if [ "${NGX_ALLOW_MISSING_SNIPPETS:-}" != 1 ] ; then + src_path="${src_dir}/${src_name}" + if ! [ -f "${src_path}" ] ; then + log_always "file ${src_name} is not found in ${src_dir}/" + if [ "${NGX_ALLOW_MISSING_CONFLOAD:-}" != 1 ] ; then load_error - log "file ${old_name} is skipped" + log "file ${src_name} is skipped" fi continue fi - ln_cp "${old_path}" "${new_path}" - done ; unset s + ln_cp "${src_path}" "${dst_path}" + done } +[ -d "${volume_root}/load" ] || install -d "${volume_root}/load" +find "${volume_root}/load/" -mindepth 1 -exec rm -rf {} + + combine_modules core ${NGX_CORE_MODULES:-} combine_modules http ${NGX_HTTP_MODULES:-} combine_modules mail ${NGX_MAIL_MODULES:-} combine_modules stream ${NGX_STREAM_MODULES:-} -unset NGX_ALLOW_MISSING_SNIPPETS +loose=$(( 1 - NGX_STRICT_LOAD )) +NGX_ALLOW_MISSING_CONFLOAD=$(gobool_to_int "${NGX_ALLOW_MISSING_CONFLOAD:-${loose}}" ${loose}) +unset loose -combine_snippets core ${NGX_CORE_SNIPPETS:-} -combine_snippets core_ev ${NGX_CORE_EVENTS_SNIPPETS:-} -combine_snippets http ${NGX_HTTP_SNIPPETS:-} -combine_snippets mail ${NGX_MAIL_SNIPPETS:-} -combine_snippets stream ${NGX_STREAM_SNIPPETS:-} +combine_confload core ${NGX_CORE_CONFLOAD:-} +combine_confload core_ev ${NGX_CORE_EVENTS_CONFLOAD:-} +combine_confload http ${NGX_HTTP_CONFLOAD:-} +combine_confload mail ${NGX_MAIL_CONFLOAD:-} +combine_confload stream ${NGX_STREAM_CONFLOAD:-} ## some modules doesn't have configuration at all -NGX_ALLOW_MISSING_SNIPPETS=1 +NGX_ALLOW_MISSING_CONFLOAD=1 -combine_snippets core ${NGX_CORE_MODULES:-} -combine_snippets http ${NGX_HTTP_MODULES:-} -combine_snippets mail ${NGX_MAIL_MODULES:-} -combine_snippets stream ${NGX_STREAM_MODULES:-} +combine_confload core ${NGX_CORE_MODULES:-} +combine_confload http ${NGX_HTTP_MODULES:-} +combine_confload mail ${NGX_MAIL_MODULES:-} +combine_confload stream ${NGX_STREAM_MODULES:-} exit 0 diff --git a/image-entry.d/55-remove-merged-tree.sh b/image-entry.d/65-remove-merged-tree.sh similarity index 100% rename from image-entry.d/55-remove-merged-tree.sh rename to image-entry.d/65-remove-merged-tree.sh diff --git a/image-entry.d/56-adjust-core-user.sh b/image-entry.d/66-adjust-core-user.sh similarity index 100% rename from image-entry.d/56-adjust-core-user.sh rename to image-entry.d/66-adjust-core-user.sh