update workflow to fix docker run syntax
All checks were successful
/ release-and-build (push) Successful in 1m21s
All checks were successful
/ release-and-build (push) Successful in 1m21s
This commit is contained in:
@@ -163,15 +163,15 @@ jobs:
|
||||
run: |
|
||||
set -x
|
||||
|
||||
# --- 1. VARIABLEN VORBEREITEN ---
|
||||
export TZ=Europe/Berlin
|
||||
CURRENT_TIME=$(date '+%d.%m.%Y %H:%M')
|
||||
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 }}"
|
||||
REPO_URL="https://git.pi-farm.de/${{ gitea.repository }}"
|
||||
|
||||
if [ ! -f "buildargs.env" ]; then echo "❌ buildargs.env fehlt!"; exit 1; fi
|
||||
if [ ! -f "buildargs.env" ]; then echo "❌ buildargs.env missing!"; exit 1; fi
|
||||
|
||||
grep -v '^#' buildargs.env | sed 's/\r$//' > cleaned_env.sh
|
||||
set -a
|
||||
@@ -185,9 +185,11 @@ jobs:
|
||||
EOF
|
||||
COMMIT_MSG=$(sed 's/\[skip ci\]//g' commit_msg.txt | xargs)
|
||||
|
||||
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/docker-compose.template -O docker-compose.template || echo "Templates konnten nicht geladen werden"
|
||||
# --- 2. TEMPLATES LADEN ---
|
||||
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/README.template -O README.template || echo "Warnung: README Template fehlt"
|
||||
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/docker-compose.template -O docker-compose.template || echo "Warnung: Compose Template fehlt"
|
||||
|
||||
# --- 3. VERSION HISTORY ---
|
||||
NEW_ROW="| **$BUILD_TAG** | $CURRENT_TIME | $COMMIT_MSG ✅ |"
|
||||
if [ -f "VERSION.history" ]; then
|
||||
grep -v "| **$BUILD_TAG** |" VERSION.history > VERSION.history.tmp || true
|
||||
@@ -230,63 +232,86 @@ jobs:
|
||||
done <<< "$vol_vars"
|
||||
fi
|
||||
|
||||
RUN_CMD="docker run -d \\ \n --name $REPO_PURE \\ \n --restart unless-stopped"
|
||||
# --- 5. DOCKER RUN BEFEHL (NEU: Als Datei schreiben) ---
|
||||
# Wir schreiben direkt in eine Datei. Da gibt es keine Interpretationsfehler.
|
||||
# Wichtig: " \\" am Ende der Zeilen explizit hinschreiben.
|
||||
{
|
||||
echo "docker run -d \\"
|
||||
echo " --name $REPO_PURE \\"
|
||||
echo " --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}"
|
||||
val=$(echo "$line" | cut -d= -f2-)
|
||||
echo " -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}"
|
||||
key=$(echo "$line" | cut -d= -f1); clean_key=${key#ENV_}; val=$(echo "$line" | cut -d= -f2-)
|
||||
echo " -e ${clean_key}=${val} \\"
|
||||
elif [[ "$line" =~ ^VOL_ ]]; then
|
||||
val=$(echo "$line" | cut -d= -f2-); RUN_CMD="${RUN_CMD} \\ \n -v ${val}"
|
||||
val=$(echo "$line" | cut -d= -f2-)
|
||||
echo " -v ${val} \\"
|
||||
fi
|
||||
done <<< "$all_params"
|
||||
fi
|
||||
RUN_CMD="${RUN_CMD} \\ \n $FULL_URL:$BUILD_TAG"
|
||||
DOCKER_RUN_FINAL=$(echo -e "$RUN_CMD")
|
||||
# Letzte Zeile OHNE Backslash
|
||||
echo " $FULL_URL:$BUILD_TAG"
|
||||
} > docker_run_block.txt
|
||||
|
||||
# --- 6. DOCKER HUB LINK ---
|
||||
DOCKERHUB_LINK_CONTENT=""
|
||||
if [[ "${{ steps.prep.outputs.push_targets }}" == *"dockerhub"* ]]; then
|
||||
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
|
||||
DOCKERHUB_LINK_CONTENT="[](https://hub.docker.com/r/${DH_USER}/${REPO_PURE})"
|
||||
fi
|
||||
|
||||
# --- 7. TEMPLATE ENGINE (Optimiert für File-Injection) ---
|
||||
process_template() {
|
||||
local template=$1; local output=$2
|
||||
[ ! -f "$template" ] && return
|
||||
cp "$template" "$output"
|
||||
|
||||
# Simple Ersetzungen
|
||||
sed -i "s|__REPO_NAME__|$REPO_PURE|g" "$output"
|
||||
sed -i "s|__FULL_URL__|$FULL_URL|g" "$output"
|
||||
sed -i "s|__BUILD_TAG__|$BUILD_TAG|g" "$output"
|
||||
sed -i "s|__BASE_IMAGE__|$BASE_IMAGE|g" "$output"
|
||||
sed -i "s|__ARM_STATUS__|$ARM_STATUS|g" "$output"
|
||||
sed -i "s|__CURRENT_DATE__|$CURRENT_TIME|g" "$output"
|
||||
sed -i "s|__REPO_URL__|$REPO_URL|g" "$output"
|
||||
|
||||
# Komplexe Blöcke: AWK für Strings, SED für Files
|
||||
awk -v r="$HISTORY_CONTENT" '{gsub(/__HISTORY_CONTENT__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||
awk -v r="$DOCKER_RUN_FINAL" '{gsub(/__DOCKER_RUN__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||
awk -v r="$DOCKERHUB_LINK_CONTENT" '{gsub(/__DOCKERHUB_LINK__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||
|
||||
if grep -q "__DESCRIPTION__" "$output"; then
|
||||
awk -v r="$(echo -e "${DESCRIPTION:-No Description.}")" '{gsub(/__DESCRIPTION__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||
# NEU: Docker Run Block via File einfügen (sicherste Methode)
|
||||
if grep -q "__DOCKER_RUN__" "$output" && [ -f "docker_run_block.txt" ]; then
|
||||
sed -e '/__DOCKER_RUN__/{r docker_run_block.txt' -e 'd;}' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||
fi
|
||||
|
||||
# Compose Block via File einfügen
|
||||
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
|
||||
|
||||
# ENV/PORTS/VOL Blöcke
|
||||
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
|
||||
|
||||
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"
|
||||
|
||||
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"
|
||||
# Description als letztes
|
||||
if grep -q "__DESCRIPTION__" "$output"; then
|
||||
awk -v r="$(echo -e "${DESCRIPTION:-Keine Beschreibung.}")" '{gsub(/__DESCRIPTION__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
||||
fi
|
||||
}
|
||||
|
||||
process_template "docker-compose.template" "docker-compose.yml"
|
||||
process_template "README.template" "README.md"
|
||||
|
||||
# --- 8. EXPORTS ---
|
||||
echo "FINAL_MSG=$COMMIT_MSG" >> $GITHUB_ENV
|
||||
echo "DESCRIPTION<<EOF" >> $GITHUB_ENV
|
||||
echo -e "$DESCRIPTION" >> $GITHUB_ENV
|
||||
|
||||
Reference in New Issue
Block a user