Update.
This commit is contained in:
@@ -84,7 +84,7 @@ class ContainerService(BaseService):
|
||||
"./"
|
||||
+ str(await self.services.channel.get_home_folder(channel_uid))
|
||||
+ ":"
|
||||
+ "/home/ubuntu"
|
||||
+ "/root"
|
||||
],
|
||||
)
|
||||
return await self.compose.get_instance(name)
|
||||
|
||||
+25
-12
@@ -66,7 +66,9 @@ class ComposeFileManager:
|
||||
"context": ".",
|
||||
"dockerfile": "DockerfileUbuntu",
|
||||
},
|
||||
"user":"ubuntu"
|
||||
"user":"root",
|
||||
"working_dir": "/home/retoor/projects/snek",
|
||||
"environment": [f"SNEK_UID={name}"],
|
||||
}
|
||||
service["command"] = command or "tail -f /dev/null"
|
||||
if cpus or memory:
|
||||
@@ -165,14 +167,13 @@ class ComposeFileManager:
|
||||
stdout = b''
|
||||
stderr = str(ex).encode()
|
||||
await self.event_handler(name,"stdout",stdout or stderr)
|
||||
if proc.returncode != 0:
|
||||
raise RuntimeError(f"Failed to stop {name}: {stderr.decode()}")
|
||||
print("Return code", proc.returncode)
|
||||
if stdout:
|
||||
await self.event_handler(name,"stdout",stdout)
|
||||
return stdout.decode(errors="ignore")
|
||||
await self.event_handler(name,"stdout",stdout or b'')
|
||||
return stdout and stdout.decode(errors="ignore") or ""
|
||||
|
||||
await self.event_handler(name,"stdout",stderr)
|
||||
return stderr.decode(errors="ignore")
|
||||
await self.event_handler(name,"stdout",stderr or b'')
|
||||
return stderr and stderr.decode(errors="ignore") or ""
|
||||
|
||||
async def start(self, name):
|
||||
"""Asynchronously start a container by doing 'docker compose up -d [name]'."""
|
||||
@@ -187,15 +188,27 @@ class ComposeFileManager:
|
||||
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"docker", "compose", "-f", self.compose_path, "up", name, "-d",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
stdin=asyncio.subprocess.PIPE,
|
||||
)
|
||||
stdout,stderr = await proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
print(f"Failed to start {name}: {stderr.decode(errors='ignore')}")
|
||||
return False
|
||||
stdout, stderr = None, None
|
||||
while proc.returncode is None:
|
||||
try:
|
||||
stdout, stderr = await proc.communicate()
|
||||
except Exception as ex:
|
||||
stdout = b''
|
||||
stderr = str(ex).encode()
|
||||
if stdout:
|
||||
print(stdout.decode(errors="ignore"))
|
||||
if stderr:
|
||||
print(stderr.decode(errors="ignore"))
|
||||
await self.event_handler(name,"stdout",stdout or stderr)
|
||||
print("Return code", proc.returncode)
|
||||
|
||||
master, slave = pty.openpty()
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"docker", "compose", "-f", self.compose_path, "exec", name, "/bin/bash",
|
||||
"docker", "compose", "-f", self.compose_path, "exec", name, "/usr/local/bin/entry",
|
||||
stdin=slave,
|
||||
stdout=slave,
|
||||
stderr=slave,
|
||||
|
||||
Reference in New Issue
Block a user