Refactor Dockerfile to parameterize user and group IDs for enhanced flexibility
Some checks failed
Talks slides — image & chart / vars (push) Successful in 2s
Talks slides — image & chart / Helm chart (push) Successful in 9s
Talks slides — image & chart / Build container image (push) Failing after 23s

- Introduced ARG variables for UID and GID to allow dynamic user and group configuration.
- Updated ownership commands to utilize the new UID and GID parameters, improving compatibility with different environments.
- Maintained non-root user practices while ensuring proper permissions for Nginx and associated files.
This commit is contained in:
Le Prévost-Corvellec Arnault
2026-04-08 22:06:28 +02:00
parent 600c07e358
commit 4a5cbb950b

View File

@@ -1,8 +1,11 @@
# syntax=docker/dockerfile:1
# Image officielle « non-root » (nginxinc) : pid, user, port 8080 — on nimite pas nginx:alpine à coups de sed.
# https://github.com/nginxinc/docker-nginx-unprivileged
# Même logique que limage upstream : UID/GID numériques, pas le nom « nginx ».
# https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/stable/alpine/Dockerfile
FROM nginxinc/nginx-unprivileged:stable-alpine
ARG UID=101
ARG GID=101
USER root
RUN --mount=type=cache,target=/var/cache/apk \
apk add --no-cache git
@@ -21,16 +24,15 @@ RUN find . -mindepth 1 -delete \
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
COPY refresh.sh /refresh.sh
# Même UID que limage (nginx, 101) ; pas de retouche manuelle de nginx.conf.
RUN chmod +x /refresh.sh \
&& chown -R nginx:nginx /usr/share/nginx/html /refresh.sh \
&& chown -R "${UID}:${GID}" /usr/share/nginx/html /refresh.sh \
&& mkdir -p /home/nginx \
&& chown nginx:nginx /home/nginx \
&& su nginx -s /bin/sh -c 'HOME=/home/nginx git config --global --add safe.directory /usr/share/nginx/html'
&& chown "${UID}:${GID}" /home/nginx \
&& su "${UID}" -s /bin/sh -c 'HOME=/home/nginx git config --global --add safe.directory /usr/share/nginx/html'
ENV HOME=/home/nginx
USER nginx
USER ${UID}
EXPOSE 8080