Kevin Nowak de063f1886
Some checks failed
continuous-integration/drone/push Build is failing
Dockerfile aktualisiert
2026-05-17 09:43:45 +00:00

36 lines
1.3 KiB
Docker

# === STAGE 1: Die Bau-Umgebung (wird am Ende weggeworfen) ===
FROM alpine:latest AS builder
RUN apk add --no-cache build-base
WORKDIR /build
COPY deployment.c .
# Hier wird die fertige, ausführbare Binärdatei erzeugt
RUN gcc -o deployment deployment.c
# === STAGE 2: Die schlanke Laufzeit-Umgebung (das finale Image) ===
FROM alpine:latest
WORKDIR /app
# Nur das fertige C-Programm aus Stage 1 herüberkopieren (spart ~150MB!)
COPY --from=builder /build/deployment .
# Verzeichnis für die Ausgabe anlegen
RUN mkdir /output
# Anforderung 1: Datavolume für die Ausgabe definieren
VOLUME /output
# Anforderung 2 & 3: Nicht-Root-User anlegen & Schreibrechte für /output vergeben
RUN adduser -D appuser && chown -R appuser:appuser /app /output
USER appuser
# Anforderung 4: Funktionsfähiger HEALTHCHECK
# Er prüft alle 10 Sekunden, ob das Programm die Datei erfolgreich beschreibt
HEALTHCHECK --interval=10s --timeout=3s \
CMD test -f /output/output.txt || exit 1
# Da wir auf Alpine sind, nutzen wir /bin/sh (spart die Installation von bash)
ENTRYPOINT ["/bin/sh", "-c"]
# Das '&' (statt '&&') sorgt dafür, dass das C-Programm im Hintergrund startet,
# damit das 'tail -f' im Vordergrund sofort anspringt und dem User Feedback gibt!
CMD ["./deployment 10 > /output/output.txt & tail -f /output/output.txt"]