1. try #1
@@ -329,53 +329,53 @@ jobs:
|
||||
fi
|
||||
|
||||
cat << 'EOF' > update_script.py
|
||||
import os, sys
|
||||
import os, re
|
||||
|
||||
def process(output_file):
|
||||
# Hier mappen wir README.md auf deine rm.template
|
||||
if output_file == "README.md":
|
||||
template_name = ".gitea/rm.template" if os.path.exists(".gitea/rm.template") else "rm.template"
|
||||
else:
|
||||
template_name = output_file.replace('.yml', '.template')
|
||||
# 1. Wir lesen die Schlüsselnamen (Keys) aus der buildargs.env aus,
|
||||
# damit wir wissen, welche Variablen als Platzhalter eingefügt werden sollen.
|
||||
env_keys = []
|
||||
if os.path.exists("buildargs.env"):
|
||||
with open("buildargs.env", "r", encoding="utf-8") as f:
|
||||
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):
|
||||
return
|
||||
# Falls keine spezifischen gefunden wurden, Fallback auf die üblichen
|
||||
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:
|
||||
content = f.read()
|
||||
# 2. Erzeuge den Env-Block mit ${VARIABLE_NAME} Syntax
|
||||
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", ""))
|
||||
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."))
|
||||
env_block_str = "\n".join(env_block_lines)
|
||||
|
||||
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())
|
||||
# 3. Template einlesen und Platzhalter ersetzen
|
||||
template_name = ".gitea/docker-compose.template" if os.path.exists(".gitea/docker-compose.template") else "docker-compose.template"
|
||||
|
||||
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(template_name, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
with open(output_file, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
# Ersetzungen durchführen
|
||||
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")
|
||||
process("README.md")
|
||||
with open("docker-compose.yml", "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
print("docker-compose.yml erfolgreich mit Platzhaltern generiert!")
|
||||
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
|
||||
rm -f update_script.py
|
||||
|
||||
|
||||
Reference in new issue
Block a user