Skip to content

Commit f7af2aa

Browse files
NGINX Opensource support added (#142)
1 parent 360c8ab commit f7af2aa

File tree

4 files changed

+76
-36
lines changed

4 files changed

+76
-36
lines changed

nginx-agent-docker/Dockerfile.oss

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM nginx:stable-bullseye-perl
2+
3+
ARG NMS_URL
4+
5+
# Initial packages setup
6+
RUN apt-get -y update \
7+
&& apt-get -y install wget gpg \
8+
&& wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq \
9+
&& chmod +x /usr/bin/yq \
10+
&& set -x \
11+
# Forward request logs to Docker log collector
12+
&& ln -sf /dev/stdout /var/log/nginx/access.log \
13+
&& ln -sf /dev/stderr /var/log/nginx/error.log \
14+
# User and group
15+
&& groupadd -g 1001 nginx-agent \
16+
&& usermod root -G nginx-agent \
17+
&& usermod nginx -G nginx-agent \
18+
# NGINX Instance Manager agent installation
19+
&& if [ `curl -o /dev/null -sk -w "%{http_code}\n" $NMS_URL/install/nginx-agent` = 200 ] ; then \
20+
bash -c 'export DATA_PLANE_KEY="placeholder" && curl -k $NMS_URL/install/nginx-agent | sh' && echo "NGINX Agent installed"; else \
21+
bash -c 'export DATA_PLANE_KEY="placeholder" && curl -k $NMS_URL/nginx-agent/install | sh || :' && echo "NGINX Agent installed"; fi
22+
23+
# Startup script
24+
COPY ./container/start.sh /deployment/
25+
RUN chmod +x /deployment/start.sh && touch /.dockerenv
26+
27+
EXPOSE 80
28+
STOPSIGNAL SIGTERM
29+
30+
CMD /deployment/start.sh

nginx-agent-docker/Dockerfile renamed to nginx-agent-docker/Dockerfile.plus

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ ARG NMS_URL
44
ARG NAP_WAF=false
55

66
# Initial packages setup
7-
RUN apt-get -y update \
7+
RUN apt-get -y update \
88
&& apt-get -y install apt-transport-https lsb-release ca-certificates wget gnupg2 curl debian-archive-keyring iproute2 \
99
&& mkdir -p /deployment /etc/ssl/nginx \
1010
&& addgroup --system --gid 20983 nginx \
1111
&& adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 20983 nginx \
12-
&& wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq \
13-
&& chmod +x /usr/bin/yq
12+
&& wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq \
13+
&& chmod +x /usr/bin/yq
1414

1515
# Use certificate and key from kubernetes secret
1616
RUN --mount=type=secret,id=nginx-crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode=0644 \
@@ -43,8 +43,7 @@ RUN --mount=type=secret,id=nginx-crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode=0644
4343

4444
# Startup script
4545
COPY ./container/start.sh /deployment/
46-
RUN chmod +x /deployment/start.sh && touch /.dockerenv
47-
46+
RUN chmod +x /deployment/start.sh && touch /.dockerenv
4847

4948
EXPOSE 80
5049
STOPSIGNAL SIGTERM

nginx-agent-docker/README.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
## Description
44

5-
This repository can be used to build a docker image with NGINX Plus and NGINX Instance Manager Agent (https://docs.nginx.com/nginx-instance-manager/).
5+
This repository can be used to build a docker image with NGINX (Plus or Opensource) and NGINX Instance Manager Agent (https://docs.nginx.com/nginx-instance-manager/).
66

77
## Tested releases
88

99
This repository has been tested with: NGINX agent for:
1010

11+
- NGINX Plus R29+
12+
- NGINX Opensource 1.24.0+
1113
- NGINX Agent 2.14+
1214
- NGINX Instance Manager 2.15+
1315
- NGINX App Protect WAF 4.100.1+
@@ -27,10 +29,9 @@ This repository has been tested with: NGINX agent for:
2729
The install script can be used to build the Docker image:
2830

2931
```
30-
$ ./scripts/build.sh
31-
NGINX Plus & NGINX Instance Manager agent Docker image builder
32+
NGINX Opensource/Plus & NGINX Agent Docker image builder
3233
33-
This tool builds a Docker image to run NGINX Plus and NGINX Instance Manager agent
34+
This tool builds a Docker image to run NGINX Opensource/Plus and NGINX Agent
3435
3536
=== Usage:
3637
@@ -42,8 +43,9 @@ NGINX Plus & NGINX Instance Manager agent Docker image builder
4243
-t [target image] - The Docker image to be created
4344
-C [file.crt] - Certificate to pull packages from the official NGINX repository
4445
-K [file.key] - Key to pull packages from the official NGINX repository
45-
-n [URL] - NGINX Instance Manager URL to fetch the agent
46-
-w - Add NGINX App Protect WAF
46+
-n [URL] - NGINX Instance Manager / NGINX SaaS console URL to fetch the agent
47+
-w - Add NGINX App Protect WAF (requires NGINX Plus)
48+
-O - Use NGINX Opensource instead of NGINX Plus
4749
4850
=== Examples:
4951
@@ -52,21 +54,18 @@ NGINX Plus & NGINX Instance Manager agent Docker image builder
5254
5355
NGINX Plus, NGINX App Protect WAF and NGINX Agent image:
5456
./scripts/build.sh -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-with-agent:latest-nap -w -n https://nim.f5.ff.lan
57+
58+
NGINX Opensource and NGINX Agent image:
59+
./scripts/build.sh -O -t registry.ff.lan:31005/nginx-oss-with-agent:latest -n https://nim.f5.ff.lan
5560
```
5661

5762
1. Clone this repository
58-
2. Get your license certificate and key to fetch NGINX Management Suite packages from NGINX repository
59-
3. [Install](https://docs.nginx.com/nginx-management-suite/) and start NGINX Management Suite / NGINX Instance Manager
60-
4. Build the Docker image using:
61-
62-
```
63-
$ ./scripts/build.sh -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-with-agent:r28 -n https://ubuntu.ff.lan
64-
```
63+
2. For NGINX Plus only: get your license certificate and key to fetch NGINX Management Suite packages from NGINX repository
64+
3. [Install](https://docs.nginx.com/nginx-management-suite/) and start NGINX Management Suite / NGINX Instance Manager. Skip this step if using the NGINX SaaS console
65+
4. Build the Docker image using `./scripts/build.sh`
6566

6667
the build script will push the image to your private registry once build is complete.
6768

68-
- the `-w` flag can be used to include NGINX App Protect WAF support in the docker image
69-
7069
### Running the docker image on Kubernetes
7170

7271
1. Edit `manifests/1.nginx-nim.yaml` and specify the correct image by modifying the `image:` line, and set the following environment variables. Default values for `NIM_HOST` and `NIM_GRPC_PORT` can be used if NGINX Instance Manager is deployed using https://github.com/nginxinc/NGINX-Demos/tree/master/nginx-nms-docker
@@ -75,9 +74,9 @@ the build script will push the image to your private registry once build is comp
7574
- `NIM_TOKEN` - NGINX One Cloud Console authentication token
7675
- `NIM_INSTANCEGROUP` - instance group for the NGINX instance
7776
- `NIM_TAGS` - comma separated list of tags for the NGINX instance
78-
- `NIM_ADVANCED_METRICS` - set to `"true"` to enable advanced metrics collection
79-
- `NAP_WAF` - set to `"true"` to enable NGINX App Protect WAF (docker image built using `-w`)
80-
- `NAP_WAF_PRECOMPILED_POLICIES` - set to `"true"` to enable NGINX App Protect WAF precompiled policies (docker image built using `-w`)
77+
- `NIM_ADVANCED_METRICS` - set to `"true"` to enable advanced metrics collection - NGINX Plus only
78+
- `NAP_WAF` - set to `"true"` to enable NGINX App Protect WAF (docker image built using `-w`) - NGINX Plus only
79+
- `NAP_WAF_PRECOMPILED_POLICIES` - set to `"true"` to enable NGINX App Protect WAF precompiled policies (docker image built using `-w`) - NGINX Plus only
8180
- `AGENT_LOGLEVEL` - NGINX Agent loglevel, optional. If not specified defaults to `info`
8281

8382
2. Start and stop using
@@ -87,7 +86,7 @@ $ ./scripts/nginxWithAgentStart.sh start
8786
$ ./scripts/nginxWithAgentStart.sh stop
8887
```
8988

90-
3. After startup NGINX Plus instances will register to NGINX Instance Manager and will be displayed on the "instances" dashboard
89+
3. After startup NGINX instances will register to NGINX Instance Manager / NGINX SaaS console and will be displayed on the "instances" dashboard
9190

9291
### Running the docker image on Docker
9392

nginx-agent-docker/scripts/build.sh

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@
22

33
# https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-docker/#docker_plus
44

5-
BANNER="NGINX Plus & NGINX Instance Manager agent Docker image builder\n\n
6-
This tool builds a Docker image to run NGINX Plus and NGINX Instance Manager agent\n\n
5+
BANNER="NGINX Opensource/Plus & NGINX Agent Docker image builder\n\n
6+
This tool builds a Docker image to run NGINX Opensource/Plus and NGINX Agent\n\n
77
=== Usage:\n\n
88
$0 [options]\n\n
99
=== Options:\n\n
1010
-h\t\t\t- This help\n
1111
-t [target image]\t- The Docker image to be created\n
1212
-C [file.crt]\t\t- Certificate to pull packages from the official NGINX repository\n
1313
-K [file.key]\t\t- Key to pull packages from the official NGINX repository\n
14-
-n [URL]\t\t- NGINX Instance Manager URL to fetch the agent\n
15-
-w\t\t\t- Add NGINX App Protect WAF\n\n
14+
-n [URL]\t\t- NGINX Instance Manager / NGINX SaaS console URL to fetch the agent\n
15+
-w\t\t\t- Add NGINX App Protect WAF (requires NGINX Plus)\n
16+
-O\t\t\t- Use NGINX Opensource instead of NGINX Plus\n\n
1617
=== Examples:\n\n
1718
NGINX Plus and NGINX Agent image:\n
1819
$0 -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-with-agent:latest -n https://nim.f5.ff.lan\n\n
1920
NGINX Plus, NGINX App Protect WAF and NGINX Agent image:\n
20-
$0 -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-with-agent:latest-nap -w -n https://nim.f5.ff.lan\n"
21+
$0 -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-with-agent:latest-nap -w -n https://nim.f5.ff.lan\n\n
22+
NGINX Opensource and NGINX Agent image:\n
23+
$0 -O -t registry.ff.lan:31005/nginx-oss-with-agent:latest -n https://nim.f5.ff.lan\n"
2124

22-
while getopts 'ht:C:K:a:n:w' OPTION
25+
while getopts 'ht:C:K:a:n:wO' OPTION
2326
do
2427
case "$OPTION" in
2528
h)
@@ -41,6 +44,9 @@ do
4144
w)
4245
NAP_WAF=true
4346
;;
47+
O)
48+
NGINX_OSS=true
49+
;;
4450
esac
4551
done
4652

@@ -58,26 +64,32 @@ fi
5864

5965
if [ -z "${NMSURL}" ]
6066
then
61-
echo "NGINX Instance Manager URL is required"
67+
echo "NGINX Instance Manager / NGINX SaaS console URL is required"
6268
exit
6369
fi
6470

65-
if ([ -z "${NGINX_CERT}" ] || [ -z "${NGINX_KEY}" ])
71+
if ([ -z "${NGINX_OSS}" ] && ([ -z "${NGINX_CERT}" ] || [ -z "${NGINX_KEY}" ]) )
6672
then
6773
echo "NGINX certificate and key are required for automated installation"
6874
exit
6975
fi
7076

7177
echo "=> Target docker image is $IMAGENAME"
7278

73-
if [ ! -z "${NAP_WAF}" ]
79+
if ([ ! -z "${NAP_WAF}" ] && [ -z "${NGINX_OSS}" ])
7480
then
7581
echo "=> Building with NGINX App Protect WAF support"
7682
fi
7783

78-
DOCKER_BUILDKIT=1 docker build --no-cache -f Dockerfile \
79-
--secret id=nginx-key,src=$NGINX_KEY --secret id=nginx-crt,src=$NGINX_CERT \
80-
--build-arg NMS_URL=$NMSURL --build-arg NAP_WAF=$NAP_WAF -t $IMAGENAME .
84+
if [ -z "${NGINX_OSS}" ]
85+
then
86+
DOCKER_BUILDKIT=1 docker build --no-cache -f Dockerfile.plus \
87+
--secret id=nginx-key,src=$NGINX_KEY --secret id=nginx-crt,src=$NGINX_CERT \
88+
--build-arg NMS_URL=$NMSURL --build-arg NAP_WAF=$NAP_WAF -t $IMAGENAME .
89+
else
90+
DOCKER_BUILDKIT=1 docker build --no-cache -f Dockerfile.oss \
91+
--build-arg NMS_URL=$NMSURL -t $IMAGENAME .
92+
fi
8193

8294
echo "=> Build complete for $IMAGENAME"
8395
docker push $IMAGENAME

0 commit comments

Comments
 (0)