add docker_volume_backupper service helper
This commit is contained in:
parent
ad618a0442
commit
074ffbd734
|
@ -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()
|
Loading…
Reference in New Issue