Skip to content

Commit 652e648

Browse files
committed
[REF] Adapted 'docky open' command for Docker Compose V2.
1 parent fe0fcf7 commit 652e648

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

docky/cmd/run_open.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

55
import sys
6+
import subprocess
67
from plumbum import cli
78
from .base import Docky, DockySub
89
from ..common.api import raise_error, logger
@@ -19,7 +20,10 @@ class DockyExec(DockySub):
1920
service = cli.SwitchAttr(["service"])
2021

2122
def _use_specific_user(self, service):
22-
return not self.root and self.project.get_user(service)
23+
user = self.project.get_user(service)
24+
if self.root:
25+
user = "root"
26+
return user
2327

2428
def _get_cmd_line(self, optionnal_command_line):
2529
user = self._use_specific_user(self.service)
@@ -81,7 +85,24 @@ class DockyOpen(DockyExec):
8185

8286
def _main(self, *optionnal_command_line):
8387
super()._main(*optionnal_command_line)
84-
self._exec("dcpatched", ["exec", "-e", "NOGOSU=True", self.service] + self.cmd)
88+
# self._exec("dcpatched", ["exec", "-e", "NOGOSU=True", self.service] + self.cmd)
89+
90+
# Get Project Name
91+
# Example: docky-odoo-brasil-14 odoo
92+
project_name = self.project.name + "-" + self.project.service
93+
94+
# Get User
95+
user = self._use_specific_user(self.service)
96+
97+
# Get Container ID
98+
command = "docker ps -aqf name=" + project_name
99+
# Example of return value
100+
# b'b5db9db21381\n'
101+
# Option text=true return as string instead of bytes and strip remove break line
102+
# TODO: Is there a better way to do it, for example with Plumbum?
103+
container_id = subprocess.check_output(command, shell=True,text=True).strip()
104+
105+
self._exec("docker", ["exec", "-u", user, "-it", container_id, "/bin/bash"])
85106

86107
@Docky.subcommand("system")
87108
class DockySystem(DockyExec):

0 commit comments

Comments
 (0)