Update Dockerfile
This commit is contained in:
parent
34728990c3
commit
e7304fab26
48
Dockerfile
48
Dockerfile
@ -1,27 +1,45 @@
|
|||||||
# Base-Image
|
# ---- Build-Stage ----
|
||||||
FROM alpine AS build-env
|
FROM alpine:3.20 AS build-env
|
||||||
|
|
||||||
# Pakete installieren
|
# Build-Abhängigkeiten installieren (nur für die Build-Stage)
|
||||||
RUN apt-get update
|
RUN apk add --no-cache \
|
||||||
RUN apt-get install -y build-essential gcc curl vim net-tools
|
build-base \
|
||||||
|
gcc \
|
||||||
|
curl
|
||||||
|
|
||||||
# Arbeitsverzeichnis setzen
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# alles kopieren
|
# Quellcode kopieren
|
||||||
COPY . .
|
COPY deployment.c .
|
||||||
|
|
||||||
# Code kompilieren
|
# Programm kompilieren (statisch linken für bessere Portabilität)
|
||||||
RUN gcc -o deployment deployment.c
|
RUN gcc -static -o deployment deployment.c
|
||||||
|
|
||||||
# Verzeichnis für Ausgabe anlegen
|
# ---- Finale Stage ----
|
||||||
RUN mkdir /output
|
FROM alpine:3.20
|
||||||
|
|
||||||
|
# Kein root User - eigenen User erstellen
|
||||||
|
RUN addgroup -g 1000 -S appgroup && \
|
||||||
|
adduser -u 1000 -S appuser -G appgroup
|
||||||
|
|
||||||
|
# Nur notwendige Pakete installieren (curl für healthcheck, net-tools nicht nötig)
|
||||||
|
RUN apk add --no-cache curl
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Programm aus Build-Stage kopieren
|
||||||
|
COPY --from=build-env --chown=appuser:appgroup /app/deployment /app/deployment
|
||||||
|
|
||||||
|
# Ausgabeverzeichnis mit korrekten Berechtigungen
|
||||||
|
RUN mkdir -p /output && chown -R appuser:appgroup /output
|
||||||
|
|
||||||
|
# Zu nicht-root Benutzer wechseln
|
||||||
USER appuser
|
USER appuser
|
||||||
|
|
||||||
|
# Healthcheck alle 30 Sekunden
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||||
CMD curl -f http://localhost:8080/health || exit 1
|
CMD curl -f http://localhost:8080/health || exit 1
|
||||||
|
|
||||||
# Ausgabe wird ins Container-Dateisystem geschrieben
|
# Programm ausführen (ohne Bash, direkt)
|
||||||
ENTRYPOINT ["/bin/bash", "-c"]
|
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