Skip to content

Commit f224f49

Browse files
fix: Support for Agent v2 (#42)
1 parent e16806c commit f224f49

File tree

6 files changed

+38
-24
lines changed

6 files changed

+38
-24
lines changed

nginx/docker-image-builder/Dockerfile.oss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM nginx:stable-bullseye-perl@sha256:fc78d87401fdbadf36c638febdad36ae17dd51d7b
22

33
ARG NMS_URL
44
ARG NGINX_AGENT=false
5+
ARG NGINX_AGENT_VERSION=2
56

67
# Initial packages setup
78
RUN apt-get -y update \
@@ -22,7 +23,7 @@ RUN apt-get -y update \
2223
&& curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor > /usr/share/keyrings/nginx-archive-keyring.gpg \
2324
&& echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://packages.nginx.org/nginx-agent/debian/ `lsb_release -cs` agent" > /etc/apt/sources.list.d/nginx-agent.list \
2425
&& apt-get -y update \
25-
&& apt-get -y install nginx-agent; fi
26+
&& apt-get -y install nginx-agent=`apt-cache madison nginx-agent | grep "| $NGINX_AGENT_VERSION\." | awk '{print $3}' | head -n1`; fi
2627

2728
# Startup script
2829
COPY ./container/start.sh /deployment/

nginx/docker-image-builder/Dockerfile.plus

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM debian:bullseye-slim@sha256:779034981fec838da124ff6ab9211499ba5d4e769dabdfd
22

33
ARG NAP_WAF=false
44
ARG NGINX_AGENT=false
5+
ARG NGINX_AGENT_VERSION=2
56

67
# Initial packages setup
78
RUN apt-get -y update \
@@ -37,7 +38,7 @@ RUN --mount=type=secret,id=nginx-crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode=0644
3738
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor > /usr/share/keyrings/nginx-archive-keyring.gpg \
3839
&& echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://packages.nginx.org/nginx-agent/debian/ `lsb_release -cs` agent" > /etc/apt/sources.list.d/nginx-agent.list \
3940
&& apt-get -y update \
40-
&& apt-get -y install nginx-agent; fi
41+
&& apt-get -y install nginx-agent=`apt-cache madison nginx-agent | grep "| $NGINX_AGENT_VERSION\." | awk '{print $3}' | head -n1`; fi
4142

4243
# Startup script
4344
COPY ./container/start.sh /deployment/

nginx/docker-image-builder/Dockerfile.plus.unprivileged

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM debian:bullseye-slim@sha256:779034981fec838da124ff6ab9211499ba5d4e769dabdfd
22

33
ARG NAP_WAF=false
44
ARG NGINX_AGENT=false
5+
ARG NGINX_AGENT_VERSION=2
56

67
ARG UID=101
78
ARG GID=101
@@ -12,6 +13,8 @@ RUN apt-get -y update \
1213
&& mkdir -p /deployment /etc/ssl/nginx /etc/nms \
1314
&& addgroup --system --gid $GID nginx \
1415
&& adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid $UID nginx \
16+
&& addgroup --system --gid 1001 nginx-agent \
17+
&& usermod nginx -G nginx-agent \
1518
&& wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq \
1619
&& chmod +x /usr/bin/yq
1720

@@ -44,7 +47,7 @@ RUN --mount=type=secret,id=nginx-crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode=0644
4447
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor > /usr/share/keyrings/nginx-archive-keyring.gpg \
4548
&& echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://packages.nginx.org/nginx-agent/debian/ `lsb_release -cs` agent" > /etc/apt/sources.list.d/nginx-agent.list \
4649
&& apt-get -y update \
47-
&& apt-get -y install nginx-agent \
50+
&& apt-get -y install nginx-agent=`apt-cache madison nginx-agent | grep "| $NGINX_AGENT_VERSION\." | awk '{print $3}' | head -n1` \
4851
# implement changes required to run NGINX Agent as an unprivileged user
4952
&& chown -R $UID:0 /etc/nginx-agent \
5053
&& chmod -R g+w /etc/nginx-agent \
@@ -68,7 +71,9 @@ RUN rm /etc/nginx/conf.d/default.conf \
6871
&& chown -R $UID:0 /usr/lib/nginx/modules \
6972
&& chmod -R g+w /usr/lib/nginx/modules \
7073
&& chown -R $UID:0 /etc/nms \
71-
&& chmod -R g+w /etc/nms
74+
&& chmod -R g+w /etc/nms \
75+
&& chown -R $UID:0 /run \
76+
&& chmod -R g+w /run
7277

7378
# Startup script
7479
COPY ./container/start.sh /deployment/

nginx/docker-image-builder/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ NGINX Docker Image builder
5151
-w - Add NGINX App Protect WAF (requires NGINX Plus)
5252
-O - Use NGINX Open Source instead of NGINX Plus
5353
-u - Build unprivileged image (only for NGINX Plus)
54-
-a - Add NGINX Agent
54+
-a [2|3] - Add NGINX Agent v2 or v3
5555
5656
=== Examples:
5757
5858
NGINX Plus and NGINX Agent image:
59-
./scripts/build.sh -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-agent-root -a
59+
./scripts/build.sh -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-agent-root -a 2
6060
6161
NGINX Plus, NGINX App Protect WAF and NGINX Agent image:
62-
./scripts/build.sh -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-nap-agent-root -w -a
62+
./scripts/build.sh -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-nap-agent-root -w -a 2
6363
6464
NGINX Plus, NGINX App Protect WAF and NGINX Agent unprivileged image:
65-
./scripts/build.sh -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-nap-agent-nonroot -w -u -a
65+
./scripts/build.sh -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-nap-agent-nonroot -w -u -a 2
6666
6767
NGINX Opensource and NGINX Agent image:
68-
./scripts/build.sh -O -t registry.ff.lan:31005/nginx-docker:oss-root -a
68+
./scripts/build.sh -O -t registry.ff.lan:31005/nginx-docker:oss-root -a 2
6969
```
7070

7171
1. Clone this repository

nginx/docker-image-builder/container/start.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ nginx
1414
sleep 2
1515

1616
if [[ "$NGINX_AGENT_ENABLED" == "true" ]]; then
17-
18-
# NGINX Agent version detection, change in behaviour in v2.24.0+
19-
AGENT_VERSION=`nginx-agent -v|awk '{print $3}'`
20-
AGENT_VERSION_MAJOR=`echo $AGENT_VERSION | awk -F\. '{print $1}' | sed 's/v//'`
21-
AGENT_VERSION_MINOR=`echo $AGENT_VERSION | awk -F\. '{print $2}'`
22-
23-
echo "=> NGINX Agent version $AGENT_VERSION"
24-
2517
PARM=""
2618

2719
yq -i '

nginx/docker-image-builder/scripts/build.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ $0 [options]\n\n
1414
-w\t\t\t- Add NGINX App Protect WAF (requires NGINX Plus)\n
1515
-O\t\t\t- Use NGINX Open Source instead of NGINX Plus\n
1616
-u\t\t\t- Build unprivileged image (only for NGINX Plus)\n
17-
-a\t\t\t- Add NGINX Agent\n\n
17+
-a [2|3]\t\t- Add NGINX Agent v2 or v3\n\n
1818
=== Examples:\n\n
1919
NGINX Plus and NGINX Agent image:\n
20-
$0 -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-agent-root -a\n\n
20+
$0 -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-agent-root -a 2\n\n
2121
2222
NGINX Plus, NGINX App Protect WAF and NGINX Agent image:\n
23-
$0 -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-nap-agent-root -w -a\n\n
23+
$0 -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-nap-agent-root -w -a 2\n\n
2424
2525
NGINX Plus, NGINX App Protect WAF and NGINX Agent unprivileged image:\n
26-
$0 -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-nap-agent-nonroot -w -u -a\n\n
26+
$0 -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-docker:plus-nap-agent-nonroot -w -u -a 2\n\n
2727
2828
NGINX Opensource and NGINX Agent image:\n
29-
$0 -O -t registry.ff.lan:31005/nginx-docker:oss-root -a\n"
29+
$0 -O -t registry.ff.lan:31005/nginx-docker:oss-root -a 2\n"
3030

31-
while getopts 'ht:C:K:awOu' OPTION
31+
while getopts 'ht:C:K:a:wOu' OPTION
3232
do
3333
case "$OPTION" in
3434
h)
@@ -46,6 +46,7 @@ do
4646
;;
4747
a)
4848
NGINX_AGENT=true
49+
NGINX_AGENT_VERSION=$OPTARG
4950
;;
5051
w)
5152
NAP_WAF=true
@@ -71,6 +72,12 @@ then
7172
exit
7273
fi
7374

75+
if [ -z "${NGINX_AGENT_VERSION}" ]
76+
then
77+
echo "NGINX Agent version is required"
78+
exit
79+
fi
80+
7481
if ([ -z "${NGINX_OSS}" ] && ([ -z "${NGINX_CERT}" ] || [ -z "${NGINX_KEY}" ]) )
7582
then
7683
echo "NGINX certificate and key are required for automated installation"
@@ -81,7 +88,13 @@ echo "=> Target docker image is $IMAGENAME"
8188

8289
if [ "${NGINX_AGENT}" ]
8390
then
84-
echo "=> Building with NGINX Agent"
91+
if [ "${NGINX_AGENT_VERSION}" -eq "2" ] || [ "${NGINX_AGENT_VERSION}" -eq "3" ]
92+
then
93+
echo "=> Building with NGINX Agent v${NGINX_AGENT_VERSION}"
94+
else
95+
echo "NGINX Agent version must be either '2' or '3'"
96+
exit
97+
fi
8598
fi
8699

87100
if ([ ! -z "${NAP_WAF}" ] && [ -z "${NGINX_OSS}" ])
@@ -104,12 +117,14 @@ then
104117
DOCKER_BUILDKIT=1 docker build --no-cache -f $DOCKERFILE_NAME \
105118
--secret id=nginx-key,src=$NGINX_KEY --secret id=nginx-crt,src=$NGINX_CERT \
106119
--build-arg NAP_WAF=$NAP_WAF --build-arg NGINX_AGENT=$NGINX_AGENT \
120+
--build-arg NGINX_AGENT_VERSION=$NGINX_AGENT_VERSION \
107121
$OPT_PLATFORM \
108122
-t $IMAGENAME .
109123
else
110124
echo "=> Building with NGINX Open Source"
111125
DOCKER_BUILDKIT=1 docker build --no-cache -f Dockerfile.oss \
112126
--build-arg NGINX_AGENT=$NGINX_AGENT \
127+
--build-arg NGINX_AGENT_VERSION=$NGINX_AGENT_VERSION \
113128
-t $IMAGENAME .
114129
fi
115130

0 commit comments

Comments
 (0)