Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
58d9674
Add initial Dockerfile to build NGINX OSS images based on ubi9-minimal
shaun-nx Sep 22, 2025
20d131e
Update repo files and use red hat registered ubi-minimal
shaun-nx Sep 22, 2025
3022205
Merge branch 'main' into feat/ubi-base-image
shaun-nx Sep 22, 2025
f154680
Get required UBI packages for NGINX and install agent
shaun-nx Sep 23, 2025
42c4cec
Merge branch 'main' into feat/ubi-base-image
shaun-nx Sep 23, 2025
b880fc7
Update entrypoint to find NGINX master process. Ensure `/tmp` is writ…
shaun-nx Sep 24, 2025
c46e928
Merge branch 'main' into feat/ubi-base-image
shaun-nx Sep 24, 2025
caaf91a
Build control plane from UBI base image. Move current Alpine dockerfi…
shaun-nx Sep 24, 2025
25cee52
Add Dockerfile to build NGINX Plus image based on ubi9-minimal
shaun-nx Sep 24, 2025
fd1498c
Fix eof errors
shaun-nx Sep 24, 2025
2e9bac0
Merge branch 'feat/openshift-support' into feat/ubi-base-image
shaun-nx Sep 24, 2025
85d8358
Move alpine base Dockerfiles back to build dir
shaun-nx Sep 25, 2025
0f03b47
Merge branch 'feat/openshift-support' into feat/ubi-base-image
shaun-nx Sep 25, 2025
d28416a
Fix merge conflict
shaun-nx Sep 25, 2025
523ebd1
Update labels
shaun-nx Sep 25, 2025
31750dd
Update lables for plus builds
shaun-nx Sep 25, 2025
7146752
Update lables to distinguish between OSS and Plus
shaun-nx Sep 25, 2025
e776ae1
Make NGINX Plus version configurable
shaun-nx Sep 25, 2025
c5e49a3
Update build/ubi/Dockerfile.nginx
shaun-nx Sep 25, 2025
bc7c10f
Update lables and remove BASE_IMAGE
shaun-nx Sep 25, 2025
cbcd7ca
Remove local reference to crt and key files
shaun-nx Sep 25, 2025
048c38c
Merge branch 'feat/openshift-support' into feat/ubi-base-image
shaun-nx Sep 26, 2025
d9155b2
Set permissions on required directories. Update lables
shaun-nx Sep 26, 2025
168e2b0
Update Makefile
shaun-nx Sep 26, 2025
00dbbc6
Ensure subscription manage and shadowutils are removed
shaun-nx Sep 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ repos:
rev: v6.0.0
hooks:
- id: trailing-whitespace
exclude: (^tests/results/|\.avdl$|_generated.go$)
exclude: (^operators/|^tests/results/|\.avdl$|_generated.go$)
- id: end-of-file-fixer
exclude: (^operators/)
- id: check-yaml
args: [--allow-multiple-documents]
exclude: (^charts/nginx-gateway-fabric/templates)
exclude: (^operators/|^charts/nginx-gateway-fabric/templates)
- id: check-added-large-files
exclude: (^operators/)
- id: check-merge-conflict
- id: check-case-conflict
- id: check-vcs-permalinks
Expand All @@ -24,7 +26,7 @@ repos:
args: [--fix=lf]
- id: no-commit-to-branch
- id: detect-private-key
exclude: (^examples/|^docs/|.*_test.go$)
exclude: (^operators/|^examples/|^docs/|.*_test.go$)

- repo: https://github.com/gitleaks/gitleaks
rev: v8.28.0
Expand Down
5 changes: 5 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ignore:
- config/crd/bases/
- deploy
- site/static
- operators/

rules:
braces: enable
Expand All @@ -17,6 +18,7 @@ rules:
comments-indentation:
ignore: |
charts/nginx-gateway-fabric/values.yaml
operators/
document-end: disable
document-start: disable
empty-lines: enable
Expand All @@ -27,6 +29,8 @@ rules:
spaces: consistent
indent-sequences: consistent
check-multi-line-strings: true
ignore: |
operators/
key-duplicates: enable
key-ordering: disable
line-length:
Expand All @@ -46,3 +50,4 @@ rules:
truthy:
ignore: |
.github/workflows/
operators/
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ NJS_DIR = internal/controller/nginx/modules/src
KIND_CONFIG_FILE = $(SELF_DIR)config/cluster/kind-cluster.yaml
NGINX_DOCKER_BUILD_PLUS_ARGS = --secret id=nginx-repo.crt,src=$(SELF_DIR)nginx-repo.crt --secret id=nginx-repo.key,src=$(SELF_DIR)nginx-repo.key
BUILD_AGENT = local
BASE_IMAGE ?= nginx:1.29.1-alpine-otel

PROD_TELEMETRY_ENDPOINT = oss.edge.df.f5.com:443
# the telemetry related variables below are also configured in goreleaser.yml
Expand Down Expand Up @@ -43,6 +44,8 @@ HELM_SCHEMA_VERSION = 0.18.1
PREFIX ?= nginx-gateway-fabric## The name of the NGF image. For example, nginx-gateway-fabric
NGINX_PREFIX ?= $(PREFIX)/nginx## The name of the nginx image. For example: nginx-gateway-fabric/nginx
NGINX_PLUS_PREFIX ?= $(PREFIX)/nginx-plus## The name of the nginx plus image. For example: nginx-gateway-fabric/nginx-plus
BUILD_OS ?= alpine## The OS of the nginx image. Possible values: alpine and ubi
IMAGE_PULL_POLICY ?= Never## The image pull policy for the NGF and nginx images. Possible values: Always, Never, IfNotPresent
TAG ?= $(VERSION:v%=%)## The tag of the image. For example, 1.1.0
TARGET ?= local## The target of the build. Possible values: local and container
OUT_DIR ?= build/out## The folder where the binary will be stored
Expand All @@ -52,7 +55,7 @@ PLUS_ENABLED ?= false
PLUS_LICENSE_FILE ?= $(SELF_DIR)license.jwt
PLUS_USAGE_ENDPOINT ?=## The N+ usage endpoint. For development, please set to the N1 staging endpoint.

override NGINX_DOCKER_BUILD_OPTIONS += --build-arg NJS_DIR=$(NJS_DIR) --build-arg NGINX_CONF_DIR=$(NGINX_CONF_DIR) --build-arg BUILD_AGENT=$(BUILD_AGENT)
override NGINX_DOCKER_BUILD_OPTIONS += --build-arg NJS_DIR=$(NJS_DIR) --build-arg NGINX_CONF_DIR=$(NGINX_CONF_DIR) --build-arg BUILD_AGENT=$(BUILD_AGENT) --build-arg BASE_IMAGE=$(BASE_IMAGE)

.DEFAULT_GOAL := help

Expand Down Expand Up @@ -83,21 +86,21 @@ build-prod-ngf-image: build-ngf-image ## Build the NGF docker image for producti

.PHONY: build-ngf-image
build-ngf-image: check-for-docker build ## Build the NGF docker image
docker build --platform linux/$(GOARCH) --build-arg BUILD_AGENT=$(BUILD_AGENT) --target $(strip $(TARGET)) -f $(SELF_DIR)build/Dockerfile -t $(strip $(PREFIX)):$(strip $(TAG)) $(strip $(SELF_DIR))
docker build --platform linux/$(GOARCH) --build-arg BUILD_AGENT=$(BUILD_AGENT) --target $(strip $(TARGET)) -f $(SELF_DIR)build/$(BUILD_OS)/Dockerfile -t $(strip $(PREFIX)):$(strip $(TAG)) $(strip $(SELF_DIR))

.PHONY: build-prod-nginx-image
build-prod-nginx-image: build-nginx-image ## Build the custom nginx image for production

.PHONY: build-nginx-image
build-nginx-image: check-for-docker ## Build the custom nginx image
docker build --platform linux/$(GOARCH) $(strip $(NGINX_DOCKER_BUILD_OPTIONS)) -f $(SELF_DIR)build/Dockerfile.nginx -t $(strip $(NGINX_PREFIX)):$(strip $(TAG)) $(strip $(SELF_DIR))
docker build --platform linux/$(GOARCH) $(strip $(NGINX_DOCKER_BUILD_OPTIONS)) -f $(SELF_DIR)build/$(BUILD_OS)/Dockerfile.nginx -t $(strip $(NGINX_PREFIX)):$(strip $(TAG)) $(strip $(SELF_DIR))

.PHONY: build-prod-nginx-plus-image
build-prod-nginx-plus-image: build-nginx-plus-image ## Build the custom nginx plus image for production

.PHONY: build-nginx-plus-image
build-nginx-plus-image: check-for-docker ## Build the custom nginx plus image
docker build --platform linux/$(GOARCH) $(strip $(NGINX_DOCKER_BUILD_OPTIONS)) $(strip $(NGINX_DOCKER_BUILD_PLUS_ARGS)) -f $(SELF_DIR)build/Dockerfile.nginxplus -t $(strip $(NGINX_PLUS_PREFIX)):$(strip $(TAG)) $(strip $(SELF_DIR))
docker build --platform linux/$(GOARCH) $(strip $(NGINX_DOCKER_BUILD_OPTIONS)) $(strip $(NGINX_DOCKER_BUILD_PLUS_ARGS)) -f $(SELF_DIR)build/$(BUILD_OS)/Dockerfile.nginxplus -t $(strip $(NGINX_PLUS_PREFIX)):$(strip $(TAG)) $(strip $(SELF_DIR))

.PHONY: check-for-docker
check-for-docker: ## Check if Docker is installed
Expand Down Expand Up @@ -226,7 +229,7 @@ install-ngf-local-build-with-plus: check-for-plus-usage-endpoint build-images-wi

.PHONY: helm-install-local
helm-install-local: install-gateway-crds ## Helm install NGF on configured kind cluster with local images. To build, load, and install with helm run make install-ngf-local-build.
helm install nginx-gateway $(CHART_DIR) --set nginx.image.repository=$(NGINX_PREFIX) --create-namespace --wait --set nginxGateway.image.pullPolicy=Never --set nginx.service.type=NodePort --set nginxGateway.image.repository=$(PREFIX) --set nginxGateway.image.tag=$(TAG) --set nginx.image.tag=$(TAG) --set nginx.image.pullPolicy=Never --set nginxGateway.gwAPIExperimentalFeatures.enable=$(ENABLE_EXPERIMENTAL) -n nginx-gateway $(HELM_PARAMETERS)
helm install nginx-gateway $(CHART_DIR) --set nginx.image.repository=$(NGINX_PREFIX) --create-namespace --wait --set nginxGateway.image.pullPolicy=$(IMAGE_PULL_POLICY) --set nginx.service.type=NodePort --set nginxGateway.image.repository=$(PREFIX) --set nginxGateway.image.tag=$(TAG) --set nginx.image.tag=$(TAG) --set nginx.image.pullPolicy=$(IMAGE_PULL_POLICY) --set nginxGateway.gwAPIExperimentalFeatures.enable=$(ENABLE_EXPERIMENTAL) -n nginx-gateway $(HELM_PARAMETERS) || helm uninstall nginx-gateway -n nginx-gateway

.PHONY: helm-install-local-with-plus
helm-install-local-with-plus: check-for-plus-usage-endpoint install-gateway-crds ## Helm install NGF with NGINX Plus on configured kind cluster with local images. To build, load, and install with helm run make install-ngf-local-build-with-plus.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions build/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ fi
nginx_pid=$!

SECONDS=0

while ! ps -ef | grep "nginx: master process" | grep -v grep; do
if ((SECONDS > 5)); then
while [[ ! -f /var/run/nginx.pid ]] && [[ ! -f /var/run/nginx/nginx.pid ]]; do
if ((SECONDS > 30)); then
echo "couldn't find nginx master process"
exit 1
fi
sleep 1
done

# start nginx-agent, pass args
Expand Down
30 changes: 30 additions & 0 deletions build/ubi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# syntax=docker/dockerfile:1.18
FROM golang:1.25 AS builder

WORKDIR /go/src/github.com/nginx/nginx-gateway-fabric

COPY go.mod go.sum /go/src/github.com/nginx/nginx-gateway-fabric/
RUN go mod download

COPY . /go/src/github.com/nginx/nginx-gateway-fabric
RUN make build

FROM golang:1.25 AS ca-certs-provider

FROM redhat/ubi9-minimal:9.6 AS ngf-ubi-minimal
# CA certs are needed for telemetry report so that NGF can verify the server's certificate.
COPY --from=ca-certs-provider --link /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
USER 101:1001
ARG BUILD_AGENT
ENV BUILD_AGENT=${BUILD_AGENT}
ENTRYPOINT [ "/usr/bin/gateway" ]

FROM ngf-ubi-minimal AS container
COPY --from=builder /go/src/github.com/nginxinc/nginx-gateway-fabric/build/out/gateway /usr/bin/gateway

FROM ngf-ubi-minimal AS local
COPY ./build/out/gateway /usr/bin/gateway

FROM ngf-ubi-minimal AS goreleaser
ARG TARGETARCH
COPY dist/gateway_linux_$TARGETARCH*/gateway /usr/bin/gateway
74 changes: 74 additions & 0 deletions build/ubi/Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# syntax=docker/dockerfile:1.18
FROM scratch AS nginx-files

# Repository and key files for UBI-based builds
ADD --link --chown=101:1001 https://nginx.org/keys/nginx_signing.key nginx_signing.key
ADD --link --chown=101:1001 build/ubi/repos/nginx.repo nginx.repo
ADD --link --chown=101:1001 build/ubi/repos/agent.repo agent.repo

FROM redhat/ubi9-minimal:9.6 AS ubi-minimal

FROM ghcr.io/nginx/dependencies/nginx-ubi:ubi9@sha256:01a32246761b9bbe47a6a29bcd8ca6e9b6e331b3bdfa372d8987b622276f7025 AS ubi9-packages

FROM ubi-minimal AS ubi-nginx

# renovate: datasource=github-tags depName=nginx/agent
ARG NGINX_AGENT_VERSION=v3.3.1
ARG NJS_DIR
ARG NGINX_CONF_DIR
ARG BUILD_AGENT

LABEL name="NGINX Gateway Fabric NGINX" \
maintainer="[email protected]" \
vendor="NGINX Inc" \
summary="NGINX for NGINX Gateway Fabric" \
description="NGINX data plane for NGINX Gateway Fabric Gateway API implementation" \
org.nginx.ngf.image.build.agent="${BUILD_AGENT}" \
io.k8s.description="NGINX data plane for NGINX Gateway Fabric Gateway API implementation" \
io.openshift.tags="nginx,gateway,kubernetes,openshift"

COPY --link --chown=101:1001 LICENSE /licenses/

# Install NGINX with OTEL support using the same approach as NGINX IC
RUN --mount=type=bind,from=nginx-files,src=nginx_signing.key,target=/tmp/nginx_signing.key \
--mount=type=bind,from=nginx-files,src=nginx.repo,target=/etc/yum.repos.d/nginx.repo \
--mount=type=bind,from=nginx-files,src=agent.repo,target=/etc/yum.repos.d/agent.repo \
--mount=type=bind,from=ubi9-packages,src=/,target=/ubi-bin/ \
# Import NGINX signing key
rpm --import /tmp/nginx_signing.key \
# Install c-ares from the dependencies image (contains required libs)
&& rpm -Uvh /ubi-bin/c-ares-*.rpm \
# Create nginx user with consistent UID/GID
&& groupadd -g 1001 nginx \
&& useradd -r -u 101 -g nginx -s /sbin/nologin -d /var/cache/nginx nginx \
# Install NGINX and modules including OTEL
&& microdnf --nodocs install -y nginx nginx-module-njs nginx-module-otel \
# Install nginx-agent
&& microdnf --nodocs install -y nginx-agent-${NGINX_AGENT_VERSION#v}* \
# Clean up (only remove what we can)
&& microdnf clean all \
&& rm -rf /var/cache/yum

# Configure directories and logging
RUN mkdir -p /usr/lib/nginx/modules /var/run/nginx /usr/lib64/nginx/modules \
# Forward request and error logs to docker log collector
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
&& cp -r /usr/lib64/nginx/modules/ngx_* /usr/lib/nginx/modules/ \
# Set proper permissions for nginx user
&& chown -R 101:1001 /etc/nginx /var/cache/nginx /var/log/nginx /var/run/nginx

# Copy configuration files and scripts
COPY build/entrypoint.sh /agent/entrypoint.sh
COPY ${NJS_DIR}/httpmatches.js /usr/lib/nginx/modules/njs/httpmatches.js
COPY ${NGINX_CONF_DIR}/nginx.conf /etc/nginx/nginx.conf
COPY ${NGINX_CONF_DIR}/grpc-error-locations.conf /etc/nginx/grpc-error-locations.conf
COPY ${NGINX_CONF_DIR}/grpc-error-pages.conf /etc/nginx/grpc-error-pages.conf

# Set executable permissions
RUN chmod +x /agent/entrypoint.sh && chown 101:1001 /agent/entrypoint.sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? It should already have these permissions. This also isn't needed in the alpine Dockerfiles.


# Switch to non-root user
USER 101:1001

ENTRYPOINT ["/agent/entrypoint.sh"]
79 changes: 79 additions & 0 deletions build/ubi/Dockerfile.nginxplus
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# syntax=docker/dockerfile:1.18
FROM scratch AS nginx-files

# NGINX Plus repo and key files (must be provided at build time)
ADD --link --chown=101:1001 https://cs.nginx.com/static/files/plus-9.repo nginx-plus.repo
ADD --link --chown=101:1001 https://nginx.org/keys/nginx_signing.key nginx_signing.key
ADD --link --chown=101:1001 build/ubi/repos/agent.repo agent.repo
ADD --link --chown=101:1001 nginx-repo.crt nginx-repo.crt
ADD --link --chown=101:1001 nginx-repo.key nginx-repo.key

FROM redhat/ubi9-minimal:9.6 AS ubi-minimal

FROM ghcr.io/nginx/dependencies/nginx-ubi:ubi9@sha256:01a32246761b9bbe47a6a29bcd8ca6e9b6e331b3bdfa372d8987b622276f7025 AS ubi9-packages

FROM ubi-minimal AS ubi-nginxplus

# renovate: datasource=github-tags depName=nginx/agent
ARG NGINX_AGENT_VERSION=v3.3.1
ARG NJS_DIR
ARG NGINX_CONF_DIR
ARG BUILD_AGENT

LABEL name="NGINX Gateway Fabric NGINX Plus" \
maintainer="[email protected]" \
vendor="NGINX Inc" \
summary="NGINX Plus for NGINX Gateway Fabric" \
description="NGINX Plus data plane for NGINX Gateway Fabric Gateway API implementation" \
org.nginx.ngf.image.build.agent="${BUILD_AGENT}" \
io.k8s.description="NGINX Plus data plane for NGINX Gateway Fabric Gateway API implementation" \
io.openshift.tags="nginx-plus,gateway,kubernetes,openshift"

COPY --link --chown=101:1001 LICENSE /licenses/

# Install NGINX Plus and modules
RUN --mount=type=bind,from=nginx-files,src=nginx-plus.repo,target=/etc/yum.repos.d/nginx-plus.repo \
--mount=type=bind,from=nginx-files,src=agent.repo,target=/etc/yum.repos.d/agent.repo \
--mount=type=bind,from=nginx-files,src=nginx_signing.key,target=/tmp/nginx_signing.key \
--mount=type=bind,from=ubi9-packages,src=/,target=/ubi-bin/ \
--mount=type=secret,id=nginx-repo.crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode=0644 \
--mount=type=secret,id=nginx-repo.key,dst=/etc/ssl/nginx/nginx-repo.key,mode=0644 \
# Install shadow-utils for useradd and subscription-manager for repo access
microdnf --nodocs install -y shadow-utils subscription-manager \
&& rpm --import /tmp/nginx_signing.key \
# Install c-ares from the dependencies image (contains required libs)
&& rpm -Uvh /ubi-bin/c-ares-*.rpm \
# Create nginx user with consistent UID/GID
&& groupadd -g 1001 nginx \
&& useradd -r -u 101 -g nginx -s /sbin/nologin -d /var/cache/nginx nginx \
# Install NGINX Plus and modules (njs, otel)
&& microdnf --nodocs install -y nginx-plus nginx-plus-module-njs nginx-plus-module-otel \
# Install nginx-agent
&& microdnf --nodocs install -y nginx-agent-${NGINX_AGENT_VERSION#v}* \
# Clean up
&& microdnf clean all \
&& rm -rf /var/cache/yum

# Configure directories and logging
RUN mkdir -p /usr/lib/nginx/modules /var/run/nginx /usr/lib64/nginx/modules \
# Forward request and error logs to docker log collector
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
&& cp -r /usr/lib64/nginx/modules/ngx_* /usr/lib/nginx/modules/ \
# Set proper permissions for nginx user
&& chown -R 101:1001 /etc/nginx /var/cache/nginx /var/log/nginx /var/run/nginx

# Copy configuration files and scripts
COPY build/entrypoint.sh /agent/entrypoint.sh
COPY ${NJS_DIR}/httpmatches.js /usr/lib/nginx/modules/njs/httpmatches.js
COPY ${NGINX_CONF_DIR}/nginx.conf /etc/nginx/nginx.conf
COPY ${NGINX_CONF_DIR}/grpc-error-locations.conf /etc/nginx/grpc-error-locations.conf
COPY ${NGINX_CONF_DIR}/grpc-error-pages.conf /etc/nginx/grpc-error-pages.conf

# Set executable permissions
RUN chmod +x /agent/entrypoint.sh && chown 101:1001 /agent/entrypoint.sh

# Switch to non-root user
USER 101:1001

ENTRYPOINT ["/agent/entrypoint.sh"]
6 changes: 6 additions & 0 deletions build/ubi/repos/agent.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[agent]
name=agent repo
baseurl=https://packages.nginx.org/nginx-agent/centos/9/$basearch/
gpgcheck=1
enabled=1
module_hotfixes=true
6 changes: 6 additions & 0 deletions build/ubi/repos/nginx.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[nginx]
name=nginx repo
baseurl=https://packages.nginx.org/nginx/mainline/centos/9/$basearch/
gpgcheck=1
enabled=1
module_hotfixes=true
14 changes: 14 additions & 0 deletions operators/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
7 changes: 7 additions & 0 deletions operators/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Build the manager binary
FROM quay.io/operator-framework/helm-operator:v1.41.1

ENV HOME=/opt/helm
COPY watches.yaml ${HOME}/watches.yaml
COPY helm-charts ${HOME}/helm-charts
WORKDIR ${HOME}
Loading
Loading