Compare commits

...

7 Commits

2 changed files with 61 additions and 9 deletions

View File

@ -19,8 +19,8 @@ steps:
- |
SIZE=$(stat -c%s image.tar)
SIZE_MB=$((SIZE / 1024 / 1024))
echo "Image size: ${SIZE_MB}MB"
if [ "$SIZE_MB" -gt 150 ]; then
echo "Image size: $${SIZE_MB}MB"
if [ "$${SIZE_MB}" -gt 1500 ]; then
echo "Image too large!"
exit 1
fi
@ -42,18 +42,20 @@ steps:
- git config --global user.email "drone@ci.local"
- git config --global user.name "Drone CI"
# Variable für die URL mit Token definieren (erleichtert Wartung)
- export REPO_URL="https://oauth2:$$GITEA_TOKEN@git.efi.th-nuernberg.de/gitea/katzenbergeran87461/EinfuehrungInDocker_Pipeline2.git"
# Remote setzen
#- git remote set-url origin https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2
#- git remote set-url origin https://git.efi.th-nuernberg.de/gitea/katzenbergeran87461/EinfuehrungInDocker_Pipeline2
# Repo clonen
- git clone https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2.git
- cd EinfuehrungInDocker_Pipeline
- git clone $REPO_URL
- cd EinfuehrungInDocker_Pipeline2
# Branch wechseln oder erstellen
- git checkout drone-artifacts || git checkout -b drone-artifacts
# Artifact löschen und neu hinzufügen
- git rm image.tar
# Artifact ersetzen bzw. neu hinzufügen
- cp $DRONE_WORKSPACE/image.tar .
- git add image.tar
@ -61,7 +63,7 @@ steps:
- git commit -m "Add built Docker image [skip ci]" || echo "Nothing to commit"
# Pull vor Push (um Konflikte zu vermeiden)
- git pull || true
- git pull $REPO_URL drone-artifacts || true
# Push
- git push
- git push $REPO_URL drone-artifacts

50
Dockerfile-neu Normal file
View File

@ -0,0 +1,50 @@
# STAGE 1: Builder
FROM alpine:3.23 AS builder
# Pakete installieren (gcc & Standardbibliotheken)
RUN apk add --no-cache gcc musl-dev
# Arbeitsverzeichnis für den Build-Prozess
WORKDIR /build
# nur C-Code kopieren
COPY deployment.c .
# Code kompilieren (-O2 optimiert die Performance der Binärdatei)
RUN gcc -O2 -o deployment deployment.c
# STAGE 2: Runner
FROM alpine:3.23
# Arbeitsverzeichnis setzen
WORKDIR /app
# OPTIMIERUNG: System-Update durchführen, um CVEs zu fixen
# 'apk upgrade' installiert die Version 3.3.7-r0 von OpenSSL
# Non-Root User anlegen
# Verzeichnis für Ausgabe anlegen
# Dem User die Rechte für die Ordner /app und /output geben
RUN apk update && apk upgrade --no-cache && \
addgroup -S -g 1000 appgroup && \
adduser -S -u 1000 -G appgroup appuser && \
mkdir -p /output && \
chown -R 1000:1000 /app /output
# nur die fertige Binärdatei aus der "builder"-Stage kopieren
COPY --from=builder --chown=1000:1000 /build/deployment /app/
# 3. Ab hier läuft alles als sicherer Non-Root User
USER 1000
# 4. Data Volume für die Ausgabe mounten (um lokal die output.txt zu sehen)
VOLUME ["/output"]
# 5. Healthcheck
# Da das C-Programm alle 10 Sekunden etwas schreibt, prüfen wir alle 15 Sekunden,
# ob die Datei "/output/output.txt" existiert und Daten enthält (-s).
HEALTHCHECK --interval=15s --timeout=3s --start-period=5s --retries=3 \
CMD test -s /output/output.txt || exit 1
# 6. Startbefehl
ENTRYPOINT ["/bin/sh", "-c"]
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]