Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
114 lines (76 loc) · 3.62 KB
/
Copy pathDockerfile
File metadata and controls
114 lines (76 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# syntax=docker/dockerfile:1
# ---- Build stages: install snmpsim and its locked deps into a virtualenv ----
# Debian's own python3 is the same interpreter, at the same path
# (/usr/bin/python3), as in the distroless runtime, so the venv works there.
FROM debian:trixie-slim AS builder-base
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& apt-get install -y --no-install-recommends python3
COPY --from=ghcr.io/astral-sh/uv:0.12.5 /uv /usr/local/bin/uv
ENV UV_PYTHON=/usr/bin/python3 \
UV_PYTHON_DOWNLOADS=never \
UV_PROJECT_ENVIRONMENT=/opt/venv \
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy
WORKDIR /src
# snmpsim with SNMPv3 privacy (cryptography) and MIB compilation (pysmi)
FROM builder-base AS builder
# Dependencies first, so this layer is reused until uv.lock changes
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --locked --no-install-project --no-dev --extra full
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-editable --no-dev --extra full
# snmpsim searches <sys.prefix>/snmpsim/{data,variation} (snmpsim/confdir.py).
# sys.prefix is now the venv, so link it to /usr/local/snmpsim, the documented
# mount path.
RUN ln -s /usr/local/snmpsim /opt/venv/snmpsim
# snmpsim without extras, enough for the SNMPv1/v2c-only lite responder
FROM builder-base AS builder-lite
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --locked --no-install-project --no-dev
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-editable --no-dev
RUN ln -s /usr/local/snmpsim /opt/venv/snmpsim
# ---- runtime: shared runtime (distroless, no shell, runs as uid 65532) ----
FROM gcr.io/distroless/python3-debian13:nonroot AS runtime
LABEL maintainer="support@lextudio.com"
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# ---- base: runtime with the full virtualenv ----
FROM runtime AS base
COPY --from=builder /opt/venv /opt/venv
# ---- snmptrapd: trap/inform receiver ----
FROM base AS snmptrapd
LABEL description="PySNMP trap/inform receiver from snmpsim"
COPY docker/snmptrapd.py /opt/snmptrapd.py
EXPOSE 1162/udp
ENTRYPOINT ["/opt/venv/bin/python", "/opt/snmptrapd.py"]
# ---- snmpsim-lite: the lightweight SNMPv1/v2c simulator ----
FROM runtime AS snmpsim-lite
COPY --from=builder-lite /opt/venv /opt/venv
LABEL description="Docker image for running the lightweight snmpsim SNMPv1/v2c responder"
COPY docker/data /usr/local/snmpsim/data
EXPOSE 1161/udp
# As PID 1 an unhandled SIGTERM is ignored, see the snmpsim stage below.
STOPSIGNAL SIGINT
# Worker processes default to SNMPSIM_WORKERS, a number or "auto".
ENTRYPOINT ["/opt/venv/bin/snmpsim-command-responder-lite", "--agent-udpv4-endpoint=0.0.0.0:1161"]
# ---- snmpsim: the simulator (last, so it is the default build target) ----
FROM base AS snmpsim
LABEL description="Docker image for running snmpsim (PySNMP Simulator)"
COPY docker/data /usr/local/snmpsim/data
EXPOSE 1161/udp
# snmpsim only handles SIGTERM when daemonized, and as PID 1 an unhandled
# SIGTERM is ignored. Python turns SIGINT into KeyboardInterrupt, which
# snmpsim handles.
STOPSIGNAL SIGINT
# Extra snmpsim flags can be given as container arguments.
ENTRYPOINT ["/opt/venv/bin/snmpsim-command-responder", "--agent-udpv4-endpoint=0.0.0.0:1161"]