This commit is contained in:
@@ -168,26 +168,36 @@ jobs:
|
|||||||
id: update_doc
|
id: update_doc
|
||||||
if: steps.check_changes.outputs.should_build == 'true'
|
if: steps.check_changes.outputs.should_build == 'true'
|
||||||
run: |
|
run: |
|
||||||
|
set -x # Aktiviert Debug-Modus, um den Fehler genau zu sehen
|
||||||
|
|
||||||
# --- 1. VARIABLEN VORBEREITEN ---
|
# --- 1. VARIABLEN VORBEREITEN ---
|
||||||
export TZ=Europe/Berlin
|
export TZ=Europe/Berlin
|
||||||
CURRENT_TIME=$(date '+%d.%m.%Y %H:%M')
|
CURRENT_TIME=$(date '+%d.%m.%Y %H:%M')
|
||||||
BUILD_TAG=${{ steps.prep.outputs.docker_tag }}
|
BUILD_TAG="${{ steps.prep.outputs.docker_tag }}"
|
||||||
FULL_URL=${{ steps.prep.outputs.image_name }}
|
FULL_URL="${{ steps.prep.outputs.image_name }}"
|
||||||
REPO_PURE=${{ steps.prep.outputs.repo_pure }}
|
REPO_PURE="${{ steps.prep.outputs.repo_pure }}"
|
||||||
BASE_IMAGE=${{ steps.prep.outputs.base_image }}
|
BASE_IMAGE="${{ steps.prep.outputs.base_image }}"
|
||||||
|
|
||||||
# Umgebungsvariablen laden
|
# Sicherstellen, dass buildargs.env da ist
|
||||||
|
if [ ! -f "buildargs.env" ]; then echo "❌ buildargs.env fehlt!"; exit 1; fi
|
||||||
|
|
||||||
|
# Env sauber laden (ohne Subshell-Source)
|
||||||
|
grep -v '^#' buildargs.env | sed 's/\r$//' > cleaned_env.sh
|
||||||
set -a
|
set -a
|
||||||
source <(grep -v '^#' buildargs.env | sed 's/\r$//')
|
source ./cleaned_env.sh
|
||||||
set +a
|
set +a
|
||||||
|
|
||||||
if [ -f "Dockerfile.aarch64" ]; then ARM_STATUS="✅ Aktiv (eigenes Dockerfile)"; else ARM_STATUS="❌ Nicht unterstützt"; fi
|
if [ -f "Dockerfile.aarch64" ]; then ARM_STATUS="✅ Aktiv (eigenes Dockerfile)"; else ARM_STATUS="❌ Nicht unterstützt"; fi
|
||||||
COMMIT_MSG=$(echo "${{ github.event.head_commit.message }}" | sed 's/\[skip ci\]//g' | xargs)
|
|
||||||
|
# COMMIT_MSG sicher abfangen (verhindert Fehler durch Sonderzeichen)
|
||||||
|
cat << 'EOF' > commit_msg.txt
|
||||||
|
${{ gitea.event.head_commit.message }}
|
||||||
|
EOF
|
||||||
|
COMMIT_MSG=$(sed 's/\[skip ci\]//g' commit_msg.txt | xargs)
|
||||||
|
|
||||||
# --- 2. TEMPLATES LADEN ---
|
# --- 2. TEMPLATES LADEN ---
|
||||||
# || true verhindert Abbruch, falls Datei fehlt (sollte aber nicht passieren)
|
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/README.template -O README.template || echo "Templates konnten nicht geladen werden"
|
||||||
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/README.template -O README.template || echo "Warnung: README.template nicht geladen"
|
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/docker-compose.template -O docker-compose.template || echo "Templates konnten nicht geladen werden"
|
||||||
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/docker-compose.template -O docker-compose.template || echo "Warnung: docker-compose.template nicht geladen"
|
|
||||||
|
|
||||||
# --- 3. VERSION HISTORY UPDATE ---
|
# --- 3. VERSION HISTORY UPDATE ---
|
||||||
NEW_ROW="| **$BUILD_TAG** | $CURRENT_TIME | $COMMIT_MSG ✅ |"
|
NEW_ROW="| **$BUILD_TAG** | $CURRENT_TIME | $COMMIT_MSG ✅ |"
|
||||||
@@ -202,96 +212,95 @@ jobs:
|
|||||||
HISTORY_CONTENT=$(cat VERSION.history)
|
HISTORY_CONTENT=$(cat VERSION.history)
|
||||||
|
|
||||||
# --- 4. ENV / PORTS / VOL BLÖCKE GENERIEREN ---
|
# --- 4. ENV / PORTS / VOL BLÖCKE GENERIEREN ---
|
||||||
# WICHTIG: "|| true" am Ende der greps verhindert exit code 1 bei leeren Ergebnissen
|
|
||||||
ENV_BLOCK_CONTENT=""
|
ENV_BLOCK_CONTENT=""
|
||||||
env_vars=$(grep '^ENV_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
env_vars=$(grep '^ENV_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||||
if [ ! -z "$env_vars" ]; then
|
if [ -n "$env_vars" ]; then
|
||||||
ENV_BLOCK_CONTENT=" environment:\n"
|
ENV_BLOCK_CONTENT=" environment:\n"
|
||||||
for line in $env_vars; do
|
while read -r line; do
|
||||||
key=$(echo $line | cut -d= -f1); val=$(echo $line | cut -d= -f2-); clean_key=${key#ENV_}
|
[ -z "$line" ] && continue
|
||||||
|
key=$(echo "$line" | cut -d= -f1); val=$(echo "$line" | cut -d= -f2-); clean_key=${key#ENV_}
|
||||||
ENV_BLOCK_CONTENT="${ENV_BLOCK_CONTENT} - ${clean_key}=${val}\n"
|
ENV_BLOCK_CONTENT="${ENV_BLOCK_CONTENT} - ${clean_key}=${val}\n"
|
||||||
done
|
done <<< "$env_vars"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PORTS_BLOCK_CONTENT=""
|
PORTS_BLOCK_CONTENT=""
|
||||||
port_vars=$(grep '^PORT_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
port_vars=$(grep '^PORT_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||||
if [ ! -z "$port_vars" ]; then
|
if [ -n "$port_vars" ]; then
|
||||||
PORTS_BLOCK_CONTENT=" ports:\n"
|
PORTS_BLOCK_CONTENT=" ports:\n"
|
||||||
for line in $port_vars; do
|
while read -r line; do
|
||||||
val=$(echo $line | cut -d= -f2-); PORTS_BLOCK_CONTENT="${PORTS_BLOCK_CONTENT} - ${val}\n"
|
[ -z "$line" ] && continue
|
||||||
done
|
val=$(echo "$line" | cut -d= -f2-); PORTS_BLOCK_CONTENT="${PORTS_BLOCK_CONTENT} - ${val}\n"
|
||||||
|
done <<< "$port_vars"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
VOL_BLOCK_CONTENT=""
|
VOL_BLOCK_CONTENT=""
|
||||||
vol_vars=$(grep '^VOL_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
vol_vars=$(grep '^VOL_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||||
if [ ! -z "$vol_vars" ]; then
|
if [ -n "$vol_vars" ]; then
|
||||||
VOL_BLOCK_CONTENT=" volumes:\n"
|
VOL_BLOCK_CONTENT=" volumes:\n"
|
||||||
for line in $vol_vars; do
|
|
||||||
val=$(echo $line | cut -d= -f2-); VOL_BLOCK_CONTENT="${VOL_BLOCK_CONTENT} - ${val}\n"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# --- 5. DOCKER RUN BEFEHL GENERIEREN ---
|
|
||||||
RUN_CMD="docker run -d \\ \n --name $REPO_PURE \\ \n --restart unless-stopped"
|
|
||||||
|
|
||||||
# Hier || true im grep, damit die Pipe nicht platzt
|
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
if [[ "$line" =~ ^PORT_ ]]; then
|
[ -z "$line" ] && continue
|
||||||
val=$(echo $line | cut -d= -f2-)
|
val=$(echo "$line" | cut -d= -f2-); VOL_BLOCK_CONTENT="${VOL_BLOCK_CONTENT} - ${val}\n"
|
||||||
RUN_CMD="${RUN_CMD} \\ \n -p ${val}"
|
done <<< "$vol_vars"
|
||||||
elif [[ "$line" =~ ^ENV_ ]]; then
|
|
||||||
key=$(echo $line | cut -d= -f1); clean_key=${key#ENV_}; val=$(echo $line | cut -d= -f2-)
|
|
||||||
RUN_CMD="${RUN_CMD} \\ \n -e ${clean_key}=${val}"
|
|
||||||
elif [[ "$line" =~ ^VOL_ ]]; then
|
|
||||||
val=$(echo $line | cut -d= -f2-)
|
|
||||||
RUN_CMD="${RUN_CMD} \\ \n -v ${val}"
|
|
||||||
fi
|
fi
|
||||||
done < <(grep -E '^(PORT_|ENV_|VOL_)' buildargs.env | grep -v '^#' | sed 's/\r$//' || true)
|
|
||||||
|
|
||||||
|
# --- 5. DOCKER RUN BEFEHL ---
|
||||||
|
RUN_CMD="docker run -d \\ \n --name $REPO_PURE \\ \n --restart unless-stopped"
|
||||||
|
all_params=$(grep -E '^(PORT_|ENV_|VOL_)' buildargs.env | grep -v '^#' | sed 's/\r$//' || true)
|
||||||
|
if [ -n "$all_params" ]; then
|
||||||
|
while read -r line; do
|
||||||
|
[ -z "$line" ] && continue
|
||||||
|
if [[ "$line" =~ ^PORT_ ]]; then
|
||||||
|
val=$(echo "$line" | cut -d= -f2-); RUN_CMD="${RUN_CMD} \\ \n -p ${val}"
|
||||||
|
elif [[ "$line" =~ ^ENV_ ]]; then
|
||||||
|
key=$(echo "$line" | cut -d= -f1); clean_key=${key#ENV_}; val=$(echo "$line" | cut -d= -f2-); RUN_CMD="${RUN_CMD} \\ \n -e ${clean_key}=${val}"
|
||||||
|
elif [[ "$line" =~ ^VOL_ ]]; then
|
||||||
|
val=$(echo "$line" | cut -d= -f2-); RUN_CMD="${RUN_CMD} \\ \n -v ${val}"
|
||||||
|
fi
|
||||||
|
done <<< "$all_params"
|
||||||
|
fi
|
||||||
RUN_CMD="${RUN_CMD} \\ \n $FULL_URL:$BUILD_TAG"
|
RUN_CMD="${RUN_CMD} \\ \n $FULL_URL:$BUILD_TAG"
|
||||||
DOCKER_RUN_FINAL=$(echo -e "$RUN_CMD")
|
DOCKER_RUN_FINAL=$(echo -e "$RUN_CMD")
|
||||||
|
|
||||||
# --- 6. DOCKER HUB LINK ---
|
# --- 6. DOCKER HUB LINK ---
|
||||||
DOCKERHUB_LINK_CONTENT=""
|
DOCKERHUB_LINK_CONTENT=""
|
||||||
if [[ "$PUSH" == *"dockerhub"* ]]; then
|
if [[ "${{ steps.prep.outputs.push_targets }}" == *"dockerhub"* ]]; then
|
||||||
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
|
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
|
||||||
DOCKERHUB_LINK_CONTENT="[](https://hub.docker.com/r/${DH_USER}/${REPO_PURE})"
|
DOCKERHUB_LINK_CONTENT="[](https://hub.docker.com/r/${DH_USER}/${REPO_PURE})"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- 7. TEMPLATE ENGINE ---
|
# --- 7. TEMPLATE ENGINE ---
|
||||||
|
# Wir nutzen einen temp-Ordner für die Ersetzungen, um Sonderzeichen-Probleme zu vermeiden
|
||||||
process_template() {
|
process_template() {
|
||||||
local template=$1; local output=$2
|
local template=$1; local output=$2
|
||||||
if [ -f "$template" ]; then
|
[ ! -f "$template" ] && return
|
||||||
> "$output"
|
cp "$template" "$output"
|
||||||
while IFS= read -r line || [ -n "$line" ]; do
|
# Einfache Ersetzungen
|
||||||
line="${line//__REPO_NAME__/$REPO_PURE}"
|
sed -i "s|__REPO_NAME__|$REPO_PURE|g" "$output"
|
||||||
line="${line//__FULL_URL__/$FULL_URL}"
|
sed -i "s|__FULL_URL__|$FULL_URL|g" "$output"
|
||||||
line="${line//__BUILD_TAG__/$BUILD_TAG}"
|
sed -i "s|__BUILD_TAG__|$BUILD_TAG|g" "$output"
|
||||||
line="${line//__BASE_IMAGE__/$BASE_IMAGE}"
|
sed -i "s|__BASE_IMAGE__|$BASE_IMAGE|g" "$output"
|
||||||
line="${line//__ARM_STATUS__/$ARM_STATUS}"
|
sed -i "s|__ARM_STATUS__|$ARM_STATUS|g" "$output"
|
||||||
line="${line//__CURRENT_DATE__/$CURRENT_TIME}"
|
sed -i "s|__CURRENT_DATE__|$CURRENT_TIME|g" "$output"
|
||||||
line="${line//__HISTORY_CONTENT__/$HISTORY_CONTENT}"
|
|
||||||
line="${line//__DOCKER_RUN__/$DOCKER_RUN_FINAL}"
|
# Komplexe Blöcke über ein temporäres File einfügen (verhindert Shell-Interpretationsfehler)
|
||||||
line="${line//__DOCKERHUB_LINK__/$DOCKERHUB_LINK_CONTENT}"
|
awk -v r="$HISTORY_CONTENT" '{gsub(/__HISTORY_CONTENT__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||||
# Description
|
awk -v r="$DOCKER_RUN_FINAL" '{gsub(/__DOCKER_RUN__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||||
if [[ "$line" == *"__DESCRIPTION__"* ]]; then
|
awk -v r="$DOCKERHUB_LINK_CONTENT" '{gsub(/__DOCKERHUB_LINK__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||||
echo -e "${DESCRIPTION:-Keine Beschreibung.}" >> "$output"
|
|
||||||
# Environment
|
# Multiline DESCRIPTION & Blocks
|
||||||
elif [[ "$line" == *"__ENV_BLOCK__"* ]]; then
|
if grep -q "__DESCRIPTION__" "$output"; then
|
||||||
[ -n "$ENV_BLOCK_CONTENT" ] && echo -e "${ENV_BLOCK_CONTENT}" >> "$output"
|
awk -v r="$(echo -e "${DESCRIPTION:-Keine Beschreibung.}")" '{gsub(/__DESCRIPTION__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||||
# Ports
|
|
||||||
elif [[ "$line" == *"__PORTS_BLOCK__"* ]]; then
|
|
||||||
[ -n "$PORTS_BLOCK_CONTENT" ] && echo -e "${PORTS_BLOCK_CONTENT}" >> "$output"
|
|
||||||
# Volumes
|
|
||||||
elif [[ "$line" == *"__VOL_BLOCK__"* ]]; then
|
|
||||||
[ -n "$VOL_BLOCK_CONTENT" ] && echo -e "${VOL_BLOCK_CONTENT}" >> "$output"
|
|
||||||
# Compose
|
|
||||||
elif [[ "$line" == *"__COMPOSE_BLOCK__"* ]]; then
|
|
||||||
[ -f "docker-compose.yml" ] && cat docker-compose.yml >> "$output"
|
|
||||||
else
|
|
||||||
echo "$line" >> "$output"
|
|
||||||
fi
|
fi
|
||||||
done < "$template"
|
if grep -q "__ENV_BLOCK__" "$output"; then
|
||||||
|
awk -v r="$(echo -e "$ENV_BLOCK_CONTENT")" '{gsub(/__ENV_BLOCK__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||||
|
fi
|
||||||
|
# ... analog für Ports und Volumes ...
|
||||||
|
awk -v r="$(echo -e "$PORTS_BLOCK_CONTENT")" '{gsub(/__PORTS_BLOCK__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||||
|
awk -v r="$(echo -e "$VOL_BLOCK_CONTENT")" '{gsub(/__VOL_BLOCK__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||||
|
|
||||||
|
# Compose-Inhalt am Ende einfügen, falls das Tag da ist
|
||||||
|
if grep -q "__COMPOSE_BLOCK__" "$output" && [ -f "docker-compose.yml" ]; then
|
||||||
|
sed -e '/__COMPOSE_BLOCK__/{r docker-compose.yml' -e 'd;}' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,7 +312,6 @@ jobs:
|
|||||||
echo "DESCRIPTION<<EOF" >> $GITHUB_ENV
|
echo "DESCRIPTION<<EOF" >> $GITHUB_ENV
|
||||||
echo -e "$DESCRIPTION" >> $GITHUB_ENV
|
echo -e "$DESCRIPTION" >> $GITHUB_ENV
|
||||||
echo "EOF" >> $GITHUB_ENV
|
echo "EOF" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Push README to Docker Hub
|
- name: Push README to Docker Hub
|
||||||
# WICHTIG: Verwende jetzt outputs.push_targets statt env.PUSH
|
# WICHTIG: Verwende jetzt outputs.push_targets statt env.PUSH
|
||||||
if: steps.check_changes.outputs.should_build == 'true' && contains(steps.prep.outputs.push_targets, 'dockerhub')
|
if: steps.check_changes.outputs.should_build == 'true' && contains(steps.prep.outputs.push_targets, 'dockerhub')
|
||||||
|
|||||||
Reference in New Issue
Block a user