fix push to Dockerhub
Some checks failed
/ release-and-build (push) Failing after 56s

This commit is contained in:
2026-02-14 00:20:56 +01:00
parent d38ac15f44
commit bb5589da0d

View File

@@ -253,121 +253,115 @@ jobs:
done
- name: Update Documentation and Compose
if: steps.check_changes.outputs.should_build == 'true' || gitea.event_name == 'push'
id: update_doc
if: steps.check_changes.outputs.should_build == 'true'
run: |
set -x # <--- AKTIVIERT DAS TRACING
# --- 1. VARIABLEN VORBEREITEN ---
export TZ=Europe/Berlin
CURRENT_TIME=$(date +'%d.%m.%Y %H:%M')
BUILD_DATE_ONLY=$(date +'%d.%m.%Y')
CURRENT_TIME=$(date '+%d.%m.%Y %H:%M')
BUILD_DATE_ONLY=$(date '+%d.%m.%Y')
BUILD_TAG=${{ steps.prep.outputs.docker_tag }}
FULL_URL=${{ steps.prep.outputs.image_name }}
REPO_PURE=${{ steps.prep.outputs.repo_pure }}
BASE_IMAGE=${{ steps.prep.outputs.base_image }}
# --- HIER IST DIE BRÜCKE: Outputs in Shell-Variablen laden ---
# Wir nutzen die Namen, die du im 'prep' Step definiert hast
BUILD_TAG="${{ steps.prep.outputs.docker_tag }}"
FULL_URL="${{ steps.prep.outputs.image_name }}"
REPO_PURE="${{ steps.prep.outputs.repo_pure }}"
BASE_IMAGE="${{ steps.prep.outputs.base_image }}"
# Zusätzliche Info für ARM Status
[ -f "Dockerfile.aarch64" ] && ARM_STATUS="✅ Aktiv (eigenes Dockerfile)" || ARM_STATUS="✅ Aktiv (via Standard Dockerfile)"
if [ -f "Dockerfile.aarch64" ]; then
ARM_STATUS="✅ Aktiv (eigenes Dockerfile)"
else
ARM_STATUS="❌ Nicht unterstützt"
fi
# Env laden für die Werteeretzung (z.B. für die Generatoren)
# Umgebungsvariablen laden
set -a
source <(grep -v '^#' buildargs.env | sed 's/\r$//')
set +a
COMMIT_MSG=$(echo "${{ github.event.head_commit.message }}" | sed 's/\[skip ci\]//g' | xargs)
# Commit Message Logik
if [[ "${{ steps.prep.outputs.event_name }}" == "schedule" ]]; then
COMMIT_MSG="Automatischer Security-Rebuild"
else
COMMIT_MSG=$(git log -1 --pretty=%s --no-merges 2>/dev/null || echo "Manual build")
COMMIT_MSG=$(echo "$COMMIT_MSG" | sed 's/\[skip ci\]//g' | xargs)
fi
# --- 2. TEMPLATES LADEN ---
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/README.template -O README.template
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/docker-compose.template -O docker-compose.template
# Templates laden
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/README.template -O README.template || exit 1
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/docker-compose.template -O docker-compose.template || true
# History Update
NEW_ROW="| **v${BUILD_TAG}** | ${CURRENT_TIME} | ${COMMIT_MSG} ✅ |"
# --- 3. VERSION HISTORY UPDATE ---
NEW_ROW="| **$BUILD_TAG** | $CURRENT_TIME | $COMMIT_MSG ✅ |"
if [ -f "VERSION.history" ]; then
grep -v "| **v${BUILD_TAG}** |" VERSION.history > VERSION.history.tmp || true
echo -e "${NEW_ROW}\n$(cat VERSION.history.tmp)" > VERSION.history
grep -v "| **$BUILD_TAG** |" VERSION.history > VERSION.history.tmp
echo "$NEW_ROW" > VERSION.history
cat VERSION.history.tmp >> VERSION.history
rm VERSION.history.tmp
else
echo -e "${NEW_ROW}" > VERSION.history
echo "$NEW_ROW" > VERSION.history
fi
HISTORY_CONTENT=$(cat VERSION.history)
# --- GENERATOREN (Block-Bau) ---
# 1. Environment Block
# --- 4. ENV / PORTS / VOL BLÖCKE GENERIEREN ---
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')
if [ ! -z "$env_vars" ]; then
ENV_BLOCK_CONTENT=" environment:\\n" # Header nur wenn Variablen da sind
ENV_BLOCK_CONTENT=" environment:\n"
for line in $env_vars; do
key=$(echo "$line" | cut -d'=' -f1)
val="${!key}"
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
fi
# 2. Ports Block
PORTS_BLOCK_CONTENT=""
port_vars=$(grep '^PORT_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
if [ ! -z "$port_vars" ]; then
PORTS_BLOCK_CONTENT=" ports:\\n"
for line in $port_vars; do
key=$(echo "$line" | cut -d'=' -f1)
val="${!key}"
PORTS_BLOCK_CONTENT="${PORTS_BLOCK_CONTENT} - \"${val}\"\\n"
done
PORTS_BLOCK_CONTENT=" ports:\n"
for line in $port_vars; do
val=$(echo $line | cut -d= -f2-)
PORTS_BLOCK_CONTENT="${PORTS_BLOCK_CONTENT} - ${val}\n"
done
fi
# 3. Volumes Block
VOL_BLOCK_CONTENT=""
vol_vars=$(grep '^VOL_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
if [ ! -z "$vol_vars" ]; then
VOL_BLOCK_CONTENT=" volumes:\\n"
for line in $vol_vars; do
key=$(echo "$line" | cut -d'=' -f1)
val="${!key}"
VOL_BLOCK_CONTENT="${VOL_BLOCK_CONTENT} - ${val}\\n"
done
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
# DOCKER RUN GENERATOR
RUN_CMD="docker run -d \\ \n --name ${REPO_PURE} \\ \n --restart unless-stopped"
# --- 5. DOCKER RUN BEFEHL GENERIEREN ---
RUN_CMD="docker run -d \\ \n --name $REPO_PURE \\ \n --restart unless-stopped"
# Variablen aus buildargs.env für RUN-Befehl sammeln
# Wir nutzen hier direkt die exportierten Werte
# Environment Args für Run Command
while read -r line; do
[[ $line =~ ^PORT_ ]] && val="${line#*=}" && RUN_CMD="${RUN_CMD} \\ \n -p ${val}"
if [[ $line =~ ^ENV_ ]]; then
key="${line%%=*}"; clean_key="${key#ENV_}"; val="${!key}"
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
[[ $line =~ ^VOL_ ]] && val="${line#*=}" && RUN_CMD="${RUN_CMD} \\ \n -v ${val}"
done < <(grep -E '^(PORT_|ENV_|VOL_)' buildargs.env | grep -v '^#' | sed 's/\r$//')
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 HUB LINK GENERATOR ---
# --- 6. DOCKER HUB LINK GENERATOR ---
DOCKERHUB_LINK_CONTENT=""
if [[ "$PUSH" == *"dockerhub"* ]]; then
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
DOCKERHUB_LINK_CONTENT="[![Docker Hub](https://img.shields.io/badge/docker-hub-blue?logo=docker&logoColor=white)](https://hub.docker.com/r/${DH_USER}/${REPO_PURE})"
fi
# --- TEMPLATE ENGINE (KORRIGIERT & ERWEITERT) ---
# --- 7. TEMPLATE ENGINE FUNKTION ---
process_template() {
local template=$1; local output=$2
if [ -f "$template" ]; then
> "$output"
while IFS= read -r line || [ -n "$line" ]; do
# 1. Standard Ersetzungen
line="${line//__REPO_NAME__/$REPO_PURE}"
line="${line//__FULL_URL__/$FULL_URL}"
line="${line//__BUILD_TAG__/$BUILD_TAG}"
@@ -377,14 +371,8 @@ jobs:
line="${line//__HISTORY_CONTENT__/$HISTORY_CONTENT}"
line="${line//__DOCKER_RUN__/$DOCKER_RUN_FINAL}"
line="${line//__DOCKERHUB_LINK__/$DOCKERHUB_LINK_CONTENT}"
if [[ "$line" == *"__DESCRIPTION__"* ]]; then
# echo -e interpretiert das \n als echte neue Zeile
echo -e "${DESCRIPTION:-Keine Beschreibung.}" >> "$output"
# 2. Block Injection
if [[ "$line" == *"__DESCRIPTION__"* ]]; then
# echo -e interpretiert das \n als echte neue Zeile
echo -e "${DESCRIPTION:-Keine Beschreibung.}" >> "$output"
elif [[ "$line" == *"__ENV_BLOCK__"* ]]; then
[ -n "$ENV_BLOCK_CONTENT" ] && echo -e "${ENV_BLOCK_CONTENT}" >> "$output"
@@ -401,18 +389,18 @@ jobs:
fi
}
# Templates verarbeiten (Compose ZUERST!)
process_template "docker-compose.template" "docker-compose.yml"
process_template "README.template" "README.md"
# --- MULTILINE EXPORT FÜR NÄCHSTE STEPS ---
# Das ist die Gitea/GitHub Syntax für mehrzeilige Variablen
# --- 8. EXPORTS FÜR NÄCHSTE STEPS ---
echo "FINAL_MSG=$COMMIT_MSG" >> $GITHUB_ENV
# Multiline Export für DESCRIPTION
echo "DESCRIPTION<<EOF" >> $GITHUB_ENV
echo -e "$DESCRIPTION" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "FINAL_MSG=$COMMIT_MSG" >> $GITHUB_ENV
echo "PUSH=$PUSH" >> $GITHUB_ENV
- name: Commit, Tag and Push Changes
if: steps.check_changes.outputs.should_build == 'true'
run: |
@@ -424,6 +412,35 @@ jobs:
git push origin main
git push -f origin "v${{ steps.prep.outputs.docker_tag }}"
- name: Cleanup Temporary Tags on Docker Hub
if: steps.check_changes.outputs.should_build == 'true' && contains(env.PUSH, 'dockerhub')
run: |
echo "🧹 Aufräumen temporärer Docker Hub Tags..."
# 1. Login Token holen
TOKEN=$(curl -s -X POST "https://hub.docker.com/v2/users/login/" \
-H "Content-Type: application/json" \
-d "{\"username\": \"${{ secrets.DOCKERHUB_USERNAME }}\", \"password\": \"${{ secrets.DOCKERHUB_TOKEN }}\"}" | jq -r .token)
if [ "$TOKEN" != "null" ]; then
REPO_PURE=${{ steps.prep.outputs.repo_pure }}
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
# 2. Lösche tmp-amd64
echo "Lösche $DH_USER/$REPO_PURE:tmp-amd64 ..."
curl -s -X DELETE "https://hub.docker.com/v2/repositories/${DH_USER}/${REPO_PURE}/tags/tmp-amd64/" \
-H "Authorization: JWT ${TOKEN}"
# 3. Lösche tmp-arm64
echo "Lösche $DH_USER/$REPO_PURE:tmp-arm64 ..."
curl -s -X DELETE "https://hub.docker.com/v2/repositories/${DH_USER}/${REPO_PURE}/tags/tmp-arm64/" \
-H "Authorization: JWT ${TOKEN}"
echo "✅ Temporäre Tags entfernt."
else
echo "⚠️ Konnte kein Token für Cleanup erhalten. Tags bleiben bestehen."
fi
- name: Cleanup Docker Artifacts
if: always()
run: docker image prune -f