Files
surveybox/Dockerfile
T
marco.morath 6c5175d2f1
CI / audit (push) Skipped
CI / checks (push) Successful in 4m3s
CI / image (push) Successful in 1m11s
v1.0.0
2026-11-26 10:44:32 +01:00

91 lines
3.6 KiB
Docker

# syntax=docker/dockerfile:1
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# Ein Image für Web und Worker. Läuft ohne Root und mit schreibgeschütztem
# Dateisystem; beschreibbar sind nur /data (Volume) und /tmp (tmpfs).
ARG PYTHON_VERSION=3.13
ARG DEBIAN_SUITE=trixie
# ---------------------------------------------------------------------------
# Bauen: Abhängigkeiten aus der Lock-Datei (nur mit passenden Hashes)
# ---------------------------------------------------------------------------
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_SUITE} AS build
ENV PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /build
COPY requirements.lock ./
RUN python -m venv /opt/venv \
&& /opt/venv/bin/pip install --require-hashes --no-deps --only-binary=:all: -r requirements.lock \
&& /opt/venv/bin/python -m pip uninstall -y pip
COPY surveybox ./surveybox
RUN /opt/venv/bin/pybabel compile --statistics -D messages -d surveybox/locale \
&& /opt/venv/bin/python -m compileall -q surveybox
# ---------------------------------------------------------------------------
# Laufzeit
# ---------------------------------------------------------------------------
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_SUITE} AS runtime
ARG DEBIAN_SUITE
# PostgreSQL-Client-Werkzeuge für die Sicherung. Mehrere Hauptversionen,
# damit zu jedem unterstützten Server ein passendes pg_dump vorhanden ist.
ARG PG_CLIENT_VERSIONS="17 18 19"
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends ca-certificates curl gnupg; \
install -d /usr/share/postgresql-common/pgdg; \
curl -fsSL -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc \
https://www.postgresql.org/media/keys/ACCC4CF8.asc; \
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt ${DEBIAN_SUITE}-pgdg main" \
> /etc/apt/sources.list.d/pgdg.list; \
apt-get update; \
# Sicherheitsupdates, die im Basis-Image noch fehlen
apt-get upgrade -y --no-install-recommends; \
pkgs=""; for v in ${PG_CLIENT_VERSIONS}; do pkgs="$pkgs postgresql-client-$v"; done; \
apt-get install -y --no-install-recommends $pkgs; \
apt-get purge -y --auto-remove curl gnupg; \
rm -rf /var/lib/apt/lists/*
# pip wird zur Laufzeit nicht gebraucht; seine mitgelieferten Bibliotheken
# (urllib3, msgpack, setuptools) würden sonst als Lücken im Image auftauchen.
RUN python -m pip uninstall -y pip \
&& rm -rf /usr/local/lib/python3.*/ensurepip
RUN groupadd --system --gid 10001 surveybox \
&& useradd --system --uid 10001 --gid surveybox --home-dir /nonexistent \
--no-create-home --shell /usr/sbin/nologin surveybox \
&& install -d -o surveybox -g surveybox -m 0750 /data /data/backups
COPY --from=build /opt/venv /opt/venv
COPY --from=build /build/surveybox /app/surveybox
# Hilfe in der Anwendung (/help): Dokumentation der laufenden Version
COPY docs /app/docs
COPY CHANGELOG.md /app/CHANGELOG.md
ENV PATH=/opt/venv/bin:$PATH \
PYTHONPATH=/app \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
SURVEYBOX_DATA_DIR=/data
WORKDIR /app
USER surveybox:surveybox
VOLUME ["/data"]
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=10s --start-period=300s --retries=3 \
CMD ["python", "-m", "surveybox.cli", "healthcheck"]
ENTRYPOINT ["python", "-m", "surveybox.cli"]
CMD ["web"]
LABEL org.opencontainers.image.title="Surveybox" \
org.opencontainers.image.version="1.0.0" \
org.opencontainers.image.description="Formulare und Abstimmungen, selbst gehostet" \
org.opencontainers.image.licenses="AGPL-3.0-or-later"