forked from freudenreichan/EinfuehrungInDocker_Pipeline2
This commit is contained in:
parent
4b4bcbf56e
commit
12883602f8
43
Dockerfile
43
Dockerfile
@ -1,23 +1,38 @@
|
|||||||
# Base-Image
|
# ── Stage 1: Build ──────────────────────────────────────────────────────────
|
||||||
FROM alpine AS build-env
|
FROM alpine:3.19 AS builder
|
||||||
|
|
||||||
# Pakete installieren
|
# Nur das nötigste zum Kompilieren
|
||||||
RUN apk add --no-cache build-base
|
RUN apk add --no-cache gcc musl-dev
|
||||||
|
|
||||||
|
|
||||||
# Arbeitsverzeichnis setzen
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# alles kopieren
|
|
||||||
COPY deployment.c .
|
COPY deployment.c .
|
||||||
|
|
||||||
# Code kompilieren
|
RUN gcc -o deployment deployment.c -static
|
||||||
RUN gcc -o deployment deployment.c
|
|
||||||
|
|
||||||
# Verzeichnis für Ausgabe anlegen
|
# ── Stage 2: Runtime ─────────────────────────────────────────────────────────
|
||||||
RUN mkdir /output
|
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"]
|
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