WIP
This commit is contained in:
parent
2735859028
commit
5750a5a495
5 changed files with 150 additions and 30 deletions
31
.lazy.lua
Normal file
31
.lazy.lua
Normal file
|
@ -0,0 +1,31 @@
|
|||
local function find_table_with_value(tables, search_value)
|
||||
for _, tbl in ipairs(tables) do
|
||||
for _, value in pairs(tbl) do
|
||||
if value == search_value then
|
||||
return tbl
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
return {
|
||||
{
|
||||
"mfussenegger/nvim-dap",
|
||||
optional = true,
|
||||
config = function()
|
||||
local root = vim.lsp.get_clients()[1].root_dir
|
||||
table.insert(require("dap").configurations.python, {
|
||||
type = "python",
|
||||
request = "launch",
|
||||
name = "custom",
|
||||
program = root .. "/modules/compose.py",
|
||||
console = "integratedTerminal",
|
||||
pythonPath = os.getenv("VIRTUAL_ENV") .. "/bin/python",
|
||||
args = { root .. "/test.json" },
|
||||
justMyCode = false,
|
||||
})
|
||||
find_table_with_value(require("lazyvim.plugins.extras.dap.core"), "mfussenegger/nvim-dap").config()
|
||||
end,
|
||||
},
|
||||
}
|
|
@ -22,13 +22,18 @@ def recursive_update(
|
|||
default = copy.deepcopy(default)
|
||||
|
||||
for key in update: # noqa: PLC0206
|
||||
if isinstance(update[key], dict) and isinstance(default.get(key), dict):
|
||||
default[key] = recursive_update(default[key], update[key])
|
||||
if isinstance(update[key], dict) and (
|
||||
isinstance(default.get(key), dict) or default.get(key) is None
|
||||
):
|
||||
default[key] = recursive_update(default.get(key, {}), update[key])
|
||||
|
||||
elif isinstance(update[key], list) and isinstance(default.get(key), list):
|
||||
default_set = set(default[key])
|
||||
custom_set = set(update[key])
|
||||
default[key] = list(default_set.union(custom_set))
|
||||
elif isinstance(update[key], list) and (
|
||||
isinstance(default.get(key), list) or default.get(key) is None
|
||||
):
|
||||
# default_set = set(default.get(key, []))
|
||||
# custom_set = set(update[key])
|
||||
# default[key] = list(default_set.union(custom_set))
|
||||
default[key] = default.get(key, []).extend(update[key])
|
||||
|
||||
else:
|
||||
default[key] = update[key]
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# Copyright: (c) 2024, Luca Bilke <luca@bil.ke>
|
||||
# MIT License (see LICENSE)
|
||||
|
||||
# FIX: This entire library is broken and needs to be fixed
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
|
@ -46,16 +48,13 @@ def apply_base(state: State, params: dict[str, Any]) -> State:
|
|||
|
||||
|
||||
def apply_definition(state: State, params: dict[str, Any], definition: dict[str, Any]) -> State:
|
||||
service_name: str = params["name"]
|
||||
project = copy.deepcopy(state.after)
|
||||
services: dict[str, Any] = project["services"]
|
||||
service: dict[str, Any] = services[service_name]
|
||||
service: dict[str, Any] = services[params["name"]]
|
||||
|
||||
_ = recursive_update(service, definition)
|
||||
service = recursive_update(service, definition)
|
||||
|
||||
services.update({service_name: service})
|
||||
|
||||
return replace(state, after=project)
|
||||
return update(state, params, service)
|
||||
|
||||
|
||||
def apply_settings(state: State, params: dict[str, Any]) -> State:
|
||||
|
@ -70,22 +69,21 @@ def apply_settings(state: State, params: dict[str, Any]) -> State:
|
|||
|
||||
|
||||
def update(state: State, params: dict[str, Any], update: dict[str, Any]) -> State:
|
||||
service_name: str = params["name"]
|
||||
project = copy.deepcopy(state.after)
|
||||
|
||||
project["services"][service_name] = project["services"].get(service_name, {})
|
||||
_ = recursive_update(project["services"][service_name], update)
|
||||
|
||||
# FIX: this silently throws out misconfigured volumes
|
||||
unique_volumes = dict(
|
||||
{
|
||||
vol["target"]: vol
|
||||
for vol in project["services"][service_name].get("volumes", [])
|
||||
if "target" in vol
|
||||
}.values(),
|
||||
project["services"][params["name"]] = recursive_update(
|
||||
project["services"].get(params["name"], {}),
|
||||
update,
|
||||
)
|
||||
|
||||
project["services"][service_name]["volumes"] = unique_volumes
|
||||
new_definition = project["services"][params["name"]]
|
||||
new_volumes: list[dict[str, Any]] = new_definition.get("volumes") or []
|
||||
|
||||
# FIX: this silently throws out misconfigured volumes
|
||||
unique_volumes = list({vol["source"]: vol for vol in new_volumes if "target" in vol}.values())
|
||||
|
||||
project["services"][params["name"]]["volumes"] = unique_volumes
|
||||
|
||||
return replace(state, after=project)
|
||||
|
||||
|
||||
|
@ -97,11 +95,11 @@ def run_helper(
|
|||
if not params.get("name"):
|
||||
params["name"] = str.split(helper.__module__, ".")[-1]
|
||||
|
||||
if not params.get("overwrite"):
|
||||
params["overwrite"] = params.get("definition", {})
|
||||
if not (overwrite := params.get("overwrite")):
|
||||
overwrite = params.get("definition", {})
|
||||
|
||||
state = apply_base(state, params)
|
||||
state = apply_settings(state, params)
|
||||
state = helper(state, params)
|
||||
state = apply_definition(state, params, params["overwrite"])
|
||||
state = apply_definition(state, params, overwrite)
|
||||
return update_project(state)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
# ruff: noqa: E402
|
||||
|
||||
from __future__ import annotations
|
||||
from pprint import pp
|
||||
|
||||
# TODO: break this down per module
|
||||
# TODO: generate this by reassembling
|
||||
|
@ -485,10 +484,12 @@ def main() -> None:
|
|||
state = common.get_state(module)
|
||||
|
||||
for name, services_params in [(x, y) for x, y in module.params["services"].items() if y]:
|
||||
for service_params in services_params:
|
||||
for index, service_params in enumerate(services_params):
|
||||
service_params["_index"] = index
|
||||
helper = getattr(service, name).helper
|
||||
state = service.common.run_helper(state, service_params, helper)
|
||||
pp(state.after)
|
||||
|
||||
print("fuck")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
85
plugins/test.json
Normal file
85
plugins/test.json
Normal file
|
@ -0,0 +1,85 @@
|
|||
{
|
||||
"ANSIBLE_MODULE_ARGS": {
|
||||
"name": "taskwarrior",
|
||||
"project_dir": "/var/lib/ez_compose",
|
||||
"services": {
|
||||
"custom": [
|
||||
{
|
||||
"definition": {
|
||||
"image": "ghcr.io/gothenburgbitfactory/taskchampion-sync-server:main@sha256:4798edada4b264cdcc82f1c8ea2389cdd5cde02926f74b2361005438056f5729",
|
||||
"volumes": [
|
||||
{
|
||||
"source": "sync_data",
|
||||
"target": "/var/lib/taskchampion-sync-server",
|
||||
"type": "volume"
|
||||
}
|
||||
]
|
||||
},
|
||||
"label_helpers": {
|
||||
"docker_volume_backupper": {},
|
||||
"traefik_router": {
|
||||
"entrypoints": ["web-secure"],
|
||||
"rule": "Host(`taskwarrior-sync.snailed.de`)"
|
||||
}
|
||||
},
|
||||
"name": "sync"
|
||||
}
|
||||
],
|
||||
"docker_volume_backupper": [
|
||||
{
|
||||
"backup_volumes": ["sync_data"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"default_definition": {
|
||||
"environment": {
|
||||
"TZ": "Europe/Berlin"
|
||||
}
|
||||
},
|
||||
"label_default_args": {
|
||||
"traefik_router": {
|
||||
"certresolver": "letsencrypt"
|
||||
}
|
||||
},
|
||||
"service_default_args": {
|
||||
"docker_volume_backupper": {
|
||||
"archive": "/tank/docker-backups"
|
||||
}
|
||||
},
|
||||
"service_default_definitions": {
|
||||
"docker_volume_backupper": {
|
||||
"environment": {
|
||||
"BACKUP_CRON_EXPRESSION": "0 6 * * *",
|
||||
"BACKUP_RETENTION_DAYS": "7",
|
||||
"EXEC_FORWARD_OUTPUT": true,
|
||||
"GPG_PASSPHRASE": "UYi9wgpWKgZBep",
|
||||
"GZIP_PARALLELISM": "2",
|
||||
"NOTIFICATION_URLS": "smtp://root%40snaile.de:RzBNcz@5iq5gGw@tripoli.snaile.de:465/?FromAddress=root@snaile.de&ToAddresses=luca@bil.ke&Encryption=ImplicitTLS",
|
||||
"SSH_HOST_NAME": "u374707.your-storagebox.de",
|
||||
"SSH_PASSWORD": "8WHePPymUsPUaXeS",
|
||||
"SSH_PORT": "23",
|
||||
"SSH_REMOTE_PATH": "/home/docker-backups",
|
||||
"SSH_USER": "u374707-sub1"
|
||||
},
|
||||
"image": "offen/docker-volume-backup:v2.43.0"
|
||||
},
|
||||
"docker_in_docker": {
|
||||
"image": "docker:27.4.0-dind"
|
||||
},
|
||||
"mariadb": {
|
||||
"image": "mariadb:11.6.2"
|
||||
},
|
||||
"postgres": {
|
||||
"image": "postgres:16.6-alpine"
|
||||
},
|
||||
"redis": {
|
||||
"image": "redis:7.4.1-alpine"
|
||||
},
|
||||
"docker_socket_proxy": {
|
||||
"image": "tecnativa/docker-socket-proxy:0.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue