forked from freudenreichan/EinfuehrungInDocker_Pipeline2
Compare commits
No commits in common. "main" and "main" have entirely different histories.
20
.drone.yml
20
.drone.yml
@ -19,8 +19,8 @@ steps:
|
|||||||
- |
|
- |
|
||||||
SIZE=$(stat -c%s image.tar)
|
SIZE=$(stat -c%s image.tar)
|
||||||
SIZE_MB=$((SIZE / 1024 / 1024))
|
SIZE_MB=$((SIZE / 1024 / 1024))
|
||||||
echo "Image size: $${SIZE_MB}MB"
|
echo "Image size: ${SIZE_MB}MB"
|
||||||
if [ "$${SIZE_MB}" -gt 150 ]; then
|
if [ "$SIZE_MB" -gt 150 ]; then
|
||||||
echo "Image too large!"
|
echo "Image too large!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -42,20 +42,18 @@ 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"
|
||||||
|
|
||||||
# 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
|
# Remote setzen
|
||||||
#- git remote set-url origin https://git.efi.th-nuernberg.de/gitea/katzenbergeran87461/EinfuehrungInDocker_Pipeline2
|
#- git remote set-url origin https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2
|
||||||
|
|
||||||
# Repo clonen
|
# Repo clonen
|
||||||
- git clone $REPO_URL
|
- git clone https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2.git
|
||||||
- cd EinfuehrungInDocker_Pipeline2
|
- cd EinfuehrungInDocker_Pipeline
|
||||||
|
|
||||||
# Branch wechseln oder erstellen
|
# Branch wechseln oder erstellen
|
||||||
- git checkout drone-artifacts || git checkout -b drone-artifacts
|
- git checkout drone-artifacts || git checkout -b drone-artifacts
|
||||||
|
|
||||||
# Artifact ersetzen bzw. neu hinzufügen
|
# Artifact löschen und neu hinzufügen
|
||||||
|
- git rm image.tar
|
||||||
- cp $DRONE_WORKSPACE/image.tar .
|
- cp $DRONE_WORKSPACE/image.tar .
|
||||||
- git add image.tar
|
- git add image.tar
|
||||||
|
|
||||||
@ -63,7 +61,7 @@ steps:
|
|||||||
- 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"
|
||||||
|
|
||||||
# Pull vor Push (um Konflikte zu vermeiden)
|
# Pull vor Push (um Konflikte zu vermeiden)
|
||||||
- git pull $REPO_URL drone-artifacts || true
|
- git pull || true
|
||||||
|
|
||||||
# Push
|
# Push
|
||||||
- git push $REPO_URL drone-artifacts
|
- git push
|
||||||
59
Dockerfile
59
Dockerfile
@ -1,59 +1,22 @@
|
|||||||
# STAGE 1: Builder
|
# Base-Image
|
||||||
FROM alpine:3.23 AS builder
|
FROM ubuntu:latest
|
||||||
|
|
||||||
# Pakete installieren (gcc & Standardbibliotheken)
|
# Pakete installieren
|
||||||
RUN apk add --no-cache gcc musl-dev
|
RUN apt-get update
|
||||||
|
RUN apt-get install -y build-essential gcc curl vim net-tools
|
||||||
# Arbeitsverzeichnis für den Build-Prozess
|
|
||||||
WORKDIR /build
|
|
||||||
|
|
||||||
# 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
|
# Arbeitsverzeichnis setzen
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# OPTIMIERUNG: System-Update durchführen, um CVEs zu fixen
|
# alles kopieren
|
||||||
# 'apk upgrade' installiert die Version 3.3.7-r0 von OpenSSL
|
COPY . .
|
||||||
RUN apk update && apk upgrade --no-cache
|
|
||||||
|
|
||||||
# Non-Root User anlegen
|
# Code kompilieren
|
||||||
# RUN addgroup -S appgroup
|
RUN gcc -o deployment deployment.c
|
||||||
# RUN adduser -S appuser -G appgroup
|
|
||||||
|
|
||||||
# Verzeichnis für Ausgabe anlegen
|
# Verzeichnis für Ausgabe anlegen
|
||||||
RUN mkdir -p /output
|
RUN mkdir /output
|
||||||
|
|
||||||
# Dem User die Rechte für die Ordner /app und /output geben
|
|
||||||
# RUN chown -R appuser:appgroup /app /output
|
|
||||||
|
|
||||||
# nur die fertige Binärdatei aus der "builder"-Stage kopieren
|
|
||||||
COPY --from=builder /build/deployment /app/
|
|
||||||
# COPY --from=builder --chown=appuser:appgroup /build/deployment /app/
|
|
||||||
|
|
||||||
# 3. Data Volume für die Ausgabe mounten
|
|
||||||
VOLUME ["/output"]
|
|
||||||
|
|
||||||
# 4. Ab hier läuft alles als sicherer Non-Root User
|
|
||||||
# USER appuser
|
|
||||||
|
|
||||||
# 5. Healthcheck implementieren
|
|
||||||
# Da das C-Programm alle 10 Sekunden etwas schreibt, prüfen wir alle 15 Sekunden,
|
|
||||||
# ob die Datei "/output/ausgabe.log" existiert und Daten enthält (-s).
|
|
||||||
# HEALTHCHECK --interval=15s --timeout=3s --start-period=5s --retries=3 \
|
|
||||||
# CMD test -s /output/ausgabe.log || exit 1
|
|
||||||
|
|
||||||
# 6. Startbefehl
|
|
||||||
# Wir starten das Programm (Intervall: 10 Sekunden) und hängen die Ausgabe (>>) an die Datei im Volume an.
|
|
||||||
# (Dein C-Code nutzt netterweise schon fflush(stdout), was perfekt für diese Umleitung ist!)
|
|
||||||
# CMD ["sh", "-c", "./deployment 10 >> /output/ausgabe.log && tail -f /output/ausgabe.log"]
|
|
||||||
|
|
||||||
# Ausgabe wird ins Container-Dateisystem geschrieben
|
# Ausgabe wird ins Container-Dateisystem geschrieben
|
||||||
ENTRYPOINT ["/bin/sh", "-c"]
|
ENTRYPOINT ["/bin/bash", "-c"]
|
||||||
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
||||||
@ -1,22 +0,0 @@
|
|||||||
# 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
|
|
||||||
RUN gcc -o deployment deployment.c
|
|
||||||
|
|
||||||
# Verzeichnis für 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"]
|
|
||||||
Loading…
x
Reference in New Issue
Block a user