diff --git a/build/Dockerfile.nginxplus b/build/Dockerfile.nginxplus index 60ac79fcdf..7ce2cfafbc 100644 --- a/build/Dockerfile.nginxplus +++ b/build/Dockerfile.nginxplus @@ -4,11 +4,28 @@ FROM scratch AS nginx-files # the following links can be replaced with local files if needed, i.e. ADD --chown=101:1001 ADD --link --chown=101:1001 https://cs.nginx.com/static/keys/nginx_signing.rsa.pub nginx_signing.rsa.pub +# Build nginx-agent from source +FROM golang:1.24-alpine AS agent-builder + +RUN apk add --no-cache git make curl jq + +# Clone the specific branch with full history to avoid git describe issues +RUN git clone --branch retry-api-ping https://github.com/nginx/agent.git /src/agent + +WORKDIR /src/agent + +# Set git config for the build process +RUN git config --global user.email "build@nginx.com" && \ + git config --global user.name "Docker Build" + +# Build the agent using the correct target +RUN make build + FROM alpine:3.22 ARG NGINX_PLUS_VERSION=R35 -# renovate: datasource=github-tags depName=nginx/agent -ARG NGINX_AGENT_VERSION=v3.2.1 +# Using custom agent build from retry-api-ping branch +ARG NGINX_AGENT_BRANCH=retry-api-ping ARG NJS_DIR ARG NGINX_CONF_DIR ARG BUILD_AGENT @@ -19,14 +36,19 @@ RUN --mount=type=secret,id=nginx-repo.crt,dst=/etc/apk/cert.pem,mode=0644 \ addgroup -g 1001 -S nginx \ && adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx \ && printf "%s\n" "https://pkgs.nginx.com/plus/${NGINX_PLUS_VERSION}/alpine/v$(grep -E -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" >> /etc/apk/repositories \ - && printf "%s\n" "https://pkgs.nginx.com/nginx-agent/alpine/v$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" >> /etc/apk/repositories \ - && apk add --no-cache nginx-plus nginx-plus-module-njs nginx-plus-module-otel nginx-agent=${NGINX_AGENT_VERSION#v} + && apk add --no-cache nginx-plus nginx-plus-module-njs nginx-plus-module-otel RUN apk add --no-cache bash \ && mkdir -p /usr/lib/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 + && ln -sf /dev/stderr /var/log/nginx/error.log \ + # Create directories for nginx-agent + && mkdir -p /usr/bin /etc/nginx-agent /var/log/nginx-agent /var/lib/nginx-agent + +# Copy the custom-built nginx-agent binary +COPY --from=agent-builder /src/agent/build/nginx-agent /usr/bin/nginx-agent +RUN chmod +x /usr/bin/nginx-agent COPY build/entrypoint.sh /agent/entrypoint.sh COPY ${NJS_DIR}/httpmatches.js /usr/lib/nginx/modules/njs/httpmatches.js @@ -34,10 +56,12 @@ COPY ${NGINX_CONF_DIR}/nginx-plus.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 -RUN chown -R 101:1001 /etc/nginx /var/cache/nginx /var/lib/nginx +RUN chown -R 101:1001 /etc/nginx /var/cache/nginx /var/lib/nginx /etc/nginx-agent /var/log/nginx-agent /var/lib/nginx-agent USER 101:1001 LABEL org.nginx.ngf.image.build.agent="${BUILD_AGENT}" +LABEL org.nginx.ngf.image.agent.branch="${NGINX_AGENT_BRANCH}" +LABEL org.nginx.ngf.image.agent.source="custom-build-retry-api-ping" ENTRYPOINT ["/agent/entrypoint.sh"]