working
This commit is contained in:
54
src/docker_compose/compose/rendered.py
Normal file
54
src/docker_compose/compose/rendered.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import final
|
||||
|
||||
from docker_compose.cfg import ROOT
|
||||
from docker_compose.compose.compose import Compose
|
||||
|
||||
|
||||
@final
|
||||
@dataclass(slots=True)
|
||||
class Rendered(Compose):
|
||||
# @property
|
||||
# def org(self) -> str:
|
||||
# return self.cfg.org_data.org
|
||||
|
||||
@property
|
||||
def bind_vols(self) -> Iterator[Path]:
|
||||
root = str(ROOT)
|
||||
for app in self.services:
|
||||
for vol in app.volumes:
|
||||
path = self.cfg.render_all(vol.split(":", 1)[0])
|
||||
if not path.startswith(root):
|
||||
continue
|
||||
path = Path(path)
|
||||
if path.is_file():
|
||||
continue
|
||||
yield path
|
||||
|
||||
# @property
|
||||
# def missing_bind_vols(self) -> Iterator[Path]:
|
||||
# for path in self.bind_vols:
|
||||
# if path.exists():
|
||||
# continue
|
||||
# yield path
|
||||
|
||||
def mk_bind_vols(self) -> None:
|
||||
for path in self.bind_vols:
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def write_bind_vols(self) -> None:
|
||||
self.cfg.src_paths.volume_data.write(map(str, self.bind_vols))
|
||||
|
||||
@property
|
||||
def proxy_nets(self) -> Iterator[str]:
|
||||
for net in self.networks.proxys:
|
||||
yield self.cfg.render_all(net)
|
||||
|
||||
@property
|
||||
def as_rendered(self) -> str:
|
||||
return self.cfg.render(self.as_template)
|
||||
|
||||
def write(self) -> None:
|
||||
self.cfg.dest_paths.compose_file.write(self.as_rendered)
|
||||
Reference in New Issue
Block a user