mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-21 21:44:40 +03:00
Five fixes to the Docker image, found while running it-tools on OpenShift, where containers run as an arbitrary UID. No application code is changed. Start on a read-only filesystem. `docker run --read-only` and Kubernetes readOnlyRootFilesystem crash-loop the container, because 20-envsubst-on-templates.sh checks its output directory with `[ ! -w $dir ]`. That only reads permission bits, so a read-only mount passes the check, the write fails with EROFS and `set -e` stops the entrypoint. 19-skip-envsubst-if-readonly.envsh now tests the directory with a real write and, on failure, points NGINX_ENVSUBST_TEMPLATE_DIR at a missing path so the envsubst script exits early. That is only safe if the config in the image is already correct, and today it is nginx's stock welcome config, so the Dockerfile renders the template at build time as well. Writable setups are unchanged: the write test passes, nothing is exported and the config is rendered at startup as before, so a custom $PORT still works. Skip IPv6 when the host has none. nginx.conf always listens on IPv6, so where IPv6 is off nginx fails with `socket() [::]:8080 failed (97: Address family not supported by protocol)`. 25-remove-ipv6-listen-if-unavailable.sh comments those lines out, using the same /proc/net/if_inet6 check as nginx's own 10-listen-on-ipv6-by-default.sh, and exits at once when IPv6 works. It probes the directory before editing, because `sed -i` rewrites through a temporary file there, so a writable file in a read-only directory is not enough, and it tolerates a failed edit so it can never stop the entrypoint. Match workers to the cpu limit. `worker_processes auto` counts the host's cores, not the container's cpu limit, so the image starts 256 workers on a 256-core host in any container size. `docker run -m 192m` is enough to be OOM-killed at startup. Setting NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE enables the script nginx already ships. Containers without a cpu limit keep one worker per core. This is the only change that affects a deployment that works today. Return 404 for missing assets. All paths fall back to index.html, so a missing build file returns 200 and text/html, and the browser reports a confusing MIME error instead of a 404. /assets/ now skips the SPA fallback. Sub-folder requests such as /it-tools/assets/... still match `location /`, so those deployments do not change. Stop remapping js. nginx.conf includes mime.types, which already maps js, then maps it again, so every startup logs a duplicate extension warning. mime.types has no entry for mjs, so mjs stays and js goes. Signed-off-by: Sebastian Danielsson <sebastian.danielsson@proton.me>