Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75c9ced16f | ||
|
|
3600af1c6d | ||
|
|
d2c31901e1 | ||
|
|
95ca0108a0 | ||
|
|
0c9631de4d |
No files matched your search
+42
-1
@@ -10,6 +10,7 @@
|
||||
die Zugangsdaten als Gitea-Actions-Secrets/-Variablen."""
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@@ -24,6 +25,12 @@ from authentik_client.rest import ApiException
|
||||
DEFAULT_AUTHENTIK_URL = "https://auth.share-fix.de/api/v3"
|
||||
DEFAULT_GITEA_URL = "https://git.share-fix.de"
|
||||
DEFAULT_SERVER = "H1"
|
||||
SERVER_HOSTS = {
|
||||
"H1": "host-1.futcloud.de",
|
||||
"H2": "host-2.futcloud.de",
|
||||
}
|
||||
WORKFLOW_SOURCE = Path(__file__).resolve().parent / "examples" / "deploy.yml"
|
||||
WORKFLOW_TARGET = ".gitea/workflows/deploy.yml"
|
||||
HOME_DIR_BASE = "/home"
|
||||
USERNAME_RE = re.compile(r"^[a-z_][a-z0-9_-]{0,31}$")
|
||||
|
||||
@@ -58,6 +65,22 @@ class Gitea:
|
||||
raise
|
||||
self._request("POST", url, json={"value": value})
|
||||
|
||||
def create_file(self, repo_path: str, file_path: str, content: str, message: str) -> bool:
|
||||
"""Legt eine Datei im Default-Branch an. False, wenn sie bereits existiert."""
|
||||
url = f"/repos/{repo_path}/contents/{file_path}"
|
||||
try:
|
||||
self._request("GET", url)
|
||||
return False
|
||||
except requests.HTTPError as e:
|
||||
if e.response is None or e.response.status_code != 404:
|
||||
raise
|
||||
print(f"Creating {file_path} in {repo_path}")
|
||||
self._request("POST", url, json={
|
||||
"content": base64.b64encode(content.encode()).decode(),
|
||||
"message": message,
|
||||
})
|
||||
return True
|
||||
|
||||
|
||||
def normalize_repo_path(raw: str, gitea_url: str) -> str:
|
||||
"""Akzeptiert 'owner/repo', Web-URLs und Clone-URLs (mit/ohne .git)."""
|
||||
@@ -141,6 +164,11 @@ def parse_args() -> argparse.Namespace:
|
||||
p.add_argument("--docker-group",
|
||||
help="Gruppe für Docker-Deploys (Standard: server_<SERVER>_docker_compose)")
|
||||
p.add_argument("--no-docker-group", action="store_true", help="Docker-Deploy-Gruppe nicht zuweisen")
|
||||
p.add_argument("--deploy-host",
|
||||
help="Hostname des Zielservers für die Variable deploy_host "
|
||||
f"(Standard: Mapping {', '.join(f'{k}→{v}' for k, v in SERVER_HOSTS.items())})")
|
||||
p.add_argument("--no-workflow", action="store_true",
|
||||
help=f"{WORKFLOW_TARGET} nicht im Repo anlegen")
|
||||
p.add_argument("--authentik-url", default=DEFAULT_AUTHENTIK_URL)
|
||||
p.add_argument("--authentik-token", default=os.environ.get("AUTHENTIK_TOKEN"),
|
||||
help="Bearer-Token für die authentik-API (oder Env AUTHENTIK_TOKEN)")
|
||||
@@ -176,6 +204,9 @@ def main() -> int:
|
||||
|
||||
if not re.fullmatch(r"[A-Za-z0-9_-]+", args.server):
|
||||
sys.exit(f"Ungültiger Servername: '{args.server}'")
|
||||
deploy_host = args.deploy_host or SERVER_HOSTS.get(args.server)
|
||||
if not deploy_host:
|
||||
sys.exit(f"Kein Host für Server '{args.server}' bekannt (SERVER_HOSTS: {', '.join(SERVER_HOSTS)}); --deploy-host angeben")
|
||||
if not args.dry_run and not args.authentik_token:
|
||||
print(f"Authentik-API-Token erstellen unter {args.authentik_url.split('/api')[0]}/if/user/#/settings;page=page-tokens")
|
||||
args.authentik_token = getpass("Enter authentik token: ")
|
||||
@@ -204,7 +235,10 @@ def main() -> int:
|
||||
print(f"Home-Verz.: {home_dir}")
|
||||
print(f"Gruppen: {', '.join(group_names)}")
|
||||
print(f"Notes: {repo['html_url']}")
|
||||
print(f"Gitea-Secrets: deploy_user, deploy_pass")
|
||||
print("Gitea-Secrets: deploy_user, deploy_pass")
|
||||
print(f"Gitea-Variable: deploy_host={deploy_host}")
|
||||
if not args.no_workflow:
|
||||
print(f"Workflow: {WORKFLOW_TARGET} (direkt im Default-Branch, falls nicht vorhanden)")
|
||||
if args.dry_run:
|
||||
print("\n[dry-run] Es wurde nichts angelegt.")
|
||||
return 0
|
||||
@@ -222,7 +256,14 @@ def main() -> int:
|
||||
|
||||
try:
|
||||
gitea.set_variable(repo_path, "deploy_user", username)
|
||||
gitea.set_variable(repo_path, "deploy_host", deploy_host)
|
||||
gitea.set_secret(repo_path, "deploy_pass", key)
|
||||
# Zuletzt: der Commit löst den ersten Deploy aus, dafür muss alles gesetzt sein
|
||||
if not args.no_workflow:
|
||||
created = gitea.create_file(repo_path, WORKFLOW_TARGET, WORKFLOW_SOURCE.read_text(),
|
||||
"Deploy-Workflow hinzugefügt")
|
||||
if not created:
|
||||
print(f"{WORKFLOW_TARGET} existiert bereits, übersprungen")
|
||||
except requests.RequestException as e:
|
||||
sys.exit(f"Fehler in Gitea: {e}")
|
||||
|
||||
|
||||
+5
-3
@@ -1,12 +1,14 @@
|
||||
# Beispiel: .gitea/workflows/deploy.yml im Repo eines Dienstes
|
||||
#
|
||||
# Die eigentliche Logik liegt als Composite Action in diesem Repo (action.yml).
|
||||
# Die Version (@v1.0.0) wird von Renovate per PR aktualisiert (siehe renovate.json).
|
||||
# Die Version (@v1.0.1) wird von Renovate per PR aktualisiert (siehe renovate.json).
|
||||
#
|
||||
# Voraussetzungen (Setup mit create-deploy-user.py --project-path owner/repo):
|
||||
# Variable deploy_user - Deploy-User (wird vom Skript gesetzt)
|
||||
# Secret deploy_pass - Passwort/App-Token des Users (wird vom Skript gesetzt)
|
||||
# Variable deploy_host - Hostname/IP des Zielservers (manuell setzen)
|
||||
# Variable deploy_host - Hostname des Zielservers (wird vom Skript aus --server gesetzt)
|
||||
#
|
||||
# Das Skript legt diese Datei auch selbst als .gitea/workflows/deploy.yml im Repo an.
|
||||
#
|
||||
# Das Repo enthält docker-compose.yml (und optional docker-compose.override.yml)
|
||||
# im Wurzelverzeichnis; sie landen in ~/deployment auf dem Server.
|
||||
@@ -27,7 +29,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: https://git.share-fix.de/jochen/admin-toolsuite@v1.0.0
|
||||
- uses: https://git.share-fix.de/jochen/admin-toolsuite@v1.0.1
|
||||
with:
|
||||
deploy_user: ${{ vars.deploy_user }}
|
||||
deploy_host: ${{ vars.deploy_host }}
|
||||
|
||||
@@ -1,27 +1,66 @@
|
||||
# Beispiel: .gitea/workflows/renovate.yml (einmal zentral oder pro Repo)
|
||||
# .gitea/workflows/renovate.yaml
|
||||
# Liegt in einem eigenen Repo, z. B. "infra/renovate-bot".
|
||||
# Renovate findet per Autodiscover alle Repos, auf die der Bot-User Zugriff hat.
|
||||
#
|
||||
# Voraussetzungen:
|
||||
# Secret RENOVATE_TOKEN - Gitea-Token des Bot-Users (Rechte: repository r/w, issue r/w, user r)
|
||||
# Secret GITHUB_COM_TOKEN - optional, nur für Release-Notes/Rate-Limits von github.com
|
||||
# Voraussetzung: Secret RENOVATE_TOKEN (Gitea-Token des Bot-Users)
|
||||
|
||||
name: renovate
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 4 * * *"
|
||||
workflow_dispatch:
|
||||
- cron: "17 3 * * *" # täglich 03:17
|
||||
workflow_dispatch: # manuell auslösbar
|
||||
|
||||
concurrency:
|
||||
group: renovate
|
||||
cancel-in-progress: false # nie zwei Läufe parallel
|
||||
|
||||
jobs:
|
||||
renovate:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: renovate/renovate:latest
|
||||
container: ghcr.io/renovatebot/renovate:latest@sha256:823dc5036b911696c27faacf7664219b28e6e15826405720df29aad208d19f25
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- name: Renovate ausführen
|
||||
- name: Run Renovate
|
||||
run: renovate
|
||||
env:
|
||||
# --- Plattform ---
|
||||
RENOVATE_PLATFORM: gitea
|
||||
RENOVATE_ENDPOINT: https://git.share-fix.de/api/v1
|
||||
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
|
||||
GITHUB_COM_TOKEN: ${{ secrets.GITHUB_COM_TOKEN }}
|
||||
RENOVATE_GIT_AUTHOR: "Renovate Bot <4lzkkgpo@futmail.de>"
|
||||
|
||||
# --- Autodiscover ---
|
||||
RENOVATE_AUTODISCOVER: "true"
|
||||
# Nur bestimmte Orgs/Repos (Glob oder /Regex/), Rest ignorieren.
|
||||
|
||||
# --- Onboarding ---
|
||||
# Neue Repos bekommen einen Onboarding-PR mit dieser renovate.json.
|
||||
RENOVATE_ONBOARDING: "true"
|
||||
RENOVATE_ONBOARDING_CONFIG: >-
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": ["config:recommended", "docker:pinDigests"],
|
||||
"timezone": "Europe/Berlin",
|
||||
"schedule": ["before 6am"],
|
||||
"automerge": false,
|
||||
"packageRules": [
|
||||
{
|
||||
"matchDatasources": ["docker"],
|
||||
"matchUpdateTypes": ["patch", "digest"],
|
||||
"automerge": true
|
||||
},
|
||||
{
|
||||
"matchDatasources": ["docker"],
|
||||
"matchUpdateTypes": ["major"],
|
||||
"dependencyDashboardApproval": true
|
||||
}
|
||||
]
|
||||
}
|
||||
# Repos ohne gemergte renovate.json nicht anfassen (nur Onboarding-PR).
|
||||
RENOVATE_REQUIRE_CONFIG: required
|
||||
|
||||
# --- Grenzen & Logging ---
|
||||
RENOVATE_PR_HOURLY_LIMIT: "5"
|
||||
RENOVATE_PR_CONCURRENT_LIMIT: "15"
|
||||
LOG_LEVEL: info
|
||||
+16
-2
@@ -1,5 +1,19 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": ["config:recommended"],
|
||||
"enabledManagers": ["github-actions"]
|
||||
"extends": ["config:recommended", "docker:pinDigests"],
|
||||
"timezone": "Europe/Berlin",
|
||||
"schedule": ["before 6am"],
|
||||
"automerge": false,
|
||||
"packageRules": [
|
||||
{
|
||||
"matchDatasources": ["docker"],
|
||||
"matchUpdateTypes": ["patch", "digest"],
|
||||
"automerge": true
|
||||
},
|
||||
{
|
||||
"matchDatasources": ["docker"],
|
||||
"matchUpdateTypes": ["major"],
|
||||
"dependencyDashboardApproval": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user