forked from freudenreichan/EinfuehrungInDocker_Pipeline2
This commit is contained in:
parent
1a0fcbbd12
commit
1657b50ca4
12
.drone.yml
12
.drone.yml
@ -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 150 ]; then
|
||||
echo "Image too large!"
|
||||
exit 1
|
||||
fi
|
||||
@ -43,11 +43,11 @@ steps:
|
||||
- git config --global user.name "Drone CI"
|
||||
|
||||
# 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 https://git.efi.th-nuernberg.de/gitea/katzenbergeran87461/EinfuehrungInDocker_Pipeline2.git
|
||||
- cd EinfuehrungInDocker_Pipeline2
|
||||
|
||||
# Branch wechseln oder erstellen
|
||||
- git checkout drone-artifacts || git checkout -b drone-artifacts
|
||||
@ -64,4 +64,4 @@ steps:
|
||||
- git pull || true
|
||||
|
||||
# Push
|
||||
- git push
|
||||
- git push https://$GITEA_TOKEN@git.efi.th-nuernberg.de/katzenbergeran87461/EinfuehrungInDocker_Pipeline2.git
|
||||
|
||||
55
Dockerfile
55
Dockerfile
@ -1,21 +1,54 @@
|
||||
# Base-Image
|
||||
FROM ubuntu:latest
|
||||
# STAGE 1: Builder
|
||||
FROM alpine:latest AS builder
|
||||
|
||||
# Pakete installieren
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y build-essential gcc curl vim net-tools
|
||||
# Pakete installieren (gcc & Standardbibliotheken)
|
||||
RUN apk add --no-cache gcc musl-dev
|
||||
|
||||
# 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:latest
|
||||
|
||||
# Arbeitsverzeichnis setzen
|
||||
WORKDIR /app
|
||||
|
||||
# alles kopieren
|
||||
COPY . .
|
||||
|
||||
# Code kompilieren
|
||||
RUN gcc -o deployment deployment.c
|
||||
# Non-Root User anlegen
|
||||
# RUN addgroup -S appgroup
|
||||
# RUN adduser -S appuser -G appgroup
|
||||
|
||||
# Verzeichnis für Ausgabe anlegen
|
||||
RUN mkdir /output
|
||||
RUN mkdir -p /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", "/app/deployment 10 >> /output/ausgabe.log"]
|
||||
|
||||
# Ausgabe wird ins Container-Dateisystem geschrieben
|
||||
ENTRYPOINT ["/bin/bash", "-c"]
|
||||
|
||||
22
Dockerfile-alt
Normal file
22
Dockerfile-alt
Normal file
@ -0,0 +1,22 @@
|
||||
# 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