Dockerfile aktualisiert
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Tobias Niegratschka 2026-05-05 07:51:30 +00:00
parent fd5c8099ef
commit 76dfa617d2

View File

@ -1,40 +1,33 @@
# syntax=docker/dockerfile:1 # Stage 1: Builder
############################
# 1) Builder: compilen
############################
FROM alpine:3.20 AS builder FROM alpine:3.20 AS builder
WORKDIR /app
# Build-Tools nur im Builder
RUN apk add --no-cache build-base RUN apk add --no-cache build-base
WORKDIR /app
# Nur die C-Datei kopieren
COPY deployment.c . COPY deployment.c .
# Statisches Linken ist wichtig für 'scratch' oder 'alpine'
# Kompilieren (statisch linken)
RUN gcc -O2 -static -s -o deployment deployment.c RUN gcc -O2 -static -s -o deployment deployment.c
############################ # Stage 2: Runtime
# 2) Runtime: Minimaler Footprint
############################
FROM alpine:3.20 FROM alpine:3.20
# 1. Non-Root User erstellen
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app WORKDIR /app
# Binary vom Builder kopieren # 2. Binary kopieren
COPY --from=builder /app/deployment . COPY --from=builder /app/deployment .
# Verzeichnis für das Volume erstellen # 3. Verzeichnis für Volume erstellen und Berechtigungen setzen
RUN mkdir /output RUN mkdir /output && chown appuser:appgroup /output
# 4. Zum Non-Root User wechseln
USER appuser
# Datavolume mounten (leitet die Ausgabe nach außen)
VOLUME ["/output"] VOLUME ["/output"]
# Healthcheck: Prüft, ob die Datei existiert und nicht leer ist # Healthcheck: Prüft, ob die Datei existiert und Inhalt hat
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD test -s /output/output.txt || exit 1 CMD test -s /output/output.txt || exit 1
ENTRYPOINT ["/bin/sh", "-c"] ENTRYPOINT ["/bin/sh", "-c"]
# Die Anwendung schreibt in das gemountete Volume
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"] CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]