Skip to content

Commit 79b45d9

Browse files
committed
Add own nginx container that reloads on config changes
Sadly the standard nginx container image doesn't reload nginx if the config is change. With out gvm-config approach the config might change with an update of the gvm-config container image and without reloading nginx the new config wouldn't be applied. Therefore we need an own nginx container image that auto reloads if the config changes.
1 parent 10d418b commit 79b45d9

3 files changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Nginx Container Image Builds
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "v*"
9+
paths:
10+
- nginx/*
11+
- .github/workflows/container-nginx.yml
12+
pull_request:
13+
branches:
14+
- main
15+
paths:
16+
- nginx/*
17+
- .github/workflows/container-nginx.yml
18+
workflow_dispatch:
19+
schedule:
20+
# rebuild image every sunday
21+
- cron: "0 0 * * 0"
22+
23+
permissions:
24+
contents: read
25+
packages: write
26+
id-token: write
27+
pull-requests: write
28+
29+
jobs:
30+
nginx-images:
31+
name: Build and upload Nginx container image
32+
runs-on: self-hosted-generic
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v6
37+
- name: Login to ghcr.io
38+
uses: docker/login-action@v3
39+
with:
40+
registry: ghcr.io
41+
username: ${{ github.actor }}
42+
password: ${{ secrets.GITHUB_TOKEN }}
43+
- name: Login to Greenbone Registry
44+
uses: docker/login-action@v3
45+
with:
46+
registry: ${{ vars.GREENBONE_REGISTRY }}
47+
username: ${{ secrets.GREENBONE_REGISTRY_USER }}
48+
password: ${{ secrets.GREENBONE_REGISTRY_TOKEN }}
49+
- name: Setup container meta information
50+
id: meta
51+
uses: docker/metadata-action@v5
52+
with:
53+
images: |
54+
ghcr.io/greenbone/nginx
55+
${{ vars.GREENBONE_REGISTRY }}/community/nginx
56+
labels: |
57+
org.opencontainers.image.vendor=Greenbone
58+
org.opencontainers.image.documentation=https://greenbone.github.io/docs/
59+
org.opencontainers.image.base.name=nginx:stable-trixie
60+
flavor: latest=false # no latest container tag for git tags
61+
tags: |
62+
# create container tag for git tags
63+
type=ref,event=tag
64+
type=ref,event=pr
65+
# set latest for main branch pushes
66+
type=raw,value=latest,enable={{is_default_branch}}
67+
- name: Set up QEMU
68+
uses: docker/setup-qemu-action@v3
69+
- name: Set up Docker Buildx
70+
uses: docker/setup-buildx-action@v3
71+
- name: Build and push Container image
72+
uses: docker/build-push-action@v6
73+
with:
74+
context: nginx
75+
push: ${{ github.event_name != 'pull_request' }}
76+
file: nginx/Dockerfile
77+
platforms: linux/amd64,linux/arm64
78+
labels: ${{ steps.meta.outputs.labels }}
79+
tags: ${{ steps.meta.outputs.tags }}

nginx/40-auto-reload.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
AUTO_RELOAD_FILES=${AUTO_RELOAD_FILES:-/etc/nginx/conf.d/*.conf /etc/nginx/nginx.conf}
6+
7+
auto_reload() {
8+
while inotifywait --event create,modify,delete --quiet ${AUTO_RELOAD_FILES}
9+
do
10+
printf "Detected change in %s, reloading Nginx...\n" "${AUTO_RELOAD_FILES}"
11+
nginx -s reload
12+
done
13+
}
14+
15+
if [ -n "${AUTO_RELOAD_FILES}" ]; then
16+
auto_reload &
17+
fi

nginx/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ARG NGINX_VERSION=stable-trixie
2+
FROM nginx:$NGINX_VERSION
3+
4+
RUN apt-get update && apt-get install --no-install-recommends --no-install-suggests -y \
5+
inotify-tools \
6+
&& rm -rf /var/lib/apt/lists/*
7+
8+
COPY 40-auto-reload.sh /docker-entrypoint.d/40-auto-reload.sh
9+
RUN chmod 755 /docker-entrypoint.d/40-auto-reload.sh

0 commit comments

Comments
 (0)