forked from freudenreichan/EinfuehrungInDocker_Pipeline2
Some checks failed
continuous-integration/drone/push Build is failing
33 lines
939 B
Docker
33 lines
939 B
Docker
# Stage 1: Builder
|
|
FROM alpine:3.20 AS builder
|
|
RUN apk add --no-cache build-base
|
|
WORKDIR /app
|
|
COPY deployment.c .
|
|
# Statisches Linken ist wichtig für 'scratch' oder 'alpine'
|
|
RUN gcc -O2 -static -s -o deployment deployment.c
|
|
|
|
# Stage 2: Runtime
|
|
FROM alpine:3.20
|
|
# 1. Non-Root User erstellen
|
|
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
|
|
|
WORKDIR /app
|
|
|
|
# 2. Binary kopieren
|
|
COPY --from=builder /app/deployment .
|
|
|
|
# 3. Verzeichnis für Volume erstellen und Berechtigungen setzen
|
|
RUN mkdir /output && chown appuser:appgroup /output
|
|
|
|
# 4. Zum Non-Root User wechseln
|
|
USER appuser
|
|
|
|
VOLUME ["/output"]
|
|
|
|
# Healthcheck: Prüft, ob die Datei existiert und Inhalt hat
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
CMD test -s /output/output.txt || exit 1
|
|
|
|
ENTRYPOINT ["/bin/sh", "-c"]
|
|
# Die Anwendung schreibt in das gemountete Volume
|
|
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"] |