forked from freudenreichan/EinfuehrungInDocker_Pipeline2
Compare commits
No commits in common. "drone-artifacts" and "main" have entirely different histories.
drone-arti
...
main
29
.drone.yml
29
.drone.yml
@ -20,7 +20,6 @@ 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
|
||||||
@ -33,11 +32,9 @@ steps:
|
|||||||
|
|
||||||
- name: push-artifact
|
- name: push-artifact
|
||||||
image: alpine:latest
|
image: alpine:latest
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
GITEA_TOKEN:
|
GITEA_TOKEN:
|
||||||
from_secret: GITEA_TOKEN
|
from_secret: GITEA_TOKEN
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
- apk add --no-cache git
|
- apk add --no-cache git
|
||||||
|
|
||||||
@ -45,28 +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"
|
||||||
|
|
||||||
# Eigenes Repository mit Token clonen
|
# Remote setzen
|
||||||
- git clone https://oauth2:$GITEA_TOKEN@git.efi.th-nuernberg.de/gitea/spiesol91009/EinfuehrungInDocker_Pipeline2_OS.git
|
#- git remote set-url origin https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2
|
||||||
|
|
||||||
# In Repository wechseln
|
# Repo clonen
|
||||||
- cd EinfuehrungInDocker_Pipeline2_OS
|
- git clone https://git.efi.th-nuernberg.de/gitea/freudenreichan/EinfuehrungInDocker_Pipeline2.git
|
||||||
|
- 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
|
||||||
|
|
||||||
# Vorhandenes Artifact entfernen (falls vorhanden)
|
# Artifact löschen und neu hinzufügen
|
||||||
- git rm image.tar || true
|
- git rm image.tar
|
||||||
|
|
||||||
# Neues Artifact kopieren
|
|
||||||
- cp $DRONE_WORKSPACE/image.tar .
|
- cp $DRONE_WORKSPACE/image.tar .
|
||||||
|
|
||||||
# Datei hinzufügen
|
|
||||||
- git add image.tar
|
- git add image.tar
|
||||||
|
|
||||||
# Commit nur bei Änderungen
|
# 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"
|
||||||
|
|
||||||
# Branch pushen
|
# Pull vor Push (um Konflikte zu vermeiden)
|
||||||
- git push --set-upstream origin drone-artifacts
|
- git pull || true
|
||||||
|
|
||||||
|
|
||||||
|
# Push
|
||||||
|
- git push
|
||||||
36
Dockerfile
36
Dockerfile
@ -1,8 +1,9 @@
|
|||||||
# ---------- Build Stage ----------
|
# Base-Image
|
||||||
FROM alpine:latest AS build
|
FROM ubuntu:latest
|
||||||
|
|
||||||
# Pakete installieren
|
# Pakete installieren
|
||||||
RUN apk add --no-cache build-base
|
RUN apt-get update
|
||||||
|
RUN apt-get install -y build-essential gcc curl vim net-tools
|
||||||
|
|
||||||
# Arbeitsverzeichnis setzen
|
# Arbeitsverzeichnis setzen
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@ -13,30 +14,9 @@ COPY . .
|
|||||||
# Code kompilieren
|
# Code kompilieren
|
||||||
RUN gcc -o deployment deployment.c
|
RUN gcc -o deployment deployment.c
|
||||||
|
|
||||||
|
|
||||||
# ---------- Runtime Stage ----------
|
|
||||||
FROM alpine:latest
|
|
||||||
|
|
||||||
# Arbeitsverzeichnis setzen
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Benutzer ohne root-Rechte anlegen
|
|
||||||
RUN adduser -D appuser
|
|
||||||
|
|
||||||
# kompiliertes Programm kopieren
|
|
||||||
COPY --from=build /app/deployment .
|
|
||||||
|
|
||||||
# Verzeichnis für Ausgabe anlegen
|
# Verzeichnis für Ausgabe anlegen
|
||||||
RUN mkdir /output && chown appuser /output
|
RUN mkdir /output
|
||||||
|
|
||||||
# Datavolume definieren
|
# Ausgabe wird ins Container-Dateisystem geschrieben
|
||||||
VOLUME ["/output"]
|
ENTRYPOINT ["/bin/bash", "-c"]
|
||||||
|
CMD ["./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
||||||
# Benutzer wechseln
|
|
||||||
USER appuser
|
|
||||||
|
|
||||||
# HEALTHCHECK
|
|
||||||
HEALTHCHECK CMD test -f /app/deployment || exit 1
|
|
||||||
|
|
||||||
# Ausgabe wird ins Datavolume geschrieben
|
|
||||||
CMD ["sh", "-c", "./deployment 10 > /output/output.txt && tail -f /output/output.txt"]
|
|
||||||
Loading…
x
Reference in New Issue
Block a user