forked from freudenreichan/EinfuehrungInDocker_Pipeline2
This commit is contained in:
parent
4b4bcbf56e
commit
12883602f8
43
Dockerfile
43
Dockerfile
@ -1,23 +1,38 @@
|
||||
# Base-Image
|
||||
FROM alpine AS build-env
|
||||
# ── Stage 1: Build ──────────────────────────────────────────────────────────
|
||||
FROM alpine:3.19 AS builder
|
||||
|
||||
# Pakete installieren
|
||||
RUN apk add --no-cache build-base
|
||||
# Nur das nötigste zum Kompilieren
|
||||
RUN apk add --no-cache gcc musl-dev
|
||||
|
||||
|
||||
# Arbeitsverzeichnis setzen
|
||||
WORKDIR /app
|
||||
|
||||
# alles kopieren
|
||||
COPY deployment.c .
|
||||
|
||||
# Code kompilieren
|
||||
RUN gcc -o deployment deployment.c
|
||||
RUN gcc -o deployment deployment.c -static
|
||||
|
||||
# Verzeichnis für Ausgabe anlegen
|
||||
RUN mkdir /output
|
||||
# ── Stage 2: Runtime ─────────────────────────────────────────────────────────
|
||||
FROM alpine:3.19
|
||||
|
||||
# Nicht-root User anlegen
|
||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||
|
||||
# Ausgabe-Verzeichnis anlegen und Rechte setzen
|
||||
RUN mkdir /output && chown appuser:appgroup /output
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Nur das Binary aus dem Build-Stage kopieren
|
||||
COPY --from=builder /app/deployment .
|
||||
RUN chown appuser:appgroup /app/deployment
|
||||
|
||||
# Volume für die Ausgabe
|
||||
VOLUME /output
|
||||
|
||||
# Als nicht-root User laufen
|
||||
USER appuser
|
||||
|
||||
# Healthcheck: prüft ob das Binary vorhanden und ausführbar ist
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
||||
CMD test -x /app/deployment || exit 1
|
||||
|
||||
# Ausgabe wird ins Container-Dateisystem geschrieben
|
||||
ENTRYPOINT ["/app/deployment"]
|
||||
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
||||
CMD ["10"]
|
||||
Loading…
x
Reference in New Issue
Block a user