forked from freudenreichan/EinfuehrungInDocker_Pipeline2
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a0fcbbd12 |
29
.drone.yml
29
.drone.yml
@ -37,16 +37,31 @@ steps:
|
|||||||
from_secret: GITEA_TOKEN
|
from_secret: GITEA_TOKEN
|
||||||
commands:
|
commands:
|
||||||
- apk add --no-cache git
|
- apk add --no-cache git
|
||||||
|
|
||||||
|
# Git konfigurieren
|
||||||
- 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"
|
||||||
# Erst clonen
|
|
||||||
- git clone https://git.efi.th-nuernberg.de/gitea/niegratschkato95684/EinfuehrungInDocker_Pipeline2.git
|
# Remote setzen
|
||||||
- cd EinfuehrungInDocker_Pipeline2
|
#- git remote set-url origin https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2
|
||||||
# Dann Remote mit Token setzen (Wichtig: $$ für Drone)
|
|
||||||
- git remote set-url origin https://niegratschkato95684:$${GITEA_TOKEN}@git.efi.th-nuernberg.de/gitea/niegratschkato95684/EinfuehrungInDocker_Pipeline2.git
|
# Repo clonen
|
||||||
|
- 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
|
||||||
- git rm image.tar || echo "image.tar not found"
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# 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"
|
||||||
- git push origin drone-artifacts
|
|
||||||
|
# Pull vor Push (um Konflikte zu vermeiden)
|
||||||
|
- git pull || true
|
||||||
|
|
||||||
|
# Push
|
||||||
|
- git push
|
||||||
39
Dockerfile
39
Dockerfile
@ -1,33 +1,22 @@
|
|||||||
# Stage 1: Builder
|
# Base-Image
|
||||||
FROM alpine:3.20 AS builder
|
FROM ubuntu:latest
|
||||||
RUN apk add --no-cache build-base
|
|
||||||
WORKDIR /app
|
|
||||||
COPY deployment.c .
|
|
||||||
# Statisches Linken ist wichtig für 'scratch' oder 'alpine'
|
|
||||||
RUN gcc -O2 -static -s -o deployment deployment.c
|
|
||||||
|
|
||||||
# Stage 2: Runtime
|
# Pakete installieren
|
||||||
FROM alpine:3.20
|
RUN apt-get update
|
||||||
# 1. Non-Root User erstellen
|
RUN apt-get install -y build-essential gcc curl vim net-tools
|
||||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
|
||||||
|
|
||||||
|
# Arbeitsverzeichnis setzen
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 2. Binary kopieren
|
# alles kopieren
|
||||||
COPY --from=builder /app/deployment .
|
COPY . .
|
||||||
|
|
||||||
# 3. Verzeichnis für Volume erstellen und Berechtigungen setzen
|
# Code kompilieren
|
||||||
RUN mkdir /output && chown appuser:appgroup /output
|
RUN gcc -o deployment deployment.c
|
||||||
|
|
||||||
# 4. Zum Non-Root User wechseln
|
# Verzeichnis für Ausgabe anlegen
|
||||||
USER appuser
|
RUN mkdir /output
|
||||||
|
|
||||||
VOLUME ["/output"]
|
# Ausgabe wird ins Container-Dateisystem geschrieben
|
||||||
|
ENTRYPOINT ["/bin/bash", "-c"]
|
||||||
# Healthcheck: Prüft, ob die Datei existiert und Inhalt hat
|
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
||||||
CMD test -s /output/output.txt || exit 1
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/sh", "-c"]
|
|
||||||
# Die Anwendung schreibt in das gemountete Volume
|
|
||||||
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
||||||
Loading…
x
Reference in New Issue
Block a user