Skip to content

Commit

Permalink
daemon/gui: fixed podman to leverage a service name when running comp…
Browse files Browse the repository at this point in the history
…ose files to match docker, updated docker/podman to expand path for compose files, updated gui to disable compose file related fields when running
  • Loading branch information
bharnden committed Feb 27, 2024
1 parent 2e8bf71 commit a5d0c70
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
14 changes: 11 additions & 3 deletions daemon/core/gui/dialogs/nodeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,22 @@ def draw(self) -> None:
compose_frame.columnconfigure(0, weight=2)
compose_frame.columnconfigure(1, weight=1)
compose_frame.columnconfigure(2, weight=1)
entry = ttk.Entry(compose_frame, textvariable=self.compose_file)
entry = ttk.Entry(
compose_frame, textvariable=self.compose_file, state=state
)
entry.grid(row=0, column=0, sticky=tk.EW, padx=PADX)
button = ttk.Button(
compose_frame, text="Compose File", command=self.click_compose
compose_frame,
text="Compose File",
command=self.click_compose,
state=state,
)
button.grid(row=0, column=1, sticky=tk.EW, padx=PADX)
button = ttk.Button(
compose_frame, text="Clear", command=self.click_compose_clear
compose_frame,
text="Clear",
command=self.click_compose_clear,
state=state,
)
button.grid(row=0, column=2, sticky=tk.EW)
compose_frame.grid(
Expand Down
3 changes: 2 additions & 1 deletion daemon/core/nodes/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def startup(self) -> None:
raise CoreError(
"a compose name is required when using a compose file"
)
data = self.host_cmd(f"cat {self.compose}")
compose_path = os.path.expandvars(self.compose)
data = self.host_cmd(f"cat {compose_path}")
template = Template(data)
rendered = template.render_unicode(node=self, hostname=hostname)
rendered = rendered.replace('"', r"\"")
Expand Down
17 changes: 15 additions & 2 deletions daemon/core/nodes/podman.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import os
import shlex
from dataclasses import dataclass, field
from pathlib import Path
Expand Down Expand Up @@ -39,6 +40,10 @@ class PodmanOptions(CoreNodeOptions):
"""
Path to a compose file, if one should be used for this node.
"""
compose_name: str = None
"""
Service name to start, within the provided compose file.
"""


@dataclass
Expand Down Expand Up @@ -82,6 +87,7 @@ def __init__(
super().__init__(session, _id, name, server, options)
self.image: str = options.image
self.compose: Optional[str] = options.compose
self.compose_name: Optional[str] = options.compose_name
self.binds: list[tuple[str, str]] = options.binds
self.volumes: dict[str, VolumeMount] = {}
for src, dst, unique, delete in options.volumes:
Expand Down Expand Up @@ -157,14 +163,21 @@ def startup(self) -> None:
self.makenodedir()
hostname = self.name.replace("_", "-")
if self.compose:
data = self.host_cmd(f"cat {self.compose}")
if not self.compose_name:
raise CoreError(
"a compose name is required when using a compose file"
)
compose_path = os.path.expandvars(self.compose)
data = self.host_cmd(f"cat {compose_path}")
template = Template(data)
rendered = template.render_unicode(node=self, hostname=hostname)
rendered = rendered.replace('"', r"\"")
rendered = "\\n".join(rendered.splitlines())
compose_path = self.directory / "podman-compose.yml"
self.host_cmd(f'printf "{rendered}" >> {compose_path}', shell=True)
self.host_cmd(f"{PODMAN_COMPOSE} up -d", cwd=self.directory)
self.host_cmd(
f"{PODMAN_COMPOSE} up -d {self.compose_name}", cwd=self.directory
)
else:
# setup commands for creating bind/volume mounts
binds = ""
Expand Down

0 comments on commit a5d0c70

Please sign in to comment.