Skip to content

Commit

Permalink
Added chart, auto-build and updated dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
InputObject2 committed May 24, 2024
1 parent dbd7d60 commit cd89b1c
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 34 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build and Push Docker Image

on:
schedule:
- cron: '0 0 * * 0' # Runs every Sunday at midnight
workflow_dispatch: # Allows manual trigger

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get latest snmpd version
id: get-version
run: |
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)
echo "latest_version=${latest_version}" >> $GITHUB_ENV
major_version=$(echo $latest_version | cut -d'.' -f1)
minor_version=$(echo $latest_version | cut -d'.' -f1-2)
echo "major_version=${major_version}" >> $GITHUB_ENV
echo "minor_version=${minor_version}" >> $GITHUB_ENV
- name: Build Docker image
run: |
docker build --build-arg SNMPD_VERSION=${{ env.latest_version }} -t ghcr.io/${{ github.repository_owner }}/snmpd:${{ env.latest_version }} .
- name: Tag Docker image
run: |
docker tag ghcr.io/${{ github.repository_owner }}/snmpd:${{ env.latest_version }} ghcr.io/${{ github.repository_owner }}/snmpd:latest
docker tag ghcr.io/${{ github.repository_owner }}/snmpd:${{ env.latest_version }} ghcr.io/${{ github.repository_owner }}/snmpd:${{ env.major_version }}
docker tag ghcr.io/${{ github.repository_owner }}/snmpd:${{ env.latest_version }} ghcr.io/${{ github.repository_owner }}/snmpd:${{ env.minor_version }}
- name: Push Docker image
run: |
docker push ghcr.io/${{ github.repository_owner }}/snmpd:${{ env.latest_version }}
docker push ghcr.io/${{ github.repository_owner }}/snmpd:latest
docker push ghcr.io/${{ github.repository_owner }}/snmpd:${{ env.major_version }}
docker push ghcr.io/${{ github.repository_owner }}/snmpd:${{ env.minor_version }}
- name: Tag the repository with the latest version
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git tag ${latest_version}
git push origin ${latest_version}
64 changes: 35 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
FROM alpine:latest

MAINTAINER Troy Kelly <troy.kelly@really.ai>

# Build-time metadata as defined at http://label-schema.org
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Docker image to provide the net-snmp daemon" \
org.label-schema.description="Provides snmpd for CoreOS and other small footprint environments without package managers" \
org.label-schema.url="https://really.ai/about/opensource" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/reallyreally/docker-snmpd" \
org.label-schema.vendor="Really Really, Inc." \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"
# Use a specific version of Debian to ensure compatibility
FROM debian:buster-slim

ARG SNMPD_VERSION=5.9.4

EXPOSE 161 161/udp

RUN apk add --update --no-cache linux-headers alpine-sdk curl findutils sed && \
mkdir -p /etc/snmp && \
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 && \
tar zxvf net-snmp.tgz && \
cd net-snmp-* && \
find . -type f -print0 | xargs -0 sed -i 's/\"\/proc/\"\/host_proc/g' && \
./configure --prefix=/usr/local --disable-ipv6 --disable-snmpv1 --with-defaults && \
make && \
make install && \
cd .. && \
rm -Rf ./net-snmp* && \
apk del linux-headers alpine-sdk curl findutils sed
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
ca-certificates \
libssl-dev \
libperl-dev \
libwrap0-dev \
libreadline-dev \
libsnmp-dev \
file

# Download and extract net-snmp
RUN mkdir -p /etc/snmp \
&& curl -L "https://sourceforge.net/projects/net-snmp/files/net-snmp/$SNMPD_VERSION/net-snmp-$SNMPD_VERSION.tar.gz/download" -o net-snmp.tgz \
&& tar zxvf net-snmp.tgz \
&& rm net-snmp.tgz

# Build and install net-snmp
RUN cd net-snmp-$SNMPD_VERSION \
&& find . -type f -print0 | xargs -0 sed -i 's/\"\/proc/\"\/host_proc/g' \
&& ./configure --prefix=/usr/local --disable-ipv6 --disable-snmpv1 --with-defaults \
&& make \
&& make install \
&& cd .. \
&& rm -rf net-snmp-$SNMPD_VERSION

# Remove build dependencies to keep the image size small
RUN apt-get purge -y --auto-remove \
build-essential \
curl

COPY snmpd.conf /etc/snmp

Expand Down
6 changes: 6 additions & 0 deletions helm/snmpd/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: snmpd
appVersion: "5.9.4"
version: "1.0.0"
type: application
description: A Helm chart for deploying snmpd as a DaemonSet
7 changes: 7 additions & 0 deletions helm/snmpd/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: snmpd-config
data:
snmpd.conf: |-
{{ .Values.config.snmpdConfig | indent 4 }}
38 changes: 38 additions & 0 deletions helm/snmpd/templates/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: snmpd-daemonset
spec:
selector:
matchLabels:
app: snmpd
template:
metadata:
labels:
app: snmpd
spec:
nodeSelector:
{{- toYaml .Values.nodeSelector | nindent 8 }}
containers:
- name: snmpd
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
{{- range .Values.ports }}
- name: {{ .name }}
containerPort: {{ .containerPort }}
hostPort: {{ .hostPort }}
protocol: {{ .protocol }}
{{- end }}
volumeMounts:
- name: snmpd-config
mountPath: /etc/snmp/snmpd.conf
subPath: snmpd.conf
securityContext:
runAsUser: 0
runAsGroup: 0
allowPrivilegeEscalation: true
volumes:
- name: snmpd-config
configMap:
name: snmpd-config
25 changes: 25 additions & 0 deletions helm/snmpd/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v1
kind: Service
metadata:
name: snmpd-service
spec:
selector:
app: snmpd
ports:
- name: snmp-tcp
port: 161
protocol: TCP
nodePort: 3161
- name: snmp-trap-tcp
port: 162
protocol: TCP
nodePort: 3162
- name: snmp-udp
port: 161
protocol: UDP
nodePort: 3161
- name: snmp-trap-udp
port: 162
protocol: UDP
nodePort: 3162
type: NodePort
36 changes: 36 additions & 0 deletions helm/snmpd/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
image:
repository: ghcr.io/inputobject2/snmpd:latest
tag: latest
pullPolicy: IfNotPresent

config:
snmpdConfig: |
# Change "public" on the line below to your preferred SNMP community string
com2sec readonly default public
group MyROGroup v2c readonly
view all included .1 80
access MyROGroup "" any noauth exact all none none
syslocation Rack, Room, Building, City, Country [GPSX,Y]
syscontact Your Name <your@email.address>
ports:
- name: snmp-tcp
containerPort: 161
hostPort: 161
protocol: TCP
- name: snmp-trap-tcp
containerPort: 162
hostPort: 162
protocol: TCP
- name: snmp-udp
containerPort: 161
hostPort: 161
protocol: UDP
- name: snmp-trap-udp
containerPort: 162
hostPort: 162
protocol: UDP

nodeSelector: {}
5 changes: 0 additions & 5 deletions hooks/build

This file was deleted.

0 comments on commit cd89b1c

Please sign in to comment.