Compare commits

..

1 Commits
main ... main

Author SHA1 Message Date
1a0fcbbd12 .drone.yml aktualisiert 2026-04-11 11:45:33 +00:00
2 changed files with 35 additions and 42 deletions

View File

@ -26,7 +26,7 @@ steps:
fi fi
- name: security-scan - name: security-scan
image: aquasec/trivy:0.69.3 image: ghcr.io/aquasecurity/trivy:0.69.3
commands: commands:
- trivy image --input image.tar --severity HIGH,CRITICAL --exit-code 1 - trivy image --input image.tar --severity HIGH,CRITICAL --exit-code 1
@ -34,7 +34,7 @@ steps:
image: alpine:latest image: alpine:latest
environment: environment:
GITEA_TOKEN: GITEA_TOKEN:
from_secret: drone_token from_secret: GITEA_TOKEN
commands: commands:
- apk add --no-cache git - apk add --no-cache git
@ -42,19 +42,26 @@ steps:
- git config --global user.email "drone@ci.local" - git config --global user.email "drone@ci.local"
- git config --global user.name "Drone CI" - git config --global user.name "Drone CI"
# Das fertige Image kurz zwischenspeichern # Remote setzen
- cp image.tar /tmp/image.tar #- git remote set-url origin https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2
# Informationen holen und in den Branch wechseln # Repo clonen
- git fetch origin - git clone https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2.git
- cd EinfuehrungInDocker_Pipeline
# Branch wechseln oder erstellen
- git checkout drone-artifacts || git checkout -b drone-artifacts - git checkout drone-artifacts || git checkout -b drone-artifacts
# Das Image zurückholen # Artifact löschen und neu hinzufügen
- cp /tmp/image.tar ./image.tar - git rm image.tar
- cp $DRONE_WORKSPACE/image.tar .
# Datei committen
- git add image.tar - git add image.tar
# Commit nur wenn Änderungen vorhanden
- git commit -m "Add built Docker image [skip ci]" || echo "Nothing to commit" - git commit -m "Add built Docker image [skip ci]" || echo "Nothing to commit"
# DER FINALE TRICK: Direkt mit Username + Token an die Ziel-URL pushen # Pull vor Push (um Konflikte zu vermeiden)
- git push https://$$GITEA_TOKEN@git.efi.th-nuernberg.de/gitea/nowakke92618/EinfuehrungInDocker_Pipeline2.git drone-artifacts - git pull || true
# Push
- git push

View File

@ -1,36 +1,22 @@
# === STAGE 1: Die Bau-Umgebung (wird am Ende weggeworfen) === # Base-Image
FROM alpine:latest AS builder FROM ubuntu:latest
RUN apk add --no-cache build-base
WORKDIR /build
COPY deployment.c .
# Hier wird die fertige, ausführbare Binärdatei erzeugt
RUN gcc -o deployment deployment.c
# === STAGE 2: Die schlanke Laufzeit-Umgebung (das finale Image) === # Pakete installieren
FROM alpine:latest RUN apt-get update
RUN apt-get install -y build-essential gcc curl vim net-tools
# Arbeitsverzeichnis setzen
WORKDIR /app WORKDIR /app
# Nur das fertige C-Programm aus Stage 1 herüberkopieren (spart ~150MB!) # alles kopieren
COPY --from=builder /build/deployment . COPY . .
# Verzeichnis für die Ausgabe anlegen # Code kompilieren
RUN gcc -o deployment deployment.c
# Verzeichnis für Ausgabe anlegen
RUN mkdir /output RUN mkdir /output
# Anforderung 1: Datavolume für die Ausgabe definieren # Ausgabe wird ins Container-Dateisystem geschrieben
VOLUME /output ENTRYPOINT ["/bin/bash", "-c"]
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
# Anforderung 2 & 3: Nicht-Root-User anlegen & Schreibrechte für /output vergeben
RUN adduser -D appuser && chown -R appuser:appuser /app /output
USER appuser
# Anforderung 4: Funktionsfähiger HEALTHCHECK
# Er prüft alle 10 Sekunden, ob das Programm die Datei erfolgreich beschreibt
HEALTHCHECK --interval=10s --timeout=3s \
CMD test -f /output/output.txt || exit 1
# Da wir auf Alpine sind, nutzen wir /bin/sh (spart die Installation von bash)
ENTRYPOINT ["/bin/sh", "-c"]
# Das '&' (statt '&&') sorgt dafür, dass das C-Programm im Hintergrund startet,
# damit das 'tail -f' im Vordergrund sofort anspringt und dem User Feedback gibt!
CMD ["./deployment 10 > /output/output.txt & tail -f /output/output.txt"]