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

This commit is contained in:
Lorenz Weller 2026-04-18 07:42:00 +00:00
parent c7e04252b6
commit 30ba6c153b

View File

@ -1,47 +1,42 @@
# ==========================================
# STAGE 1: Build (Der "Werkzeugkasten")
# ==========================================
# Aufgabe 1
FROM alpine:latest AS builder
# Installiere den C-Compiler (nur für diesen Schritt!)
# C-Compiler + No-Cache
RUN apk add --no-cache build-base
# Arbeitsverzeichnis setzen
# Arbeitsverzeichnis
WORKDIR /app
# Code hineinkopieren
COPY . .
# Code kompilieren
# Kompilieren
RUN gcc -o deployment deployment.c
# ==========================================
# STAGE 2: Runtime (Das finale, kleine Image)
# ==========================================
# Runtime
FROM alpine:latest
# 1. Non-Root User anlegen (Sicherheitskriterium)
# Aufgabe 2.2.1 Non-Root User
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Arbeitsverzeichnis setzen
# Arbeitsverzeichnis
WORKDIR /app
# 2. Nur das fertige Programm aus STAGE 1 kopieren
COPY --from=builder /app/deployment .
# 3. Output-Ordner erstellen und dem neuen User die Rechte geben
# User Rechte
RUN mkdir /output && chown appuser:appgroup /output
# 4. Ab hier wird der Container als normaler User (nicht root) ausgeführt!
# Aufgabe 2.2.2 Container als normaler User
USER appuser
# 5. Datavolume deklarieren
# Aufgabe 5 Datavolume mounten
VOLUME ["/output"]
# 6. Healthcheck implementieren
# Prüft alle 30s, ob die output.txt existiert. Wenn ja -> healthy
# Aufgabe 6 Healthcheck
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD test -f /output/output.txt || exit 1
# 7. Startbefehl (identisch zur alten Version)
# Startbefehl
CMD ["sh", "-c", "./deployment 10 > /output/output.txt && tail -f /output/output.txt"]