All checks were successful
Build and publish / build (pull_request) Successful in 19s
The image used to ship just nginx + an entrypoint, with no routing
config — adapters had to mount their own nginx.conf via compose
`configs:` for anything to work. This broke the standalone
libreshop/demo preview (`curl /admin` returned 404).
Add a default nginx.conf.template that routes the standard libreshop
surface (`/admin`, `/uploads`, `/api`, `/`, ...) to
`${NGINX_UPSTREAM_CMS:-cms:5555}` / `${NGINX_UPSTREAM_SHOP:-shop:9999}`,
plus health and forwarded-headers handling. The entrypoint runs
envsubst at startup, then nginx.
Adapter override path is preserved: if compose `configs:` already
replaced /etc/nginx/nginx.conf with a non-stock file (detected via
the absence of the upstream nginx `worker_processes auto;` line),
the entrypoint leaves it untouched.
Closes #1.
38 lines
1.3 KiB
Bash
38 lines
1.3 KiB
Bash
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Defaults — overridable via env in compose / docker run.
|
|
: "${NGINX_UPSTREAM_SHOP:=shop:9999}"
|
|
: "${NGINX_UPSTREAM_CMS:=cms:5555}"
|
|
: "${NGINX_CACHE_LIFETIME:=1h}"
|
|
export NGINX_UPSTREAM_SHOP NGINX_UPSTREAM_CMS NGINX_CACHE_LIFETIME
|
|
|
|
# Render the template only when the nginx.conf in place is the
|
|
# upstream nginx-image stock default. Adapters that mount their own
|
|
# config via compose `configs:` (e.g. mp) get the file replaced
|
|
# before this script runs; we detect that by the absence of the
|
|
# stock `worker_processes auto;` line and leave that file alone.
|
|
if [ -f /etc/nginx/nginx.conf.template ] \
|
|
&& grep -q "worker_processes auto;" /etc/nginx/nginx.conf 2>/dev/null; then
|
|
envsubst '${NGINX_UPSTREAM_SHOP} ${NGINX_UPSTREAM_CMS} ${NGINX_CACHE_LIFETIME}' \
|
|
< /etc/nginx/nginx.conf.template \
|
|
> /etc/nginx/nginx.conf
|
|
echo "→ libreshop default nginx.conf rendered from template"
|
|
else
|
|
echo "→ adapter-provided nginx.conf detected; leaving untouched"
|
|
fi
|
|
|
|
mkdir -p /cache/shop /cache/uploads /cache/api
|
|
|
|
echo "Effective nginx.conf:"
|
|
echo "---"
|
|
cat /etc/nginx/nginx.conf
|
|
echo "---"
|
|
|
|
if [ "$NGINX_DEBUG" = "true" ]; then
|
|
perl -i -pe 's|error_log /dev/stdout error|error_log /dev/stdout debug|' /etc/nginx/nginx.conf
|
|
exec nginx-debug -g 'daemon off;'
|
|
else
|
|
exec nginx -g 'daemon off;'
|
|
fi
|