Seite auf bunny laufen lassen. Konzept umgestellt

This commit is contained in:
Michael Stangl
2026-08-26 15:18:42 +02:00
parent db08a2b405
commit 56c3063cb5
7 changed files with 303 additions and 44 deletions
+64 -10
View File
@@ -1,25 +1,79 @@
#!/usr/bin/env python3
"""
IWZ Ferienwohnungen – Deploy Script
Baut die Hugo-Seite und deployt sie zu Cloudflare Pages.
IWZ Ferienwohnungen - Deploy Script
Baut die Hugo-Seite und deployt sie per FTP zur Bunny.net Storage Zone.
"""
import ftplib
import os
import subprocess
import sys
from pathlib import Path
PROJECT = "iwz-ferienwohnungen"
PROJECT_ROOT = Path(__file__).resolve().parent
PUBLIC_DIR = PROJECT_ROOT / "public"
FTP_PORT = 21
def run(cmd, desc):
print(f"\n→ {desc}...")
result = subprocess.run(cmd, shell=True)
def load_env(path):
env = {}
if not path.exists():
return env
for line in path.read_text(encoding="utf-8").splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, value = line.split("=", 1)
env[key.strip()] = value.strip()
return env
def hugo_build():
print("\n-> Hugo Build...")
result = subprocess.run("hugo --gc --minify", shell=True)
if result.returncode != 0:
print(f"\nFEHLER bei: {desc}")
print("\nFEHLER: Hugo Build fehlgeschlagen!")
sys.exit(1)
def ftp_upload_dir(ftp, local_dir, remote_dir=""):
for entry in sorted(local_dir.iterdir()):
remote_path = f"{remote_dir}/{entry.name}" if remote_dir else entry.name
if entry.is_dir():
try:
ftp.mkd(remote_path)
except ftplib.error_perm:
pass # existiert bereits
ftp_upload_dir(ftp, entry, remote_path)
else:
with open(entry, "rb") as f:
ftp.storbinary(f"STOR {remote_path}", f)
print(f" {remote_path}")
def deploy_to_bunny(host, zone, password):
print(f"\n-> Deploy zu Bunny.net Storage Zone '{zone}'...")
with ftplib.FTP() as ftp:
ftp.connect(host, FTP_PORT)
ftp.login(zone, password)
ftp.set_pasv(True)
ftp_upload_dir(ftp, PUBLIC_DIR)
if __name__ == "__main__":
print("=== IWZ Deploy ===")
run("hugo", "Hugo Build")
run(f'wrangler pages deploy public/ --project-name {PROJECT}', "Cloudflare Pages Deploy")
print("\n✓ Fertig! Seite ist live.")
env = {**load_env(PROJECT_ROOT / ".env"), **os.environ}
zone = env.get("BUNNY_STORAGE_ZONE")
host = env.get("BUNNY_STORAGE_HOST", "storage.bunnycdn.com")
password = env.get("BUNNY_STORAGE_PASSWORD")
if not zone or not password:
print("\nFEHLER: BUNNY_STORAGE_ZONE / BUNNY_STORAGE_PASSWORD fehlen.")
print("Siehe .env.example -> .env kopieren und befuellen.")
sys.exit(1)
hugo_build()
deploy_to_bunny(host, zone, password)
print("\nFertig! Seite ist live.")