This commit is contained in:
parent
7dac79062f
commit
1ff64cdbad
45
Dockerfile
45
Dockerfile
@ -1,22 +1,35 @@
|
|||||||
# Base-Image
|
# ── Stage 1: Build ───────────────────────────────────────────────────────────
|
||||||
FROM ubuntu:resolute-20260404
|
FROM gcc:14-bookworm AS builder
|
||||||
|
|
||||||
# Pakete installieren
|
WORKDIR /build
|
||||||
RUN apt-get update
|
COPY deployment.c .
|
||||||
RUN apt-get install -y build-essential gcc curl vim net-tools
|
|
||||||
|
|
||||||
# Arbeitsverzeichnis setzen
|
# Statisch linken → kein libc im Runtime-Image nötig
|
||||||
|
RUN gcc -O2 -static -o deployment deployment.c
|
||||||
|
|
||||||
|
# ── Stage 2: Runtime ─────────────────────────────────────────────────────────
|
||||||
|
FROM alpine:3.21
|
||||||
|
|
||||||
|
# Nicht-root-User anlegen
|
||||||
|
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||||
|
|
||||||
|
# Output-Verzeichnis mit korrekten Rechten anlegen
|
||||||
|
RUN mkdir /output && chown appuser:appgroup /output
|
||||||
|
|
||||||
|
# Kompiliertes Binary aus Build-Stage kopieren
|
||||||
|
COPY --from=builder /build/deployment /app/deployment
|
||||||
|
|
||||||
|
# Volume für Ausgabe-Dateien
|
||||||
|
VOLUME ["/output"]
|
||||||
|
|
||||||
|
# Als nicht-root laufen
|
||||||
|
USER appuser
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# alles kopieren
|
# Healthcheck: prüft ob das Binary vorhanden und ausführbar ist,
|
||||||
COPY . .
|
# und ob die Ausgabedatei wächst / existiert
|
||||||
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||||
|
CMD test -f /output/output.txt && test -s /output/output.txt || exit 1
|
||||||
|
|
||||||
# Code kompilieren
|
ENTRYPOINT ["/bin/sh", "-c"]
|
||||||
RUN gcc -o deployment deployment.c
|
|
||||||
|
|
||||||
# Verzeichnis für Ausgabe anlegen
|
|
||||||
RUN mkdir /output
|
|
||||||
|
|
||||||
# Ausgabe wird ins Container-Dateisystem geschrieben
|
|
||||||
ENTRYPOINT ["/bin/bash", "-c"]
|
|
||||||
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
||||||
Loading…
x
Reference in New Issue
Block a user