with podman & nginx docker image.
envsubst will be automatically executed when template file is in correct location /etc/nginx/templates in the nginx-container.
I added CSP (Content Security Policy) script-src hash to my nginx conf serving react app like this:
default.conf.template
server {
listen 8080;
root /usr/share/nginx/html;
include /etc/nginx/mime.types;
location / {
add_header Content-Security-Policy "script-src 'self' '$CSP_SCRIPT_HASH' 'strict-dynamic'";
try_files $uri $uri/ /index.html;
}
}
Dockerfile
FROM nginx:1.23.4-alpine
COPY --from=build /opt/app/build /usr/share/nginx/html
COPY nginx/templates /etc/nginx/templates/
EXPOSE 8080
Calling podman run with
podman run -e CSP_SCRIPT_HASH=sha256-wM+PPlLHcZenNEqjDFKpiuJrcOoeek6E0V5NxAro/Fc= --name mycontainername <my_nginx_image_app>
This should envsubst $CSP_SCRIPT_HASH with sha256-wM+PPlLHcZenNEqjDFKpiuJrcOoeek6E0V5NxAro/Fc=
You can run podman logs to see if envsubst is automatically executed
podman logs mycontainername
output should have like this
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
...
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/default.conf.template to /etc/nginx/conf.d/default.conf
...
/docker-entrypoint.sh: Configuration complete; ready for start up
Log verify that envsubst is executed for /etc/nginx/templates/default.conf.template file and the result file is put into correct folder /etc/nginx/conf.d/default.conf
With this I can configure when deploying my container that which additional script CSP allow to be executed by giving the hash of the script as environment variable and it is applied in nginx conf.
envsubst
. This without requiring docker or lua+perl as described in this question: #2914720 – Hiroshima