Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f0077c88c1 | |||
| 68dbda9735 | |||
| b30e07243d | |||
| 79d3a4e215 | |||
| c14b87eab9 | |||
| f9d668d8db | |||
| 94e5dea293 | |||
| 9412b817db | |||
| c216710a49 | |||
| d8a7158df3 | |||
| de063f1886 | |||
| 566e564e77 | |||
| 66b927f8e0 | |||
| 4fd2f73dfe | |||
| d175700588 | |||
| 7a785a8232 | |||
| 0c6a661fb8 | |||
| d428dbab16 | |||
| 9cc4bc497e | |||
| e1f496dd3b | |||
| cb70c06352 | |||
| ff11abc459 | |||
| 81ea75e54c |
31
.drone.yml
31
.drone.yml
@ -26,7 +26,7 @@ steps:
|
||||
fi
|
||||
|
||||
- name: security-scan
|
||||
image: ghcr.io/aquasecurity/trivy:0.69.3
|
||||
image: aquasec/trivy:0.69.3
|
||||
commands:
|
||||
- trivy image --input image.tar --severity HIGH,CRITICAL --exit-code 1
|
||||
|
||||
@ -34,7 +34,7 @@ steps:
|
||||
image: alpine:latest
|
||||
environment:
|
||||
GITEA_TOKEN:
|
||||
from_secret: GITEA_TOKEN
|
||||
from_secret: drone_token
|
||||
commands:
|
||||
- apk add --no-cache git
|
||||
|
||||
@ -42,26 +42,19 @@ steps:
|
||||
- git config --global user.email "drone@ci.local"
|
||||
- git config --global user.name "Drone CI"
|
||||
|
||||
# Remote setzen
|
||||
#- git remote set-url origin https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2
|
||||
# Das fertige Image kurz zwischenspeichern
|
||||
- cp image.tar /tmp/image.tar
|
||||
|
||||
# Repo clonen
|
||||
- git clone https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2.git
|
||||
- cd EinfuehrungInDocker_Pipeline
|
||||
|
||||
# Branch wechseln oder erstellen
|
||||
# Informationen holen und in den Branch wechseln
|
||||
- git fetch origin
|
||||
- git checkout drone-artifacts || git checkout -b drone-artifacts
|
||||
|
||||
# Artifact löschen und neu hinzufügen
|
||||
- git rm image.tar
|
||||
- cp $DRONE_WORKSPACE/image.tar .
|
||||
# Das Image zurückholen
|
||||
- cp /tmp/image.tar ./image.tar
|
||||
|
||||
# Datei committen
|
||||
- git add image.tar
|
||||
|
||||
# Commit nur wenn Änderungen vorhanden
|
||||
- git commit -m "Add built Docker image [skip ci]" || echo "Nothing to commit"
|
||||
|
||||
# Pull vor Push (um Konflikte zu vermeiden)
|
||||
- git pull || true
|
||||
|
||||
# Push
|
||||
- git push
|
||||
# DER FINALE TRICK: Direkt mit Username + Token an die Ziel-URL pushen
|
||||
- git push https://$$GITEA_TOKEN@git.efi.th-nuernberg.de/gitea/nowakke92618/EinfuehrungInDocker_Pipeline2.git drone-artifacts
|
||||
50
Dockerfile
50
Dockerfile
@ -1,22 +1,36 @@
|
||||
# Base-Image
|
||||
FROM ubuntu:latest
|
||||
|
||||
# Pakete installieren
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y build-essential gcc curl vim net-tools
|
||||
|
||||
# Arbeitsverzeichnis setzen
|
||||
WORKDIR /app
|
||||
|
||||
# alles kopieren
|
||||
COPY . .
|
||||
|
||||
# Code kompilieren
|
||||
# === STAGE 1: Die Bau-Umgebung (wird am Ende weggeworfen) ===
|
||||
FROM alpine:latest AS builder
|
||||
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
|
||||
|
||||
# Verzeichnis für Ausgabe anlegen
|
||||
# === STAGE 2: Die schlanke Laufzeit-Umgebung (das finale Image) ===
|
||||
FROM alpine:latest
|
||||
WORKDIR /app
|
||||
|
||||
# Nur das fertige C-Programm aus Stage 1 herüberkopieren (spart ~150MB!)
|
||||
COPY --from=builder /build/deployment .
|
||||
|
||||
# Verzeichnis für die Ausgabe anlegen
|
||||
RUN mkdir /output
|
||||
|
||||
# Ausgabe wird ins Container-Dateisystem geschrieben
|
||||
ENTRYPOINT ["/bin/bash", "-c"]
|
||||
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
||||
# Anforderung 1: Datavolume für die Ausgabe definieren
|
||||
VOLUME /output
|
||||
|
||||
# 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"]
|
||||
Loading…
x
Reference in New Issue
Block a user