Skip to content

Commit 50f1c34

Browse files
authored
Merge pull request #78 from nginx/mrajagopal-utils-pod
feat: Create container image of utility tools not available in production containers
2 parents 03812cb + f94e888 commit 50f1c34

File tree

6 files changed

+167
-1
lines changed

6 files changed

+167
-1
lines changed

.github/workflows/docker-build.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Build and Push Docker Image For nginx-utils Container
2+
permissions:
3+
contents: read
4+
packages: write
5+
actions: write
6+
on:
7+
release:
8+
types: [created]
9+
10+
env:
11+
RELEASE_VERSION: ${{ github.event.release.tag_name }}
12+
jobs:
13+
run-on-release:
14+
if: endsWith(github.event.release.tag_name, '-docker')
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Set Release Version
18+
run: echo "RELEASE_VERSION=${RELEASE_VERSION%-docker}" >> $GITHUB_ENV
19+
20+
- name: Starting Release Build
21+
run: echo "Starting Release Build for ${RELEASE_VERSION}"
22+
23+
- name: Checkout code
24+
uses: actions/[email protected]
25+
26+
- name: List repository files
27+
run: ls -R .; pwd
28+
- name: Set up Docker Buildx
29+
uses: docker/[email protected]
30+
31+
- name: Log in to GitHub Container Registry
32+
uses: docker/[email protected]
33+
with:
34+
registry: ghcr.io
35+
username: ${{ github.repository_owner }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
- name: Build and push Docker image
38+
uses: docker/[email protected]
39+
with:
40+
context: .
41+
file: nginx-utils/Dockerfile
42+
push: true
43+
platforms: linux/amd64,linux/arm64
44+
tags: |
45+
ghcr.io/nginx/nginx-utils:${{ env.RELEASE_VERSION }}
46+
ghcr.io/nginx/nginx-utils:latest
47+
48+
- name: Install Trivy and scan image for vulnerabilities
49+
uses: aquasecurity/[email protected]
50+
51+
with:
52+
image-ref: ghcr.io/${{ github.repository_owner }}/nginx-utils:latest
53+
format: json
54+
output: vuln-report.json
55+
56+
- name: Upload Vulnerability Report
57+
uses: actions/[email protected]
58+
with:
59+
name: vuln-report
60+
path: vuln-report.json
61+
62+
- name: Update Release Notes with Docker Image Info
63+
uses: softprops/[email protected]
64+
with:
65+
tag_name: ${{ github.event.release.tag_name }}
66+
body: |
67+
## Docker Image
68+
The Docker image for this release can be pulled using:
69+
70+
```
71+
docker pull ghcr.io/${{ github.repository_owner }}/nginx-utils:${{ github.event.release.tag_name }}
72+
```
73+
74+
Or use the `latest` tag:
75+
76+
```
77+
docker pull ghcr.io/${{ github.repository_owner }}/nginx-utils:latest
78+
```

.github/workflows/release-builder.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212

1313
jobs:
1414
build:
15+
if: endsWith(github.event.release.tag_name, '-krew')
1516
permissions:
1617
contents: write
1718

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

2425
- name: Set Release Version
25-
run: echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
26+
run: echo "RELEASE_VERSION=${RELEASE_VERSION%-krew}" >> $GITHUB_ENV
2627

2728
- name: Set up Go
2829
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
.PHONY: nginx-utils build install
12
build:
23
go build -o cmd/kubectl-nginx_supportpkg
34

5+
nginx-utils:
6+
docker buildx build --build-context project=nginx-utils --platform linux/amd64 -t nginx-utils -f nginx-utils/Dockerfile .
7+
48
install: build
59
sudo cp cmd/kubectl-nginx_supportpkg /usr/local/bin

nginx-utils/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM alpine:latest
2+
3+
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"
4+
LABEL org.opencontainers.image.vendor="NGINX"
5+
LABEL org.opencontainers.image.authors="NGINX <[email protected]>"
6+
LABEL org.opencontainers.image.url="https://github.com/nginx/nginx-supportpkg-for-k8s/pkgs/container/nginx-utils"
7+
LABEL org.opencontainers.image.documentation="https://github.com/nginx/nginx-supportpkg-for-k8s/pkgs/container/nginx-utils"
8+
LABEL org.opencontainers.image.source="https://github.com/nginx/nginx-supportpkg-for-k8s/tree/main/nginx-utils"
9+
LABEL org.opencontainers.image.licenses="Apache-2.0"
10+
11+
COPY --chmod=744 nginx-utils/api_stats.sh /root/api_stats.sh
12+
COPY --chmod=744 nginx-utils/memory_stats.sh /root/memory_stats.sh
13+
14+
RUN set -ex \
15+
&& apk --update add --no-cache \
16+
bind-tools curl netcat-openbsd iproute2 \
17+
iperf tcpdump tshark bash jq \
18+
&& rm -rf /var/cache/apk/* \
19+
&& ln -s /usr/bin/iperf /usr/local/bin/iperf \
20+
&& ls -altrh /usr/local/bin/iperf
21+
22+
# Setting User and Home
23+
USER root
24+
WORKDIR /root
25+
ENV HOSTNAME=nginx-utils
26+
27+
CMD ["bash"]

nginx-utils/api_stats.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# Parse command line options
4+
set -e
5+
set -o pipefail
6+
while getopts "p:v:h" opt; do
7+
case $opt in
8+
p) API_PORT="$OPTARG"
9+
;;
10+
h) echo "Usage: $0 [-p port]"
11+
exit 0
12+
;;
13+
\?) echo "Invalid option -$OPTARG" >&2
14+
echo "Usage: $0 [-p port]"
15+
exit 1
16+
;;
17+
esac
18+
done
19+
20+
if [ $OPTIND -eq 1 ]; then
21+
echo "No options were passed, exiting ..."
22+
echo "Usage: $(basename "$0") [-p port]"
23+
exit 1
24+
fi
25+
26+
if [ -z "${API_PORT}" ]; then
27+
echo 'Missing -p arg' >&2
28+
exit 1
29+
fi
30+
31+
api_versions=($(curl -s http://127.0.0.1:$API_PORT/api/ | sed -e 's/\[//g' -e 's/\]//g' -e 's/\,/ /g'))
32+
API_VERSION=${api_versions[-1]}
33+
echo "API_VERSION: $API_VERSION"
34+
35+
echo "**** /api/$API_VERSION/nginx ****" ;
36+
curl -s "127.0.0.1:$API_PORT/api/$API_VERSION/nginx" | jq -r '.';
37+
echo "";
38+
39+
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
40+
echo "**** $i ****" ;
41+
curl -s "127.0.0.1:$API_PORT/$i" | jq -r '.';
42+
echo "";
43+
done

nginx-utils/memory_stats.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
echo ""
4+
echo " **** Output of memory.stat ****"
5+
cat /sys/fs/cgroup/memory.stat
6+
7+
echo ""
8+
echo " **** Output of pmap for nginx and nginx-ingress processes ****"
9+
for p in $(pidof nginx nginx-ingress); do pmap ${p} -x; done
10+
11+
echo ""
12+
echo " **** Output of /proc/pid/status for nginx and nginx-ingress processes ****"
13+
for p in $(pidof nginx nginx-ingress); do cat /proc/${p}/status; done

0 commit comments

Comments
 (0)