feat(nginx): bake default white-label routing config, closes #1 (#2)
All checks were successful
Build and publish / build (push) Successful in 20s
All checks were successful
Build and publish / build (push) Successful in 20s
## Summary - Add `nginx.conf.template` with full routing: admin/CMS surfaces → `cms:5555`, uploads → `cms:5555` (cached), `/api` → `shop:9999` (no cache), `/` → `shop:9999` (cached) - Update `docker-entrypoint.sh` to render template via `envsubst` at startup; skip if adapter has already mounted its own config - Update `Dockerfile` to `COPY nginx.conf.template` into image - Bump CHANGELOG to v0.1.1 ## Test plan - [ ] Build image locally: `docker build -t libreshop/nginx:test libreshop/nginx/` - [ ] Smoke test white-label default: no env overrides → confirm rendered `/etc/nginx/nginx.conf` contains `cms:5555` and `shop:9999` - [ ] Smoke test env override: `NGINX_UPSTREAM_SHOP=shop:8080` → confirm substitution - [ ] Smoke test adapter override: mount custom `nginx.conf` via compose `configs:` → confirm "adapter-provided nginx.conf detected" log line - [ ] Deploy libreshop/demo with `nginx:v0.1.1` → confirm `/admin` returns 200 Closes #1 Co-authored-by: Michael Czechowski <michael.c@re-cinq.com> Reviewed-on: #2
This commit is contained in:
@@ -1,19 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
echo "Generated nginx.conf:"
|
||||
echo ""
|
||||
# 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 "---"
|
||||
|
||||
mkdir -p /cache/shop
|
||||
mkdir -p /cache/uploads
|
||||
mkdir -p /cache/api
|
||||
|
||||
echo "Starting nginx"
|
||||
echo "NGINX_DEBUG=${NGINX_DEBUG}"
|
||||
# Start Nginx
|
||||
if [ "$NGINX_DEBUG" = "true" ]; then
|
||||
sed -i 's/error\.log warn/error.log debug/' /etc/nginx/nginx.conf
|
||||
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;'
|
||||
|
||||
Reference in New Issue
Block a user