Skip to content

feat: Create container image of utility tools not avialable in production containers #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b39b200
feat: Create container image of utility tools not avialable in produc…
mrajagopal Nov 20, 2024
98a5ca5
Merge branch 'main' into mrajagopal-utils-pod
mrajagopal Mar 24, 2025
fed2bf3
feat: introduce NGINX API stats script
mrajagopal Mar 27, 2025
bd77d7b
Added additional tools for troubleshooting
mrajagopal May 30, 2025
d49821f
Fix: api_stats.sh improvements
mrajagopal Jun 9, 2025
742a308
Feat: Add docker-build.yml to githb workflow
mrajagopal Jun 13, 2025
90eac87
Fix: copy the local file correctly using Dockerfile syntax
mrajagopal Jun 13, 2025
053a479
fix: debug docker build workflow in github actions
mrajagopal Jun 13, 2025
47cc68e
Fix: copy file properly in Dockerfile
mrajagopal Jun 13, 2025
71e82a3
Fix: fix docker image push failure
mrajagopal Jun 13, 2025
60ac1ac
Fix: push container image to GHCR
mrajagopal Jun 13, 2025
36d1e3e
Feat: Add trivy vulnerability scan and upload report via github workflow
mrajagopal Jun 13, 2025
c4985c3
fix: vulnerability scan
mrajagopal Jun 13, 2025
8c18049
fix: vulnerability scan and report upload
mrajagopal Jun 13, 2025
9184914
fix: vulnerability report upload
mrajagopal Jun 13, 2025
bae4b72
fix: upload artifact vuln report
mrajagopal Jun 13, 2025
c70c569
Merge branch 'main' into mrajagopal-utils-pod
mrajagopal Jun 15, 2025
ea96377
Chore: Added opencontainerer annotations to the nginx-utils image
mrajagopal Jun 15, 2025
141aebb
Fix: Address workflow persmissions
mrajagopal Jun 15, 2025
3c17608
Fix: Use recent releases for workflow jobs pipeline
mrajagopal Jun 16, 2025
e20a960
Feat: Added memory stats script to the container image
mrajagopal Jun 16, 2025
75fc05c
Fix: Output JSON raw for unformatted redirection to file
mrajagopal Jun 16, 2025
c7aa018
Chore: Change docker-build workflow
mrajagopal Jun 16, 2025
bae23ef
Fix: Build container image on release trigger
mrajagopal Jun 17, 2025
47baa6d
Fix: Added muti-platform directive to docker-build workflow
mrajagopal Jun 17, 2025
ebc3ab8
Fix: Add build tags based on release tag to docker-build workflow
mrajagopal Jun 17, 2025
7d01e3b
Fix: Build the container based -docker release name
mrajagopal Jun 17, 2025
cedd60f
Fix: Build the krew based on -krew in the release name
mrajagopal Jun 18, 2025
6c73187
Fix: Add docker image info to release notes via dock-build workflow
mrajagopal Jun 18, 2025
727620e
feat: strip prefix in krew release version tags
dareste Jun 18, 2025
b9aa761
Fix: Strip suffix in docker image release tag
mrajagopal Jun 18, 2025
f94e888
Merge branch 'main' into mrajagopal-utils-pod
mrajagopal Jun 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build and Push Docker Image For nginx-utils Container
permissions:
contents: read
packages: write
actions: write
on:
release:
types: [created]

env:
RELEASE_VERSION: ${{ github.event.release.tag_name }}
jobs:
run-on-release:
if: endsWith(github.event.release.tag_name, '-docker')
runs-on: ubuntu-latest
steps:
- name: Set Release Version
run: echo "RELEASE_VERSION=${RELEASE_VERSION%-docker}" >> $GITHUB_ENV

- name: Starting Release Build
run: echo "Starting Release Build for ${RELEASE_VERSION}"

- name: Checkout code
uses: actions/checkout@v4.2.2

- name: List repository files
run: ls -R .; pwd
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.10.0

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3.4.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6.18.0
with:
context: .
file: nginx-utils/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/nginx/nginx-utils:${{ env.RELEASE_VERSION }}
ghcr.io/nginx/nginx-utils:latest

- name: Install Trivy and scan image for vulnerabilities
uses: aquasecurity/trivy-action@0.31.0

with:
image-ref: ghcr.io/${{ github.repository_owner }}/nginx-utils:latest
format: json
output: vuln-report.json

- name: Upload Vulnerability Report
uses: actions/upload-artifact@v4.6.2
with:
name: vuln-report
path: vuln-report.json

- name: Update Release Notes with Docker Image Info
uses: softprops/action-gh-release@v2.3.2
with:
tag_name: ${{ github.event.release.tag_name }}
body: |
## Docker Image
The Docker image for this release can be pulled using:

```
docker pull ghcr.io/${{ github.repository_owner }}/nginx-utils:${{ github.event.release.tag_name }}
```

Or use the `latest` tag:

```
docker pull ghcr.io/${{ github.repository_owner }}/nginx-utils:latest
```
3 changes: 2 additions & 1 deletion .github/workflows/release-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env:

jobs:
build:
if: endsWith(github.event.release.tag_name, '-krew')
permissions:
contents: write

Expand All @@ -22,7 +23,7 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set Release Version
run: echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
run: echo "RELEASE_VERSION=${RELEASE_VERSION%-krew}" >> $GITHUB_ENV

- name: Set up Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.PHONY: nginx-utils build install
build:
go build -o cmd/kubectl-nginx_supportpkg

nginx-utils:
docker buildx build --build-context project=nginx-utils --platform linux/amd64 -t nginx-utils -f nginx-utils/Dockerfile .

install: build
sudo cp cmd/kubectl-nginx_supportpkg /usr/local/bin
27 changes: 27 additions & 0 deletions nginx-utils/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM alpine:latest

LABEL org.opencontainers.image.description="Container image including various troubleshooting tools such as curl, tcpdump, iperf, netcat to name a few not available in the target container"
LABEL org.opencontainers.image.vendor="NGINX"
LABEL org.opencontainers.image.authors="NGINX <plus-support@nginx.com>"
LABEL org.opencontainers.image.url="https://github.com/nginx/nginx-supportpkg-for-k8s/pkgs/container/nginx-utils"
LABEL org.opencontainers.image.documentation="https://github.com/nginx/nginx-supportpkg-for-k8s/pkgs/container/nginx-utils"
LABEL org.opencontainers.image.source="https://github.com/nginx/nginx-supportpkg-for-k8s/tree/main/nginx-utils"
LABEL org.opencontainers.image.licenses="Apache-2.0"

COPY --chmod=744 nginx-utils/api_stats.sh /root/api_stats.sh
COPY --chmod=744 nginx-utils/memory_stats.sh /root/memory_stats.sh

RUN set -ex \
&& apk --update add --no-cache \
bind-tools curl netcat-openbsd iproute2 \
iperf tcpdump tshark bash jq \
&& rm -rf /var/cache/apk/* \
&& ln -s /usr/bin/iperf /usr/local/bin/iperf \
&& ls -altrh /usr/local/bin/iperf

# Setting User and Home
USER root
WORKDIR /root
ENV HOSTNAME=nginx-utils

CMD ["bash"]
43 changes: 43 additions & 0 deletions nginx-utils/api_stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

# Parse command line options
set -e
set -o pipefail
while getopts "p:v:h" opt; do
case $opt in
p) API_PORT="$OPTARG"
;;
h) echo "Usage: $0 [-p port]"
exit 0
;;
\?) echo "Invalid option -$OPTARG" >&2
echo "Usage: $0 [-p port]"
exit 1
;;
esac
done

if [ $OPTIND -eq 1 ]; then
echo "No options were passed, exiting ..."
echo "Usage: $(basename "$0") [-p port]"
exit 1
fi

if [ -z "${API_PORT}" ]; then
echo 'Missing -p arg' >&2
exit 1
fi

api_versions=($(curl -s http://127.0.0.1:$API_PORT/api/ | sed -e 's/\[//g' -e 's/\]//g' -e 's/\,/ /g'))
API_VERSION=${api_versions[-1]}
echo "API_VERSION: $API_VERSION"

echo "**** /api/$API_VERSION/nginx ****" ;
curl -s "127.0.0.1:$API_PORT/api/$API_VERSION/nginx" | jq -r '.';
echo "";

for i in /api/$API_VERSION/processes /api/$API_VERSION/connections /api/$API_VERSION/slabs /api/$API_VERSION/http/requests /api/$API_VERSION/http/server_zones /api/$API_VERSION/http/location_zones /api/$API_VERSION/http/caches /api/$API_VERSION/http/upstreams /api/$API_VERSION/http/keyvals; do
echo "**** $i ****" ;
curl -s "127.0.0.1:$API_PORT/$i" | jq -r '.';
echo "";
done
13 changes: 13 additions & 0 deletions nginx-utils/memory_stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
echo ""
echo " **** Output of memory.stat ****"
cat /sys/fs/cgroup/memory.stat

echo ""
echo " **** Output of pmap for nginx and nginx-ingress processes ****"
for p in $(pidof nginx nginx-ingress); do pmap ${p} -x; done

echo ""
echo " **** Output of /proc/pid/status for nginx and nginx-ingress processes ****"
for p in $(pidof nginx nginx-ingress); do cat /proc/${p}/status; done