diff --git a/Makefile b/Makefile index 8945cd7143..2d98830d55 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,8 @@ OS_VERSION ?= 24.04 BASE_IMAGE = "${CONTAINER_REGISTRY}/${OS_RELEASE}:${OS_VERSION}" IMAGE_TAG = "agent_${OS_RELEASE}_${OS_VERSION}" IMAGE_PATH ?= "/nginx/agent" +IMAGE_BUILD_TARGET ?= install-agent-local +NGINX_AGENT_VERSION ?= "" VERSION_WITH_V := v${VERSION} LDFLAGS = "-w -X main.version=${VERSION_WITH_V} -X main.commit=${COMMIT} -X main.date=${DATE}" @@ -287,21 +289,24 @@ image: ## Build agent container image for NGINX Plus, need nginx-repo.crt and ng --no-cache -f ./scripts/docker/nginx-plus/${OS_RELEASE}/Dockerfile \ --secret id=nginx-crt,src=${CERTS_DIR}/nginx-repo.crt \ --secret id=nginx-key,src=${CERTS_DIR}/nginx-repo.key \ + --build-arg CONTAINER_REGISTRY=${CONTAINER_REGISTRY} \ --build-arg BASE_IMAGE=${BASE_IMAGE} \ --build-arg PACKAGES_REPO=${PLUS_PACKAGES_REPO} \ --build-arg OS_RELEASE=${OS_RELEASE} \ --build-arg OS_VERSION=${OS_VERSION} \ + --build-arg NGINX_AGENT_VERSION=${NGINX_AGENT_VERSION} oss-image: ## Build agent container image for NGINX OSS @echo Building image with $(CONTAINER_CLITOOL); \ $(CONTAINER_BUILDENV) $(CONTAINER_CLITOOL) build -t ${IMAGE_TAG} . \ --no-cache -f ./scripts/docker/nginx-oss/${CONTAINER_OS_TYPE}/Dockerfile \ - --target install-agent-local \ + --target ${IMAGE_BUILD_TARGET} \ --build-arg PACKAGE_NAME=${PACKAGE_NAME} \ --build-arg PACKAGES_REPO=${OSS_PACKAGES_REPO} \ --build-arg BASE_IMAGE=${BASE_IMAGE} \ --build-arg OS_RELEASE=${OS_RELEASE} \ --build-arg OS_VERSION=${OS_VERSION} \ + --build-arg NGINX_AGENT_VERSION=${NGINX_AGENT_VERSION} \ --build-arg ENTRY_POINT=./scripts/docker/entrypoint.sh run-container: ## Run container from specified IMAGE_TAG diff --git a/scripts/docker/nginx-oss/apk/Dockerfile b/scripts/docker/nginx-oss/apk/Dockerfile index a9a904aacf..534fe4ccda 100644 --- a/scripts/docker/nginx-oss/apk/Dockerfile +++ b/scripts/docker/nginx-oss/apk/Dockerfile @@ -43,5 +43,6 @@ RUN apk add --allow-untrusted /agent/build/${PACKAGE_NAME}.apk FROM install-nginx as install-agent-repo -RUN apk add nginx-agent@nginx-agent +ARG NGINX_AGENT_VERSION +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then apk add nginx-agent; else apk add "nginx-agent=${NGINX_AGENT_VERSION}"; fi diff --git a/scripts/docker/nginx-oss/deb/Dockerfile b/scripts/docker/nginx-oss/deb/Dockerfile index a1ae0bdc90..dbb5afe017 100644 --- a/scripts/docker/nginx-oss/deb/Dockerfile +++ b/scripts/docker/nginx-oss/deb/Dockerfile @@ -43,4 +43,7 @@ RUN apt install -y /agent/build/$PACKAGE_NAME.deb FROM install-nginx as install-agent-repo -RUN apt-get update && apt-get install -y nginx-agent \ No newline at end of file +ARG NGINX_AGENT_VERSION + +RUN apt-get update +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then apt-get install -y nginx-agent; else apt-get install -y nginx-agent=${NGINX_AGENT_VERSION}; fi diff --git a/scripts/docker/nginx-oss/rpm/Dockerfile b/scripts/docker/nginx-oss/rpm/Dockerfile index d36bdc376e..d14dff242b 100644 --- a/scripts/docker/nginx-oss/rpm/Dockerfile +++ b/scripts/docker/nginx-oss/rpm/Dockerfile @@ -92,6 +92,9 @@ RUN yum localinstall -y /agent/build/${PACKAGE_NAME}.rpm FROM install-nginx as install-agent-repo -RUN yum install -y nginx-agent \ - && yum clean all \ +ARG NGINX_AGENT_VERSION + +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then yum install -y nginx-agent; else yum install -y nginx-agent-${NGINX_AGENT_VERSION}; fi + +RUN yum clean all \ && rm -rf /var/cache/yum /etc/yum.repos.d/* /etc/ssl/nginx diff --git a/scripts/docker/nginx-plus/almalinux/Dockerfile b/scripts/docker/nginx-plus/almalinux/Dockerfile index a4a179e047..704a079e84 100644 --- a/scripts/docker/nginx-plus/almalinux/Dockerfile +++ b/scripts/docker/nginx-plus/almalinux/Dockerfile @@ -6,6 +6,7 @@ ARG BASE_IMAGE ARG PACKAGES_REPO ARG OS_RELEASE ARG OS_VERSION +ARG NGINX_AGENT_VERSION WORKDIR /agent COPY ./scripts/docker/entrypoint.sh /agent/entrypoint.sh @@ -41,11 +42,14 @@ enabled=1 \n\ sslverify=true \n\ gpgkey=https://nginx.org/keys/nginx_signing.key" > /etc/yum.repos.d/nginx-agent.repo \ && nginxPackages=" \ - nginx-agent \ nginx-plus \ " \ - && yum install -y $nginxPackages \ - && yum clean all \ + && yum install -y $nginxPackages + + +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then yum install -y nginx-agent; else yum install -y nginx-agent-${NGINX_AGENT_VERSION}; fi + +RUN yum clean all \ && rm -rf /var/cache/yum /etc/yum.repos.d/* /etc/ssl/nginx FROM install as runtime diff --git a/scripts/docker/nginx-plus/alpine/Dockerfile b/scripts/docker/nginx-plus/alpine/Dockerfile index 09a229de90..391efafe58 100644 --- a/scripts/docker/nginx-plus/alpine/Dockerfile +++ b/scripts/docker/nginx-plus/alpine/Dockerfile @@ -3,6 +3,7 @@ FROM ${BASE_IMAGE} as install LABEL maintainer="NGINX Docker Maintainers " ARG PACKAGES_REPO +ARG NGINX_AGENT_VERSION WORKDIR /agent COPY ./scripts/docker/entrypoint.sh /agent/entrypoint.sh @@ -58,11 +59,12 @@ RUN --mount=type=secret,id=nginx-crt,dst=/etc/apk/cert.pem \ && printf "https://$PACKAGES_REPO/nginx-agent/alpine/v`egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release`/main/\n" | tee -a /etc/apk/repositories \ && nginxPackages=" \ nginx-plus \ - nginx-agent \ " \ && apk update \ && apk add $nginxPackages +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then apk add nginx-agent; else apk add "nginx-agent=${NGINX_AGENT_VERSION}"; fi + # run the nginx and agent FROM install as runtime diff --git a/scripts/docker/nginx-plus/amazonlinux/Dockerfile b/scripts/docker/nginx-plus/amazonlinux/Dockerfile index 60eb303b22..310cd6d3ee 100644 --- a/scripts/docker/nginx-plus/amazonlinux/Dockerfile +++ b/scripts/docker/nginx-plus/amazonlinux/Dockerfile @@ -6,6 +6,7 @@ ARG BASE_IMAGE ARG PACKAGES_REPO # note if OS_VERSION is 1, there will be an issues in the yum.repos.d folder ARG OS_VERSION +ARG NGINX_AGENT_VERSION WORKDIR /agent COPY ./scripts/docker/entrypoint.sh /agent/entrypoint.sh @@ -22,7 +23,6 @@ RUN --mount=type=secret,id=nginx-crt,dst=/nginx-repo.crt \ && adduser -g nginx --system --no-create-home --home /nonexistent --shell /bin/false --uid 101 nginx \ && nginxPackages=" \ nginx-plus \ - nginx-agent \ " \ && printf "[nginx-plus] \n\ name=nginx-plus repo \n\ @@ -42,8 +42,11 @@ gpgcheck=1 \n\ enabled=1 \n\ sslverify=true \n\ gpgkey=https://nginx.org/keys/nginx_signing.key" >> /etc/yum.repos.d/nginx-agent.repo \ - && yum install -y $nginxPackages \ - && yum clean all \ + && yum install -y $nginxPackages + +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then yum install -y nginx-agent; else yum install -y nginx-agent-${NGINX_AGENT_VERSION}; fi + +RUN yum clean all \ && rm -rf /var/cache/yum /etc/yum.repos.d/* /etc/ssl/nginx FROM install as runtime diff --git a/scripts/docker/nginx-plus/centos/Dockerfile b/scripts/docker/nginx-plus/centos/Dockerfile index 8eed9f70e4..f098839fa9 100644 --- a/scripts/docker/nginx-plus/centos/Dockerfile +++ b/scripts/docker/nginx-plus/centos/Dockerfile @@ -6,6 +6,7 @@ ARG BASE_IMAGE ARG PACKAGES_REPO ARG OS_RELEASE ARG OS_VERSION +ARG NGINX_AGENT_VERSION WORKDIR /agent COPY ./scripts/docker/entrypoint.sh /agent/entrypoint.sh @@ -41,11 +42,13 @@ enabled=1 \n\ sslverify=true \n\ gpgkey=https://nginx.org/keys/nginx_signing.key">> /etc/yum.repos.d/nginx-agent.repo \ && nginxPackages=" \ - nginx-agent \ nginx-plus \ " \ - && yum install -y $nginxPackages \ - && yum clean all \ + && yum install -y $nginxPackages + +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then yum install -y nginx-agent; else yum install -y nginx-agent-${NGINX_AGENT_VERSION}; fi + +RUN yum clean all \ && rm -rf /var/cache/yum /etc/yum.repos.d/* /etc/ssl/nginx FROM install as runtime diff --git a/scripts/docker/nginx-plus/debian/Dockerfile b/scripts/docker/nginx-plus/debian/Dockerfile index 08553eb069..5e745e7200 100644 --- a/scripts/docker/nginx-plus/debian/Dockerfile +++ b/scripts/docker/nginx-plus/debian/Dockerfile @@ -3,6 +3,7 @@ FROM ${BASE_IMAGE} as install LABEL maintainer="NGINX Docker Maintainers " ARG PACKAGES_REPO +ARG NGINX_AGENT_VERSION WORKDIR /agent COPY ./scripts/docker/entrypoint.sh /agent/entrypoint.sh @@ -36,7 +37,6 @@ RUN --mount=type=secret,id=nginx-crt,dst=/nginx-repo.crt \ # Use versioned packages over defaults to specify a release && nginxPackages=" \ nginx-plus \ - nginx-agent \ " \ && echo "Acquire::https::$PACKAGES_REPO::Verify-Peer \"true\";" > /etc/apt/apt.conf.d/90nginx \ && echo "Acquire::https::$PACKAGES_REPO::Verify-Host \"true\";" >> /etc/apt/apt.conf.d/90nginx \ @@ -51,10 +51,13 @@ RUN --mount=type=secret,id=nginx-crt,dst=/nginx-repo.crt \ && apt-get install --no-install-recommends --no-install-suggests -y \ $nginxPackages \ curl \ - gettext-base \ - && apt-get autoremove --purge -y \ - gnupg \ - lsb-release \ + gettext-base + +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then apt-get install -y nginx-agent; else apt-get install -y nginx-agent=${NGINX_AGENT_VERSION}; fi + +RUN apt-get autoremove --purge -y \ + gnupg \ + lsb-release \ && rm -rf /root/.gnupg \ && apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx-plus.list \ && rm -rf /etc/apt/apt.conf.d/90nginx /etc/ssl/nginx diff --git a/scripts/docker/nginx-plus/oraclelinux/Dockerfile b/scripts/docker/nginx-plus/oraclelinux/Dockerfile index 430e81e390..1d454e70d0 100644 --- a/scripts/docker/nginx-plus/oraclelinux/Dockerfile +++ b/scripts/docker/nginx-plus/oraclelinux/Dockerfile @@ -6,6 +6,7 @@ LABEL maintainer="NGINX Docker Maintainers " ARG BASE_IMAGE ARG PACKAGES_REPO ARG OS_VERSION +ARG NGINX_AGENT_VERSION WORKDIR /agent COPY ./scripts/docker/entrypoint.sh /agent/entrypoint.sh @@ -24,7 +25,6 @@ RUN --mount=type=secret,id=nginx-crt,dst=/nginx-repo.crt \ && usermod -L nginx \ && nginxPackages=" \ nginx-plus \ - nginx-agent \ " \ && printf "[nginx-plus] \n\ name=nginx-plus repo \n\ @@ -44,8 +44,11 @@ gpgcheck=1 \n\ enabled=1 \n\ sslverify=true \n\ gpgkey=https://nginx.org/keys/nginx_signing.key" >> /etc/yum.repos.d/nginx-agent.repo \ - && yum install -y $nginxPackages \ - && yum clean all \ + && yum install -y $nginxPackages + +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then yum install -y nginx-agent; else yum install -y nginx-agent-${NGINX_AGENT_VERSION}; fi + +RUN yum clean all \ && rm -rf /var/cache/yum /etc/yum.repos.d/* /etc/ssl/nginx FROM install as runtime diff --git a/scripts/docker/nginx-plus/redhatenterprise/Dockerfile b/scripts/docker/nginx-plus/redhatenterprise/Dockerfile index 5d5b0d480a..589c681e52 100644 --- a/scripts/docker/nginx-plus/redhatenterprise/Dockerfile +++ b/scripts/docker/nginx-plus/redhatenterprise/Dockerfile @@ -7,6 +7,7 @@ LABEL maintainer="NGINX Docker Maintainers " ARG PACKAGES_REPO ARG OS_VERSION +ARG NGINX_AGENT_VERSION WORKDIR /agent COPY ./scripts/docker/entrypoint.sh /agent/entrypoint.sh @@ -24,7 +25,6 @@ RUN --mount=type=secret,id=nginx-crt,dst=/nginx-repo.crt \ && usermod -s /sbin/nologin nginx \ && usermod -L nginx \ && nginxPackages=" \ - nginx-agent \ nginx-plus \ " \ && printf "[nginx-plus] \n\ @@ -45,8 +45,11 @@ gpgcheck=1 \n\ enabled=1 \n\ sslverify=true \n\ gpgkey=https://nginx.org/keys/nginx_signing.key" >> /etc/yum.repos.d/nginx-agent.repo \ - && yum install -y $nginxPackages \ - && yum clean all \ + && yum install -y $nginxPackages + +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then yum install -y nginx-agent; else yum install -y nginx-agent-${NGINX_AGENT_VERSION}; fi + +RUN yum clean all \ && rm -rf /var/cache/yum /etc/yum.repos.d/* /etc/ssl/nginx FROM install as runtime diff --git a/scripts/docker/nginx-plus/rockylinux/Dockerfile b/scripts/docker/nginx-plus/rockylinux/Dockerfile index 2282097c20..bcf6649459 100644 --- a/scripts/docker/nginx-plus/rockylinux/Dockerfile +++ b/scripts/docker/nginx-plus/rockylinux/Dockerfile @@ -6,6 +6,7 @@ ARG BASE_IMAGE ARG PACKAGES_REPO ARG OS_RELEASE ARG OS_VERSION +ARG NGINX_AGENT_VERSION WORKDIR /agent COPY ./scripts/docker/entrypoint.sh /agent/entrypoint.sh @@ -41,11 +42,13 @@ enabled=1 \n\ sslverify=true \n\ gpgkey=https://nginx.org/keys/nginx_signing.key">> /etc/yum.repos.d/nginx-agent.repo \ && nginxPackages=" \ - nginx-agent \ nginx-plus \ " \ - && yum install -y $nginxPackages \ - && yum clean all \ + && yum install -y $nginxPackages + +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then yum install -y nginx-agent; else yum install -y nginx-agent-${NGINX_AGENT_VERSION}; fi + +RUN yum clean all \ && rm -rf /var/cache/yum /etc/yum.repos.d/* /etc/ssl/nginx FROM install as runtime diff --git a/scripts/docker/nginx-plus/suse/Dockerfile b/scripts/docker/nginx-plus/suse/Dockerfile index 2c6a3961c7..0e069cdc7d 100644 --- a/scripts/docker/nginx-plus/suse/Dockerfile +++ b/scripts/docker/nginx-plus/suse/Dockerfile @@ -7,6 +7,7 @@ LABEL maintainer="NGINX Docker Maintainers " ARG OS_VERSION ARG PACKAGES_REPO +ARG NGINX_AGENT_VERSION WORKDIR /agent COPY ./scripts/docker/entrypoint.sh /agent/entrypoint.sh @@ -22,7 +23,6 @@ RUN --mount=type=secret,id=nginx-crt,dst=/nginx-repo.crt \ && zypper install ca-certificates \ && nginxPackages=" \ nginx-plus \ - nginx-agent \ " \ && if [ "$OS_VERSION" = "sles12sp5" ]; then \ zypper addrepo -G -c "https://$PACKAGES_REPO/plus/sles/12?ssl_clientcert=/etc/ssl/nginx/nginx-repo-bundle.crt&ssl_verify=peer" nginx-plus \ @@ -32,8 +32,10 @@ RUN --mount=type=secret,id=nginx-crt,dst=/nginx-repo.crt \ && zypper addrepo -G -c "https://$PACKAGES_REPO/nginx-agent/sles/15?ssl_clientcert=/etc/ssl/nginx/nginx-repo-bundle.crt&ssl_verify=peer" nginx-agent; \ fi \ && zypper refresh \ - && zypper install -y $nginxPackages \ - && rm -rf /etc/ssl/nginx/nginx-repo-bundle.crt /etc/ssl/nginx + && zypper install -y $nginxPackages + +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then zypper install -y nginx-agent; else zypper install -y nginx-agent=${NGINX_AGENT_VERSION}; fi +RUN rm -rf /etc/ssl/nginx/nginx-repo-bundle.crt /etc/ssl/nginx FROM install as runtime diff --git a/scripts/docker/nginx-plus/ubuntu/Dockerfile b/scripts/docker/nginx-plus/ubuntu/Dockerfile index cfc43c4b2b..7e3ef84a5a 100644 --- a/scripts/docker/nginx-plus/ubuntu/Dockerfile +++ b/scripts/docker/nginx-plus/ubuntu/Dockerfile @@ -3,6 +3,7 @@ FROM ${BASE_IMAGE} as install LABEL maintainer="NGINX Docker Maintainers " ARG PACKAGES_REPO +ARG NGINX_AGENT_VERSION RUN echo $PACKAGES_REPO WORKDIR /agent @@ -37,7 +38,6 @@ RUN --mount=type=secret,id=nginx-crt,dst=/nginx-repo.crt \ # Install the latest release of NGINX Plus and/or NGINX Plus modules and NGINX Agent && nginxPackages=" \ nginx-plus \ - nginx-agent \ " \ && echo "Acquire::https::$PACKAGES_REPO::Verify-Peer \"true\";" > /etc/apt/apt.conf.d/90nginx \ && echo "Acquire::https::$PACKAGES_REPO::Verify-Host \"true\";" >> /etc/apt/apt.conf.d/90nginx \ @@ -51,8 +51,10 @@ RUN --mount=type=secret,id=nginx-crt,dst=/nginx-repo.crt \ && cat /nginx-repo.crt >> /etc/ssl/nginx/nginx-repo.crt \ && cat /nginx-repo.key >> /etc/ssl/nginx/nginx-repo.key \ && apt-get update \ - && apt-get install $nginxPackages -y \ - && rm /etc/ssl/nginx/nginx-repo.crt /etc/ssl/nginx/nginx-repo.key + && apt-get install $nginxPackages -y + +RUN if [ -z "$NGINX_AGENT_VERSION" ]; then apt-get install -y nginx-agent; else apt-get install -y nginx-agent=${NGINX_AGENT_VERSION}; fi +RUN rm /etc/ssl/nginx/nginx-repo.crt /etc/ssl/nginx/nginx-repo.key # run the nginx and agent FROM install as runtime diff --git a/scripts/packages/postinstall.sh b/scripts/packages/postinstall.sh index 0572d47265..288ede9240 100755 --- a/scripts/packages/postinstall.sh +++ b/scripts/packages/postinstall.sh @@ -46,7 +46,7 @@ detect_nginx_users() { if [ "$ID" = "alpine" ]; then nginx_user=$(ps aux | grep "nginx: master process" | grep -v grep | head -1 | awk '{print $2}') else - nginx_user=$(ps aux | grep "nginx: master process" | grep -v grep | head -1 | awk '{print $1}') + nginx_user=$(ps aux | grep "nginx: master process" | grep -v grep | head -1 | cut -f1 -d " ") fi if [ -z "${nginx_user}" ]; then @@ -87,7 +87,7 @@ detect_nginx_users() { if [ "$ID" = "alpine" ]; then worker_user=$(ps aux | grep "nginx: worker process" | grep -v grep | head -1 | awk '{print $2}') else - worker_user=$(ps aux | grep "nginx: worker process" | grep -v grep | head -1 | awk '{print $1}') + worker_user=$(ps aux | grep "nginx: worker process" | grep -v grep | head -1 | cut -f1 -d " ") fi if [ -z "${worker_user}" ]; then