Skip to content

Commit 9e65403

Browse files
committed
Added chart, auto-build and updated dockerfile
1 parent dbd7d60 commit 9e65403

File tree

7 files changed

+198
-34
lines changed

7 files changed

+198
-34
lines changed

.github/workflows/build-and-push.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 0' # Runs every Sunday at midnight
6+
workflow_dispatch: # Allows manual trigger
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v2
15+
16+
- name: Set up QEMU
17+
uses: docker/setup-qemu-action@v2
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v2
21+
22+
- name: Login to GitHub Container Registry
23+
uses: docker/login-action@v2
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.repository_owner }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Get latest snmpd version
30+
id: get-version
31+
run: |
32+
latest_version=$(curl -s "https://sourceforge.net/projects/net-snmp/files/net-snmp/" | grep -Po 'href="\/projects\/net-snmp\/files\/net-snmp\/\K[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -1)
33+
echo "latest_version=${latest_version}" >> $GITHUB_ENV
34+
major_version=$(echo $latest_version | cut -d'.' -f1)
35+
minor_version=$(echo $latest_version | cut -d'.' -f1-2)
36+
echo "major_version=${major_version}" >> $GITHUB_ENV
37+
echo "minor_version=${minor_version}" >> $GITHUB_ENV
38+
39+
- name: Build Docker image
40+
run: |
41+
repo_name=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
42+
docker build --build-arg SNMPD_VERSION=${{ env.latest_version }} -t ghcr.io/$repo_name/snmpd:${{ env.latest_version }} .
43+
44+
- name: Tag Docker image
45+
run: |
46+
repo_name=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
47+
docker tag ghcr.io/$repo_name/snmpd:${{ env.latest_version }} ghcr.io/$repo_name/snmpd:latest
48+
docker tag ghcr.io/$repo_name/snmpd:${{ env.latest_version }} ghcr.io/$repo_name/snmpd:${{ env.major_version }}
49+
docker tag ghcr.io/$repo_name/snmpd:${{ env.latest_version }} ghcr.io/$repo_name/snmpd:${{ env.minor_version }}
50+
51+
- name: Push Docker image
52+
run: |
53+
repo_name=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
54+
docker push ghcr.io/$repo_name/snmpd:${{ env.latest_version }}
55+
docker push ghcr.io/$repo_name/snmpd:latest
56+
docker push ghcr.io/$repo_name/snmpd:${{ env.major_version }}
57+
docker push ghcr.io/$repo_name/snmpd:${{ env.minor_version }}
58+
59+
- name: Tag the repository with the latest version
60+
run: |
61+
git config --global user.name "github-actions[bot]"
62+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
63+
git tag ${latest_version}
64+
git push origin ${latest_version}

Dockerfile

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
1-
FROM alpine:latest
2-
3-
MAINTAINER Troy Kelly <troy.kelly@really.ai>
4-
5-
# Build-time metadata as defined at http://label-schema.org
6-
ARG BUILD_DATE
7-
ARG VCS_REF
8-
ARG VERSION
9-
LABEL org.label-schema.build-date=$BUILD_DATE \
10-
org.label-schema.name="Docker image to provide the net-snmp daemon" \
11-
org.label-schema.description="Provides snmpd for CoreOS and other small footprint environments without package managers" \
12-
org.label-schema.url="https://really.ai/about/opensource" \
13-
org.label-schema.vcs-ref=$VCS_REF \
14-
org.label-schema.vcs-url="https://github.com/reallyreally/docker-snmpd" \
15-
org.label-schema.vendor="Really Really, Inc." \
16-
org.label-schema.version=$VERSION \
17-
org.label-schema.schema-version="1.0"
1+
# Use a specific version of Debian to ensure compatibility
2+
FROM debian:buster-slim
3+
4+
ARG SNMPD_VERSION=5.9.4
185

196
EXPOSE 161 161/udp
207

21-
RUN apk add --update --no-cache linux-headers alpine-sdk curl findutils sed && \
22-
mkdir -p /etc/snmp && \
23-
curl -L "https://sourceforge.net/projects/net-snmp/files/5.4.5-pre-releases/net-snmp-5.4.5.rc1.tar.gz/download" -o net-snmp.tgz && \
24-
tar zxvf net-snmp.tgz && \
25-
cd net-snmp-* && \
26-
find . -type f -print0 | xargs -0 sed -i 's/\"\/proc/\"\/host_proc/g' && \
27-
./configure --prefix=/usr/local --disable-ipv6 --disable-snmpv1 --with-defaults && \
28-
make && \
29-
make install && \
30-
cd .. && \
31-
rm -Rf ./net-snmp* && \
32-
apk del linux-headers alpine-sdk curl findutils sed
8+
# Install build dependencies
9+
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
build-essential \
11+
curl \
12+
ca-certificates \
13+
libssl-dev \
14+
libperl-dev \
15+
libwrap0-dev \
16+
libreadline-dev \
17+
libsnmp-dev \
18+
file
19+
20+
# Download and extract net-snmp
21+
RUN mkdir -p /etc/snmp \
22+
&& curl -L "https://sourceforge.net/projects/net-snmp/files/net-snmp/$SNMPD_VERSION/net-snmp-$SNMPD_VERSION.tar.gz/download" -o net-snmp.tgz \
23+
&& tar zxvf net-snmp.tgz \
24+
&& rm net-snmp.tgz
25+
26+
# Build and install net-snmp
27+
RUN cd net-snmp-$SNMPD_VERSION \
28+
&& find . -type f -print0 | xargs -0 sed -i 's/\"\/proc/\"\/host_proc/g' \
29+
&& ./configure --prefix=/usr/local --disable-ipv6 --disable-snmpv1 --with-defaults \
30+
&& make \
31+
&& make install \
32+
&& cd .. \
33+
&& rm -rf net-snmp-$SNMPD_VERSION
34+
35+
# Remove build dependencies to keep the image size small
36+
RUN apt-get purge -y --auto-remove \
37+
build-essential \
38+
curl
3339

3440
COPY snmpd.conf /etc/snmp
3541

helm/snmpd/Chart.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: snmpd
3+
appVersion: "5.9.4"
4+
version: "1.0.0"
5+
type: application
6+
description: A Helm chart for deploying snmpd as a DaemonSet

helm/snmpd/templates/configmap.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ .Chart.Name }}-config
5+
data:
6+
snmpd.conf: |-
7+
{{ .Values.config.snmpdConfig | indent 4 }}

helm/snmpd/templates/daemonset.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: {{ .Chart.Name }}
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: snmpd
9+
template:
10+
metadata:
11+
labels:
12+
app: snmpd
13+
annotations:
14+
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
15+
spec:
16+
hostNetwork: true
17+
nodeSelector:
18+
{{- toYaml .Values.nodeSelector | nindent 8 }}
19+
containers:
20+
- name: snmpd
21+
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
22+
imagePullPolicy: {{ .Values.image.pullPolicy }}
23+
ports:
24+
{{- range .Values.ports }}
25+
- name: {{ .name }}
26+
containerPort: {{ .containerPort }}
27+
hostPort: {{ .hostPort }}
28+
protocol: {{ .protocol }}
29+
{{- end }}
30+
volumeMounts:
31+
- name: snmpd-config
32+
mountPath: /etc/snmp/snmpd.conf
33+
subPath: snmpd.conf
34+
- name: host-proc
35+
mountPath: /host_proc
36+
securityContext:
37+
runAsUser: 0
38+
runAsGroup: 0
39+
allowPrivilegeEscalation: true
40+
volumes:
41+
- name: snmpd-config
42+
configMap:
43+
name: {{ .Chart.Name }}-config
44+
- name: host-proc
45+
hostPath:
46+
path: /proc

helm/snmpd/values.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
image:
2+
repository: ghcr.io/inputobject2/snmpd
3+
tag: 5.9.4
4+
pullPolicy: IfNotPresent
5+
6+
config:
7+
snmpdConfig: |
8+
# Change "public" on the line below to your preferred SNMP community string
9+
com2sec readonly default public
10+
11+
group MyROGroup v2c readonly
12+
view all included .1 80
13+
access MyROGroup "" any noauth exact all none none
14+
15+
syslocation Rack, Room, Building, City, Country [GPSX,Y]
16+
syscontact support@example.com
17+
18+
# Load MIB modules
19+
mibs +HOST-RESOURCES-MIB
20+
mibs +UCD-SNMP-MIB
21+
22+
ports:
23+
- name: snmp-tcp
24+
containerPort: 161
25+
hostPort: 161
26+
protocol: TCP
27+
- name: snmp-trap-tcp
28+
containerPort: 162
29+
hostPort: 162
30+
protocol: TCP
31+
- name: snmp-udp
32+
containerPort: 161
33+
hostPort: 161
34+
protocol: UDP
35+
- name: snmp-trap-udp
36+
containerPort: 162
37+
hostPort: 162
38+
protocol: UDP
39+
40+
nodeSelector: {}

hooks/build

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)