Fixed some problems with this

This commit is contained in:
2026-07-28 13:44:42 +01:00
parent ebebd5d4a5
commit 290f074d74
7 changed files with 145 additions and 110 deletions
-32
View File
@@ -1,32 +0,0 @@
# restic actions registry
from playbook.action_registry import ActionRegistry
from playbook.models import StepLog
import sys
import json
import docker
import subprocess
from typing import List, Dict, Any, Tuple
dbpgactions = ActionRegistry("dbpg_actions_reg")
@dbpgactions.register(name="dump_pg_database", version="")
def dump_pg_database(ctx, name) -> StepLog:
return StepLog.ok(name, "")
# NOTE: this functions ought to be in their own registry, but I need inter
# registry communication to be possible first
###############################################################################
##### DOCKER FUNCTIONS ########################################################
@dbpgactions.register(name="get_service_container", version="")
def get_service_container(ctx, name) -> StepLog:
client = docker.from_env()
filters: Dict[str, Any]= {"label": [f"com.docker.compose.service=gitea-db"]}
print(client.containers.list(filters=filters, all=True), file=sys.stderr)
return StepLog.ok(name, "cool beans")
+21
View File
@@ -0,0 +1,21 @@
# restic actions registry
from playbook.action_registry import ActionRegistry
from playbook.models import StepLog
from playbook import ContextWrapper
from registry.docker_actions import dockeractions
import sys
import json
import docker
import subprocess
from typing import List, Dict, Any, Tuple
dbpgactions = ActionRegistry("dbpg_actions_reg")
@dbpgactions.register(name="dump_pg_database", version="")
def dump_pg_database(ctx, name) -> StepLog:
c = ContextWrapper(ctx)
return StepLog.ok(name, "")
+21
View File
@@ -0,0 +1,21 @@
from playbook.action_registry import ActionRegistry
from playbook.models import StepLog
import sys
import json
import docker
import subprocess
from typing import List, Dict, Any, Tuple
dockeractions = ActionRegistry("docker_actions_reg")
@dockeractions.register(name="get_service_container", version="")
def get_service_container(ctx, name) -> StepLog:
client = docker.from_env()
filters: Dict[str, Any]= {"label": [f"com.docker.compose.service=gitea-db"]}
print(client.containers.list(filters=filters, all=True), file=sys.stderr)
return StepLog.ok(name, "cool beans")
+7 -27
View File
@@ -114,7 +114,7 @@ def create_repo_if_not_exists(ctx, name: str = "") -> StepLog:
return StepLog.fail(name, [{"status": "failed", "output": log.error}])
# Create repo
repoCreateLog: StepLog = create_restic_repo(ctx, name + f".{create_restic_repo}")
repoCreateLog: StepLog = create_restic_repo(ctx, name + f".{create_restic_repo.__name__}")
if repoCreateLog.failed:
return StepLog.fail(name, [{"status": "failed", "output": repoCreateLog.error}])
msg = "repo created"
@@ -146,13 +146,10 @@ def check_if_repo_exists(ctx, name: str = "") -> StepLog:
@restic.register(name="backup_data_to_restic_repo", version="")
def backup_data_to_restic_repo(ctx, name) -> StepLog:
out = subprocess.run(
["restic", "backup", ctx["sourcePath"], "--json", "--quiet",
"-r", ctx["repoPath"], "--password-file", ctx["passwordFile"]],
text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
)
cmd = ["restic", "backup", ctx["sourcePath"], "--json", "--quiet",
"-r", ctx["repoPath"], "--password-file", ctx["passwordFile"]]
json_output: List[Dict[str, Any]] = parse_output(out.stdout)
returncode, json_output = run_restic_command(cmd)
errors: List[Dict[str, Any]] = find_restic_errors(json_output)
# Handle error messages in JSON output
@@ -160,24 +157,7 @@ def backup_data_to_restic_repo(ctx, name) -> StepLog:
return StepLog.fail(name, errors)
# Make sure the return code is good too
if out.returncode != 0:
return StepLog.fail(name, [{"status": "failed", "output": out.stdout}])
if returncode != 0:
return StepLog.fail(name, [{"status": "failed", "output": errors}])
# Return code is 0, so it was successful, output the message
try:
data = json.loads(out.stdout)
msg = data
except:
msg = {
"status": "ran succesfully, but an error occurred parsing the output",
"output": out.stdout,
}
return StepLog.ok(name, str(msg))
#-- BIG NOTE ------------------------------------------------------------------#
# I will use the restic registry for database actions until I make it so cross #
# registry calls with context are possible. But right now the yaml config #
# doesnt support that anyway. #
#------------------------------------------------------------------------------#
return StepLog.ok(name, "backup successful")