|
| 1 | +# syntax=docker/dockerfile:1.18 |
| 2 | +FROM scratch AS nginx-files |
| 3 | + |
| 4 | +# NGINX Plus repo and key files (must be provided at build time) |
| 5 | +ADD --link --chown=101:1001 https://cs.nginx.com/static/files/plus-9.repo nginx-plus.repo |
| 6 | +ADD --link --chown=101:1001 https://nginx.org/keys/nginx_signing.key nginx_signing.key |
| 7 | +ADD --link --chown=101:1001 build/ubi/repos/agent.repo agent.repo |
| 8 | + |
| 9 | +FROM ghcr.io/nginx/dependencies/nginx-ubi:ubi9@sha256:01a32246761b9bbe47a6a29bcd8ca6e9b6e331b3bdfa372d8987b622276f7025 AS ubi9-packages |
| 10 | + |
| 11 | +FROM redhat/ubi9-minimal:9.6 AS ubi-nginx-plus |
| 12 | + |
| 13 | +ARG NGINX_PLUS_VERSION=R35 |
| 14 | + |
| 15 | +# renovate: datasource=github-tags depName=nginx/agent |
| 16 | +ARG NGINX_AGENT_VERSION=v3.3.1 |
| 17 | +ARG NJS_DIR |
| 18 | +ARG NGINX_CONF_DIR |
| 19 | +ARG BUILD_AGENT |
| 20 | + |
| 21 | +LABEL name="F5 NGINX Gateway Fabric NGINX Plus" \ |
| 22 | + maintainer="kubernetes@nginx.com" \ |
| 23 | + vendor="F5 NGINX" \ |
| 24 | + summary="NGINX Gateway Fabric" \ |
| 25 | + description="NGINX Gateway Fabric provides an implementation for the Gateway API using NGINX as the data plane." \ |
| 26 | + org.nginx.ngf.image.build.agent="${BUILD_AGENT}" \ |
| 27 | + io.k8s.description="NGINX Gateway Fabric provides an implementation for the Gateway API using NGINX as the data plane." \ |
| 28 | + io.openshift.tags="nginx,gateway,kubernetes,openshift" |
| 29 | + |
| 30 | +COPY --link --chown=101:1001 LICENSE /licenses/ |
| 31 | + |
| 32 | +# Install NGINX Plus and modules |
| 33 | +RUN --mount=type=bind,from=nginx-files,src=nginx-plus.repo,target=/etc/yum.repos.d/nginx-plus.repo \ |
| 34 | + --mount=type=bind,from=nginx-files,src=agent.repo,target=/etc/yum.repos.d/agent.repo \ |
| 35 | + --mount=type=bind,from=nginx-files,src=nginx_signing.key,target=/tmp/nginx_signing.key \ |
| 36 | + --mount=type=bind,from=ubi9-packages,src=/,target=/ubi-bin/ \ |
| 37 | + --mount=type=secret,id=nginx-repo.crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode=0644 \ |
| 38 | + --mount=type=secret,id=nginx-repo.key,dst=/etc/ssl/nginx/nginx-repo.key,mode=0644 \ |
| 39 | + # Install shadow-utils for useradd and subscription-manager for repo access |
| 40 | + microdnf --nodocs install -y shadow-utils subscription-manager \ |
| 41 | + && rpm --import /tmp/nginx_signing.key \ |
| 42 | + # Install c-ares from the dependencies image (contains required libs) |
| 43 | + && rpm -Uvh /ubi-bin/c-ares-*.rpm \ |
| 44 | + # Create nginx user with consistent UID/GID |
| 45 | + && groupadd -g 1001 nginx \ |
| 46 | + && useradd -r -u 101 -g nginx -s /sbin/nologin -d /var/cache/nginx nginx \ |
| 47 | + # Install NGINX Plus and modules (njs, otel) |
| 48 | + && microdnf --nodocs install -y nginx-plus-${NGINX_PLUS_VERSION,,} \ |
| 49 | + && microdnf --nodocs install -y nginx-plus-module-njs-${NGINX_PLUS_VERSION,,} nginx-plus-module-otel-${NGINX_PLUS_VERSION,,} \ |
| 50 | + # Install nginx-agent |
| 51 | + && microdnf --nodocs install -y nginx-agent-${NGINX_AGENT_VERSION#v}* \ |
| 52 | + # Clean up |
| 53 | + && microdnf remove -y shadow-utils subscription-manager \ |
| 54 | + && microdnf clean all \ |
| 55 | + && rm -rf /var/cache/yum |
| 56 | + |
| 57 | +# Configure directories and logging |
| 58 | +RUN mkdir -p /usr/lib/nginx/modules /var/run/nginx /usr/lib64/nginx/modules \ |
| 59 | + # Forward request and error logs to docker log collector |
| 60 | + && ln -sf /dev/stdout /var/log/nginx/access.log \ |
| 61 | + && ln -sf /dev/stderr /var/log/nginx/error.log \ |
| 62 | + && mv /usr/lib64/nginx/modules/ngx_* /usr/lib/nginx/modules/ |
| 63 | + |
| 64 | +# Copy default html files to a writable location |
| 65 | +RUN mkdir -p /etc/nginx/html \ |
| 66 | + && cp /usr/share/nginx/html/* /etc/nginx/html/ |
| 67 | + |
| 68 | +# Set proper permissions for nginx user |
| 69 | +RUN chown -R 101:1001 /etc/nginx /var/cache/nginx |
| 70 | + |
| 71 | +# Copy configuration files and scripts |
| 72 | +COPY build/entrypoint.sh /agent/entrypoint.sh |
| 73 | +COPY ${NJS_DIR}/ /usr/lib/nginx/modules/njs/ |
| 74 | +COPY ${NGINX_CONF_DIR}/nginx.conf /etc/nginx/nginx.conf |
| 75 | +COPY ${NGINX_CONF_DIR}/grpc-error-locations.conf /etc/nginx/grpc-error-locations.conf |
| 76 | +COPY ${NGINX_CONF_DIR}/grpc-error-pages.conf /etc/nginx/grpc-error-pages.conf |
| 77 | + |
| 78 | +# Switch to non-root user |
| 79 | +USER 101:1001 |
| 80 | + |
| 81 | +ENTRYPOINT ["/agent/entrypoint.sh"] |
0 commit comments