fix docker-compose.yml handling
build-and-push.yaml (push) Invalid workflow file

This commit is contained in:
pi-farm committed 2026-10-28 15:37:42 +00:00
1 parent 171d8bc12e
commit 761b4658da
1 file changed
+38 -38
+38 -38
View File
@@ -329,53 +329,53 @@ jobs:
fi fi
cat << 'EOF' > update_script.py cat << 'EOF' > update_script.py
import os, sys import os, re
def process(output_file): # 1. Wir lesen die Schlüsselnamen (Keys) aus der buildargs.env aus,
# Hier mappen wir README.md auf deine rm.template # damit wir wissen, welche Variablen als Platzhalter eingefügt werden sollen.
if output_file == "README.md": env_keys = []
template_name = ".gitea/rm.template" if os.path.exists(".gitea/rm.template") else "rm.template" if os.path.exists("buildargs.env"):
else: with open("buildargs.env", "r", encoding="utf-8") as f:
template_name = output_file.replace('.yml', '.template') for line in f:
line = line.strip()
# Ignoriere Kommentare und leere Zeilen
if line and not line.startswith("#") and "=" in line:
key = line.split("=")[0].strip()
# Wir wollen nur die SAMBA_-Variablen oder alle BUILD_-Variablen ausschließen
if key.startswith("SAMBA_") or key.startswith("DNS_"):
env_keys.append(key)
if not os.path.exists(template_name): # Falls keine spezifischen gefunden wurden, Fallback auf die üblichen
return if not env_keys:
env_keys = [
"SAMBA_REALM", "SAMBA_DOMAIN", "SAMBA_HOSTNAME",
"SAMBA_FQDN", "SAMBA_IP", "SAMBA_NETWORK",
"DNS_FORWARDER", "SAMBA_ADMIN_PASSWORD"
]
with open(template_name, "r", encoding="utf-8") as f: # 2. Erzeuge den Env-Block mit ${VARIABLE_NAME} Syntax
content = f.read() env_block_lines = []
for key in env_keys:
env_block_lines.append(f" {key}: ${{{key}}}")
content = content.replace("__REPO_NAME__", os.environ.get("REPO_PURE", "")) env_block_str = "\n".join(env_block_lines)
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"): # 3. Template einlesen und Platzhalter ersetzen
with open("docker_run_block.txt", "r", encoding="utf-8") as f: template_name = ".gitea/docker-compose.template" if os.path.exists(".gitea/docker-compose.template") else "docker-compose.template"
content = content.replace("__DOCKER_RUN__", f.read())
if "__COMPOSE_BLOCK__" in content and os.path.exists("docker-compose.yml"): with open(template_name, "r", encoding="utf-8") as f:
with open("docker-compose.yml", "r", encoding="utf-8") as f: content = f.read()
content = content.replace("__COMPOSE_BLOCK__", f.read())
with open(output_file, "w", encoding="utf-8") as f: # Ersetzungen durchführen
f.write(content) content = content.replace("__REPO_NAME__", "samba-ad-dc")
content = content.replace("__FULL_URL__", "git.pi-farm.de/pi-farm/samba-ad-dc")
content = content.replace("__BUILD_TAG__", os.environ.get("FINAL_TAG", "trixie"))
content = content.replace("__ENV_BLOCK__", env_block_str)
process("docker-compose.yml") with open("docker-compose.yml", "w", encoding="utf-8") as f:
process("README.md") f.write(content)
print("docker-compose.yml erfolgreich mit Platzhaltern generiert!")
EOF EOF
export REPO_PURE FULL_URL BUILD_TAG BASE_IMAGE ARM_STATUS CURRENT_TIME \
HISTORY_CONTENT DOCKERHUB_LINK_CONTENT ENV_BLOCK_CONTENT \
PORTS_BLOCK_CONTENT VOL_BLOCK_CONTENT DESCRIPTION
python3 update_script.py python3 update_script.py
rm -f update_script.py rm -f update_script.py