|
1 | 1 | import json
|
2 | 2 | import logging
|
| 3 | +import os |
3 | 4 | import shlex
|
4 | 5 | from dataclasses import dataclass, field
|
5 | 6 | from pathlib import Path
|
@@ -39,6 +40,10 @@ class PodmanOptions(CoreNodeOptions):
|
39 | 40 | """
|
40 | 41 | Path to a compose file, if one should be used for this node.
|
41 | 42 | """
|
| 43 | + compose_name: str = None |
| 44 | + """ |
| 45 | + Service name to start, within the provided compose file. |
| 46 | + """ |
42 | 47 |
|
43 | 48 |
|
44 | 49 | @dataclass
|
@@ -82,6 +87,7 @@ def __init__(
|
82 | 87 | super().__init__(session, _id, name, server, options)
|
83 | 88 | self.image: str = options.image
|
84 | 89 | self.compose: Optional[str] = options.compose
|
| 90 | + self.compose_name: Optional[str] = options.compose_name |
85 | 91 | self.binds: list[tuple[str, str]] = options.binds
|
86 | 92 | self.volumes: dict[str, VolumeMount] = {}
|
87 | 93 | for src, dst, unique, delete in options.volumes:
|
@@ -157,14 +163,21 @@ def startup(self) -> None:
|
157 | 163 | self.makenodedir()
|
158 | 164 | hostname = self.name.replace("_", "-")
|
159 | 165 | if self.compose:
|
160 |
| - data = self.host_cmd(f"cat {self.compose}") |
| 166 | + if not self.compose_name: |
| 167 | + raise CoreError( |
| 168 | + "a compose name is required when using a compose file" |
| 169 | + ) |
| 170 | + compose_path = os.path.expandvars(self.compose) |
| 171 | + data = self.host_cmd(f"cat {compose_path}") |
161 | 172 | template = Template(data)
|
162 | 173 | rendered = template.render_unicode(node=self, hostname=hostname)
|
163 | 174 | rendered = rendered.replace('"', r"\"")
|
164 | 175 | rendered = "\\n".join(rendered.splitlines())
|
165 | 176 | compose_path = self.directory / "podman-compose.yml"
|
166 | 177 | self.host_cmd(f'printf "{rendered}" >> {compose_path}', shell=True)
|
167 |
| - self.host_cmd(f"{PODMAN_COMPOSE} up -d", cwd=self.directory) |
| 178 | + self.host_cmd( |
| 179 | + f"{PODMAN_COMPOSE} up -d {self.compose_name}", cwd=self.directory |
| 180 | + ) |
168 | 181 | else:
|
169 | 182 | # setup commands for creating bind/volume mounts
|
170 | 183 | binds = ""
|
|
0 commit comments