Skip to content

Commit a049dbd

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

File tree

8 files changed

+211
-34
lines changed

8 files changed

+211
-34
lines changed

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

+64
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

+35-29
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

+6
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

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

helm/snmpd/templates/daemonset.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: snmpd-daemonset
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: snmpd
9+
template:
10+
metadata:
11+
labels:
12+
app: snmpd
13+
spec:
14+
nodeSelector:
15+
{{- toYaml .Values.nodeSelector | nindent 8 }}
16+
containers:
17+
- name: snmpd
18+
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
19+
imagePullPolicy: {{ .Values.image.pullPolicy }}
20+
ports:
21+
{{- range .Values.ports }}
22+
- name: {{ .name }}
23+
containerPort: {{ .containerPort }}
24+
hostPort: {{ .hostPort }}
25+
protocol: {{ .protocol }}
26+
{{- end }}
27+
volumeMounts:
28+
- name: snmpd-config
29+
mountPath: /etc/snmp/snmpd.conf
30+
subPath: snmpd.conf
31+
securityContext:
32+
runAsUser: 0
33+
runAsGroup: 0
34+
allowPrivilegeEscalation: true
35+
volumes:
36+
- name: snmpd-config
37+
configMap:
38+
name: snmpd-config

helm/snmpd/templates/service.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: snmpd-service
5+
spec:
6+
selector:
7+
app: snmpd
8+
ports:
9+
- name: snmp-tcp
10+
port: 161
11+
protocol: TCP
12+
nodePort: 3161
13+
- name: snmp-trap-tcp
14+
port: 162
15+
protocol: TCP
16+
nodePort: 3162
17+
- name: snmp-udp
18+
port: 161
19+
protocol: UDP
20+
nodePort: 3161
21+
- name: snmp-trap-udp
22+
port: 162
23+
protocol: UDP
24+
nodePort: 3162
25+
type: NodePort

helm/snmpd/values.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
image:
2+
repository: ghcr.io/inputobject2/snmpd:latest
3+
tag: latest
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 Your Name <your@email.address>
17+
18+
ports:
19+
- name: snmp-tcp
20+
containerPort: 161
21+
hostPort: 161
22+
protocol: TCP
23+
- name: snmp-trap-tcp
24+
containerPort: 162
25+
hostPort: 162
26+
protocol: TCP
27+
- name: snmp-udp
28+
containerPort: 161
29+
hostPort: 161
30+
protocol: UDP
31+
- name: snmp-trap-udp
32+
containerPort: 162
33+
hostPort: 162
34+
protocol: UDP
35+
36+
nodeSelector: {}

hooks/build

-5
This file was deleted.

0 commit comments

Comments
 (0)