add docker_volume_backupper service helper

This commit is contained in:
Luca Bilke 2024-10-22 22:23:55 +02:00
parent ad618a0442
commit 074ffbd734
No known key found for this signature in database
GPG Key ID: C9E851809C1A5BDE
1 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,79 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2024, Luca Bilke <luca@bil.ke>
# MIT License (see LICENSE)
# TODO: write ansible sections
DOCUMENTATION = r"""
"""
EXAMPLES = r"""
"""
RETURN = r"""
"""
from __future__ import annotations # pyright: ignore[reportGeneralTypeIssues]
from ansible_collections.snailed.ez_compose.plugins.module_utils.common import (
State,
run_service,
update_service,
)
def helper(state: State) -> State:
archive = state.module.params.get("archive")
backup_volumes = state.module.params.get("backup_volumes", [])
name = state.module.params["name"]
project_name = state.module.params["project_name"]
volumes = [
{
"type": "volume",
"source": volume,
"target": f"/backup/{volume}",
"read_only": True,
}
for volume in backup_volumes
]
environment = {
"BACKUP_FILENAME": f"{project_name}-%Y-%m-%dT%H-%M-%S.{'{{ .Extension }}'}",
"BACKUP_LATEST_SYMLINK": f"{project_name}-latest",
"BACKUP_PRUNING_PREFIX": f"{project_name}-",
"BACKUP_STOP_DURING_BACKUP_LABEL": project_name,
"BACKUP_ARCHIVE": "/archive",
"DOCKER_HOST": f"tcp://{project_name}_{name}_socket_proxy:2375",
}
if archive:
volumes.append(
{
"type": "bind",
"source": f"{archive}/{project_name}",
"target": "/archive",
"bind": {"create_host_path": True},
}
)
update = {
"environment": environment,
"volumes": volumes,
}
return update_service(state, update)
def main():
extra_args = {
"archive": {"type": "str"},
"backup_volumes": {"type": "list"},
}
run_service(extra_args, helper)
if __name__ == "__main__":
main()