WIP
This commit is contained in:
parent
933e26b509
commit
9ad56d6c75
5 changed files with 78 additions and 20 deletions
plugins
roles/compose/tasks
|
@ -33,6 +33,8 @@ def recursive_update(
|
|||
default: dict[Any, Any],
|
||||
update: dict[Any, Any],
|
||||
) -> dict[Any, Any]:
|
||||
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])
|
||||
|
|
|
@ -28,17 +28,21 @@ def apply_base(state: State, params: dict[str, Any]) -> State:
|
|||
project_name: str = state.module.params["name"]
|
||||
|
||||
new: dict[str, Any] = {
|
||||
"container_name": f"{project_name}_{params["name"]}",
|
||||
"hostname": f"{project_name}_{params["name"]}",
|
||||
"container_name": f"{project_name}_{params['name']}",
|
||||
"hostname": f"{project_name}_{params['name']}",
|
||||
"image": params["image"],
|
||||
"restart": "unless-stopped",
|
||||
"environment": {},
|
||||
"labels": {},
|
||||
"volumes": [],
|
||||
"networks": {
|
||||
"networks": {
|
||||
"internal": None,
|
||||
},
|
||||
}
|
||||
} | (
|
||||
state.module.params.get("settings", {})
|
||||
.get("default_definition", {})
|
||||
.get(params["name"], {})
|
||||
)
|
||||
|
||||
return update(state, params, new)
|
||||
|
||||
|
@ -57,10 +61,15 @@ def apply_definition(state: State, params: dict[str, Any], definition: dict[str,
|
|||
|
||||
|
||||
def apply_settings(state: State, params: dict[str, Any]) -> State:
|
||||
update = (
|
||||
state.module.params.get("settings", {}).get("service_defaults", {}).get(params["name"], {})
|
||||
return update(
|
||||
state,
|
||||
params,
|
||||
(
|
||||
state.module.params.get("settings", {})
|
||||
.get("service_default_definitions", {})
|
||||
.get(params["name"], {})
|
||||
),
|
||||
)
|
||||
return update(state, params, update)
|
||||
|
||||
|
||||
def update(state: State, params: dict[str, Any], update: dict[str, Any]) -> State:
|
||||
|
@ -69,6 +78,14 @@ def update(state: State, params: dict[str, Any], update: dict[str, Any]) -> Stat
|
|||
|
||||
_ = recursive_update(project["services"][service_name], update)
|
||||
|
||||
# FIX: this silently throws out misconfigured volumes
|
||||
unique_volumes = {
|
||||
vol["target"]: vol
|
||||
for vol in project["services"][service_name].get("volumes", [])
|
||||
if "target" in vol
|
||||
}.values()
|
||||
|
||||
project["services"][service_name]["volumes"] = unique_volumes
|
||||
return replace(state, after=project)
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: compose
|
||||
|
@ -44,7 +46,7 @@ options:
|
|||
- Default definition for all containers.
|
||||
- Overwritten by per-service defaults.
|
||||
type: dict
|
||||
service_defaults:
|
||||
service_default_definitions:
|
||||
description:
|
||||
- Default definitions for each service
|
||||
type: dict
|
||||
|
@ -77,6 +79,39 @@ options:
|
|||
description:
|
||||
- Default definitions for Redis services.
|
||||
type: dict
|
||||
service_default_args:
|
||||
description:
|
||||
- Default arguments for each service helper
|
||||
type: dict
|
||||
suboptions:
|
||||
custom:
|
||||
description:
|
||||
- Default args for custom services.
|
||||
type: dict
|
||||
docker_in_docker:
|
||||
description:
|
||||
- Default args for docker in docker services.
|
||||
type: dict
|
||||
docker_socket_proxy:
|
||||
description:
|
||||
- Default args for docker socket proxy services.
|
||||
type: dict
|
||||
docker_volume_backupper:
|
||||
description:
|
||||
- Default args for docker volume backupper services.
|
||||
type: dict
|
||||
mariadb:
|
||||
description:
|
||||
- Default args for MariaDB services.
|
||||
type: dict
|
||||
postgres:
|
||||
description:
|
||||
- Default args for PostgreSQL services.
|
||||
type: dict
|
||||
redis:
|
||||
description:
|
||||
- Default args for Redis services.
|
||||
type: dict
|
||||
services:
|
||||
description:
|
||||
- Services to create in the project.
|
||||
|
@ -387,7 +422,6 @@ options:
|
|||
description:
|
||||
- Service definition to overwrite with.
|
||||
type: dict
|
||||
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
@ -455,13 +489,9 @@ def settings_spec() -> dict[str, Any]:
|
|||
settings: dict[str, Any] = {
|
||||
"type": "dict",
|
||||
"suboptions": {
|
||||
"default_definition": {
|
||||
"type": "dict",
|
||||
},
|
||||
"service_defaults": {
|
||||
"type": "dict",
|
||||
"suboptions": {},
|
||||
},
|
||||
"default_definition": {"type": "dict"},
|
||||
"service_default_args": {"type": "dict", "suboptions": {}},
|
||||
"service_default_definitions": {"type": "dict", "suboptions": {}},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -469,10 +499,19 @@ def settings_spec() -> dict[str, Any]:
|
|||
if module == "common":
|
||||
continue
|
||||
|
||||
settings["suboptions"]["service_defaults"]["suboptions"][module] = {
|
||||
settings["suboptions"]["service_default_definitions"]["suboptions"][module] = {
|
||||
"type": "dict",
|
||||
}
|
||||
|
||||
args = deepcopy(getattr(service, module).EXTRA_ARGS)
|
||||
for arg in args.values():
|
||||
arg.pop("required", None)
|
||||
|
||||
settings["suboptions"]["service_default_args"]["suboptions"][module] = {
|
||||
"type": "dict",
|
||||
"suboptions": args,
|
||||
}
|
||||
|
||||
return settings
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ output-format = "grouped"
|
|||
|
||||
[tool.ruff.lint]
|
||||
select = ["ALL"]
|
||||
ignore = ["ERA001", "TD002", "TD003", "INP001", "D100", "D101", "D103", "D104"]
|
||||
ignore = ["ERA001", "FIX002", "TD002", "TD003", "INP001", "D100", "D101", "D103", "D104"]
|
||||
|
||||
[tool.ruff.format]
|
||||
line-ending = "lf"
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
no_log: true
|
||||
when: >-
|
||||
ez_compose_state | default(None) == "present"
|
||||
and ez_compose_shared_registry_logins is defined
|
||||
and ez_compose_shared_registry_logins
|
||||
and ez_compose_registry_logins is defined
|
||||
and ez_compose_registry_logins
|
||||
|
||||
- name: Ensure shared networks exist
|
||||
community.docker.docker_network:
|
||||
|
|
Loading…
Add table
Reference in a new issue