.gitea/workflows/build-and-push.yaml aktualisiert
This commit is contained in:
1 parent
faec5655ff
commit
d194e1fa43
1 file changed
+119
-129
@@ -226,7 +226,7 @@ jobs:
|
||||
source ./cleaned_env.sh
|
||||
set +a
|
||||
|
||||
# WICHTIG: Nach dem Sourcing den dynamischen Tag (inkl. -dev falls dev-Branch) erzwingen!
|
||||
# Nach dem Sourcing den dynamischen Tag (inkl. -dev falls dev-Branch) erzwingen
|
||||
BUILD_TAG="${{ steps.prep.outputs.docker_tag }}"
|
||||
|
||||
if [ -f "Dockerfile.aarch64" ]; then ARM_STATUS="✅ Active"; else ARM_STATUS="❌ Not supported"; fi
|
||||
@@ -234,110 +234,100 @@ jobs:
|
||||
RAW_COMMIT_MSG="${{ gitea.event.head_commit.message }}"
|
||||
COMMIT_MSG=$(echo "$RAW_COMMIT_MSG" | sed 's/\[skip ci\]//g' | tr -d '\r\n' | xargs)
|
||||
|
||||
# ... (restlicher Skriptverlauf bleibt unverändert)
|
||||
TOKEN="${{ secrets.RUNNER_TOKEN }}"
|
||||
curl -sSLf -H "Authorization: token $TOKEN" \
|
||||
"https://git.pi-farm.de/pi-farm/templates/raw/branch/main/README.template" \
|
||||
-o README.template || echo "Warnung: README Template konnte nicht geladen werden"
|
||||
|
||||
# WICHTIG: Nach dem Sourcing den dynamischen Tag (inkl. -dev falls dev-Branch) erzwingen!
|
||||
BUILD_TAG="${{ steps.prep.outputs.docker_tag }}"
|
||||
curl -sSLf -H "Authorization: token $TOKEN" \
|
||||
"https://git.pi-farm.de/pi-farm/templates/raw/branch/main/docker-compose.template" \
|
||||
-o docker-compose.template || echo "Warnung: Compose Template konnte nicht geladen werden"
|
||||
|
||||
if [ -f "Dockerfile.aarch64" ]; then ARM_STATUS="✅ Active"; else ARM_STATUS="❌ Not supported"; fi
|
||||
|
||||
RAW_COMMIT_MSG="${{ gitea.event.head_commit.message }}"
|
||||
COMMIT_MSG=$(echo "$RAW_COMMIT_MSG" | sed 's/\[skip ci\]//g' | tr -d '\r\n' | xargs)
|
||||
|
||||
TOKEN="${{ secrets.RUNNER_TOKEN }}"
|
||||
curl -sSLf -H "Authorization: token $TOKEN" \
|
||||
"https://git.pi-farm.de/pi-farm/templates/raw/branch/main/README.template" \
|
||||
-o README.template || echo "Warnung: README Template konnte nicht geladen werden"
|
||||
|
||||
curl -sSLf -H "Authorization: token $TOKEN" \
|
||||
"https://git.pi-farm.de/pi-farm/templates/raw/branch/main/docker-compose.template" \
|
||||
-o docker-compose.template || echo "Warnung: Compose Template konnte nicht geladen werden"
|
||||
|
||||
for t_file in README.template docker-compose.template; do
|
||||
if [ -f "$t_file" ] && grep -qi "<!DOCTYPE html>" "$t_file"; then
|
||||
echo "❌ FEHLER: $t_file ist eine HTML-Loginseite! Download verworfen."
|
||||
rm -f "$t_file"
|
||||
fi
|
||||
done
|
||||
|
||||
NEW_ROW="| **$BUILD_TAG** | $CURRENT_TIME | $COMMIT_MSG ✅ |"
|
||||
if [ -f "VERSION.history" ]; then
|
||||
grep -v "| **$BUILD_TAG** |" VERSION.history > VERSION.history.tmp || true
|
||||
echo "$NEW_ROW" > VERSION.history
|
||||
cat VERSION.history.tmp >> VERSION.history
|
||||
rm VERSION.history.tmp
|
||||
else
|
||||
echo "$NEW_ROW" > VERSION.history
|
||||
for t_file in README.template docker-compose.template; do
|
||||
if [ -f "$t_file" ] && grep -qi "<!DOCTYPE html>" "$t_file"; then
|
||||
echo "❌ FEHLER: $t_file ist eine HTML-Loginseite! Download verworfen."
|
||||
rm -f "$t_file"
|
||||
fi
|
||||
HISTORY_CONTENT=$(cat VERSION.history)
|
||||
done
|
||||
|
||||
ENV_BLOCK_CONTENT=""
|
||||
env_vars=$(grep '^ENV_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||
if [ -n "$env_vars" ]; then
|
||||
ENV_BLOCK_CONTENT=" environment:\n"
|
||||
NEW_ROW="| **$BUILD_TAG** | $CURRENT_TIME | $COMMIT_MSG ✅ |"
|
||||
if [ -f "VERSION.history" ]; then
|
||||
grep -v "| **$BUILD_TAG** |" VERSION.history > VERSION.history.tmp || true
|
||||
echo "$NEW_ROW" > VERSION.history
|
||||
cat VERSION.history.tmp >> VERSION.history
|
||||
rm VERSION.history.tmp
|
||||
else
|
||||
echo "$NEW_ROW" > VERSION.history
|
||||
fi
|
||||
HISTORY_CONTENT=$(cat VERSION.history)
|
||||
|
||||
ENV_BLOCK_CONTENT=""
|
||||
env_vars=$(grep '^ENV_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||
if [ -n "$env_vars" ]; then
|
||||
ENV_BLOCK_CONTENT=" environment:\n"
|
||||
while read -r line; do
|
||||
[ -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"
|
||||
done <<< "$env_vars"
|
||||
fi
|
||||
|
||||
PORTS_BLOCK_CONTENT=""
|
||||
port_vars=$(grep '^PORT_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||
if [ -n "$port_vars" ]; then
|
||||
PORTS_BLOCK_CONTENT=" ports:\n"
|
||||
while read -r line; do
|
||||
[ -z "$line" ] && continue
|
||||
val=$(echo "$line" | cut -d= -f2-); PORTS_BLOCK_CONTENT="${PORTS_BLOCK_CONTENT} - ${val}\n"
|
||||
done <<< "$port_vars"
|
||||
fi
|
||||
|
||||
VOL_BLOCK_CONTENT=""
|
||||
vol_vars=$(grep '^VOL_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||
if [ -n "$vol_vars" ]; then
|
||||
VOL_BLOCK_CONTENT=" volumes:\n"
|
||||
while read -r line; do
|
||||
[ -z "$line" ] && continue
|
||||
val=$(echo "$line" | cut -d= -f2-); VOL_BLOCK_CONTENT="${VOL_BLOCK_CONTENT} - ${val}\n"
|
||||
done <<< "$vol_vars"
|
||||
fi
|
||||
|
||||
{
|
||||
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
|
||||
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"
|
||||
done <<< "$env_vars"
|
||||
if [[ "$line" =~ ^PORT_ ]]; then
|
||||
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-)
|
||||
echo " -e ${clean_key}=${val} \\"
|
||||
elif [[ "$line" =~ ^VOL_ ]]; then
|
||||
val=$(echo "$line" | cut -d= -f2-)
|
||||
echo " -v ${val} \\"
|
||||
fi
|
||||
done <<< "$all_params"
|
||||
fi
|
||||
echo " $FULL_URL:$BUILD_TAG"
|
||||
} > docker_run_block.txt
|
||||
|
||||
PORTS_BLOCK_CONTENT=""
|
||||
port_vars=$(grep '^PORT_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||
if [ -n "$port_vars" ]; then
|
||||
PORTS_BLOCK_CONTENT=" ports:\n"
|
||||
while read -r line; do
|
||||
[ -z "$line" ] && continue
|
||||
val=$(echo "$line" | cut -d= -f2-); PORTS_BLOCK_CONTENT="${PORTS_BLOCK_CONTENT} - ${val}\n"
|
||||
done <<< "$port_vars"
|
||||
fi
|
||||
DOCKERHUB_LINK_CONTENT=""
|
||||
if [[ "${{ steps.prep.outputs.push_targets }}" == *"dockerhub"* ]]; then
|
||||
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
|
||||
DOCKERHUB_LINK_CONTENT='<a href="https://hub.docker.com/r/'"${DH_USER}"'/'"${REPO_PURE}"'" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/docker-hub-blue?logo=docker&logoColor=white" alt="Docker Hub"></a>'
|
||||
fi
|
||||
|
||||
VOL_BLOCK_CONTENT=""
|
||||
vol_vars=$(grep '^VOL_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||
if [ -n "$vol_vars" ]; then
|
||||
VOL_BLOCK_CONTENT=" volumes:\n"
|
||||
while read -r line; do
|
||||
[ -z "$line" ] && continue
|
||||
val=$(echo "$line" | cut -d= -f2-); VOL_BLOCK_CONTENT="${VOL_BLOCK_CONTENT} - ${val}\n"
|
||||
done <<< "$vol_vars"
|
||||
fi
|
||||
if ! command -v python3 &> /dev/null; then
|
||||
echo "📦 python3 fehlt und wird installiert..."
|
||||
(apt-get update && apt-get install -y python3) || (apk add --no-cache python3) || true
|
||||
fi
|
||||
|
||||
{
|
||||
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-)
|
||||
echo " -p ${val} \\"
|
||||
elif [[ "$line" =~ ^ENV_ ]]; then
|
||||
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-)
|
||||
echo " -v ${val} \\"
|
||||
fi
|
||||
done <<< "$all_params"
|
||||
fi
|
||||
echo " $FULL_URL:$BUILD_TAG"
|
||||
} > docker_run_block.txt
|
||||
|
||||
DOCKERHUB_LINK_CONTENT=""
|
||||
if [[ "${{ steps.prep.outputs.push_targets }}" == *"dockerhub"* ]]; then
|
||||
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
|
||||
DOCKERHUB_LINK_CONTENT='<a href="https://hub.docker.com/r/'"${DH_USER}"'/'"${REPO_PURE}"'" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/docker-hub-blue?logo=docker&logoColor=white" alt="Docker Hub"></a>'
|
||||
fi
|
||||
|
||||
if ! command -v python3 &> /dev/null; then
|
||||
echo "📦 python3 fehlt und wird installiert..."
|
||||
(apt-get update && apt-get install -y python3) || (apk add --no-cache python3) || true
|
||||
fi
|
||||
|
||||
process_template() {
|
||||
process_template() {
|
||||
local template=$1; local output=$2
|
||||
[ ! -f "$template" ] && return
|
||||
cp "$template" "$output"
|
||||
@@ -347,48 +337,48 @@ jobs:
|
||||
PORTS_BLOCK_CONTENT VOL_BLOCK_CONTENT DESCRIPTION
|
||||
|
||||
python3 -c '
|
||||
import os, sys
|
||||
import os, sys
|
||||
|
||||
output = sys.argv[1]
|
||||
output = sys.argv[1]
|
||||
|
||||
with open(output, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
with open(output, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
content = content.replace("__REPO_NAME__", os.environ.get("REPO_PURE", ""))
|
||||
content = content.replace("__FULL_URL__", os.environ.get("FULL_URL", ""))
|
||||
content = content.replace("__BUILD_TAG__", os.environ.get("BUILD_TAG", ""))
|
||||
content = content.replace("__BASE_IMAGE__", os.environ.get("BASE_IMAGE", ""))
|
||||
content = content.replace("__ARM_STATUS__", os.environ.get("ARM_STATUS", ""))
|
||||
content = content.replace("__CURRENT_DATE__", os.environ.get("CURRENT_TIME", ""))
|
||||
content = content.replace("__HISTORY_CONTENT__", os.environ.get("HISTORY_CONTENT", ""))
|
||||
content = content.replace("__DOCKERHUB_LINK__", os.environ.get("DOCKERHUB_LINK_CONTENT", ""))
|
||||
content = content.replace("__ENV_BLOCK__", os.environ.get("ENV_BLOCK_CONTENT", "").replace("\\n", "\n"))
|
||||
content = content.replace("__PORTS_BLOCK__", os.environ.get("PORTS_BLOCK_CONTENT", "").replace("\\n", "\n"))
|
||||
content = content.replace("__VOL_BLOCK__", os.environ.get("VOL_BLOCK_CONTENT", "").replace("\\n", "\n"))
|
||||
content = content.replace("__DESCRIPTION__", os.environ.get("DESCRIPTION", "Keine Beschreibung."))
|
||||
content = content.replace("__REPO_NAME__", os.environ.get("REPO_PURE", ""))
|
||||
content = content.replace("__FULL_URL__", os.environ.get("FULL_URL", ""))
|
||||
content = content.replace("__BUILD_TAG__", os.environ.get("BUILD_TAG", ""))
|
||||
content = content.replace("__BASE_IMAGE__", os.environ.get("BASE_IMAGE", ""))
|
||||
content = content.replace("__ARM_STATUS__", os.environ.get("ARM_STATUS", ""))
|
||||
content = content.replace("__CURRENT_DATE__", os.environ.get("CURRENT_TIME", ""))
|
||||
content = content.replace("__HISTORY_CONTENT__", os.environ.get("HISTORY_CONTENT", ""))
|
||||
content = content.replace("__DOCKERHUB_LINK__", os.environ.get("DOCKERHUB_LINK_CONTENT", ""))
|
||||
content = content.replace("__ENV_BLOCK__", os.environ.get("ENV_BLOCK_CONTENT", "").replace("\\n", "\n"))
|
||||
content = content.replace("__PORTS_BLOCK__", os.environ.get("PORTS_BLOCK_CONTENT", "").replace("\\n", "\n"))
|
||||
content = content.replace("__VOL_BLOCK__", os.environ.get("VOL_BLOCK_CONTENT", "").replace("\\n", "\n"))
|
||||
content = content.replace("__DESCRIPTION__", os.environ.get("DESCRIPTION", "Keine Beschreibung."))
|
||||
|
||||
if "__DOCKER_RUN__" in content and os.path.exists("docker_run_block.txt"):
|
||||
with open("docker_run_block.txt", "r", encoding="utf-8") as f:
|
||||
content = content.replace("__DOCKER_RUN__", f.read())
|
||||
if "__DOCKER_RUN__" in content and os.path.exists("docker_run_block.txt"):
|
||||
with open("docker_run_block.txt", "r", encoding="utf-8") as f:
|
||||
content = content.replace("__DOCKER_RUN__", f.read())
|
||||
|
||||
if "__COMPOSE_BLOCK__" in content and os.path.exists("docker-compose.yml"):
|
||||
with open("docker-compose.yml", "r", encoding="utf-8") as f:
|
||||
content = content.replace("__COMPOSE_BLOCK__", f.read())
|
||||
if "__COMPOSE_BLOCK__" in content and os.path.exists("docker-compose.yml"):
|
||||
with open("docker-compose.yml", "r", encoding="utf-8") as f:
|
||||
content = content.replace("__COMPOSE_BLOCK__", f.read())
|
||||
|
||||
with open(output, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
' "$output"
|
||||
}
|
||||
with open(output, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
' "$output"
|
||||
}
|
||||
|
||||
process_template "docker-compose.template" "docker-compose.yml"
|
||||
process_template "README.template" "README.md"
|
||||
process_template "docker-compose.template" "docker-compose.yml"
|
||||
process_template "README.template" "README.md"
|
||||
|
||||
echo "FINAL_MSG=$COMMIT_MSG" >> $GITHUB_ENV
|
||||
{
|
||||
echo "DESCRIPTION<<EOF"
|
||||
echo "$DESCRIPTION"
|
||||
echo "EOF"
|
||||
} >> $GITHUB_ENV
|
||||
echo "FINAL_MSG=$COMMIT_MSG" >> $GITHUB_ENV
|
||||
{
|
||||
echo "DESCRIPTION<<EOF"
|
||||
echo "$DESCRIPTION"
|
||||
echo "EOF"
|
||||
} >> $GITHUB_ENV
|
||||
|
||||
- name: Push README to Docker Hub
|
||||
if: steps.check_changes.outputs.should_build == 'true' && contains(steps.prep.outputs.push_targets, 'dockerhub')
|
||||
|
||||
Reference in new issue
Block a user