This commit is contained in:
retoor 2025-06-11 01:21:21 +02:00
parent 1b2ad3965b
commit 5f06d7e04c
5 changed files with 105 additions and 13 deletions

View File

@ -10,3 +10,9 @@ RUN chmod +x r
RUN mv r /usr/local/bin/r
RUN echo 'root:root' | chpasswd
COPY ./terminal /opt/bootstrap
COPY ./terminal /opt/snek
RUN cp -r ./root /opt/bootrap/root
COPY ./terminal/entry /usr/local/bin/entry

View File

@ -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)

View File

@ -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,

47
terminal/.welcome.txt Normal file
View File

@ -0,0 +1,47 @@
πŸ‘‹ Welcome to your custom Ubuntu development environment!
This container is pre-configured with a rich set of tools to help you hit the ground running:
πŸ”§ Development Libraries & Tools:
Full support for building and debugging C/C++ and Python code
Libraries for SSL, readline, SQLite, zlib, bz2, ffi, lzma, and JSON-C
Valgrind for memory debugging and profiling
🐍 Python:
Python 3 with pip and virtual environment support (venv)
πŸ¦€ Rust:
Rust installed with the nightly toolchain via rustup
πŸ›  Command-line Essentials:
vim, tmux, htop, git, curl, wget, xterm, ack, and more
πŸ’¬ Networking & Communication:
irssi for IRC and lynx for browsing from the terminal
πŸ“¦ Custom Tool Installed:
Latest version of AI vibe coding tool r is installed from the
retoor.molodetz.nl repository.
To get started, open a new terminal and type "r" to launch the tool.
Configure ~/.rcontext.txt to describe it's behavior. It can be a friend
or a whatever you like.
πŸ” Credentials:
Default root password is set to: root (please change it if needed)
πŸ—‚ Custom Terminal Files:
Files from ./terminal/ have been copied to your home directory (/root/)
Enjoy hacking in your personalized command-line workspace!

26
terminal/entry Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import os
import sys
import pathlib
import os
os.chdir("/root")
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, "/root/bin")
sys.path.insert(0, "/root/bin/local/bin")
if not pathlib.Path(".welcome.txt").exists():
os.system("python3 -m venv --prompt '' .venv")
os.system("cp -r /opt/bootstrap/root/.* /root")
os.system("cp /opt/bootstrap/.welcome.txt /root/.welcome.txt")
pathlib.Path(".bashrc").write_text(pathlib.Path(".bashrc").read_text() + "\n" + "source .venv/bin/activate")
os.environ["SNEK"] = "1"
if pathlib.Path(".welcome.txt").exists():
with open(".welcome.txt") as f:
print(f.read())
os.system("bash")