diff options
Diffstat (limited to 'containers/podman_launch_devenv.py')
| -rwxr-xr-x | containers/podman_launch_devenv.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/containers/podman_launch_devenv.py b/containers/podman_launch_devenv.py new file mode 100755 index 0000000..3d0b5b0 --- /dev/null +++ b/containers/podman_launch_devenv.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +""" +Rocky SSH Container Launcher + +Manual build command: + podman build -f docker_build/Dockerfile -t rocky_dev:latest . + +Usage: + python3 podman_launch_devenv.py # Build and launch container + python3 podman_launch_devenv.py --list # List running rocky-dev containers + python3 podman_launch_devenv.py --cleanup # Stop and remove all containers +""" +import subprocess, argparse, os, glob + +def run(cmd): return subprocess.run(cmd, shell=True, capture_output=True, text=True) + +def build(): + if not glob.glob("docker_build/ssh-keys/*.pub"): os.makedirs("docker_build/ssh-keys", exist_ok=True); open("docker_build/ssh-keys/dummy.pub", "w").write("# dummy") + result = run("podman build -f docker_build/Dockerfile -t rocky_dev:latest .") + if os.path.exists("docker_build/ssh-keys/dummy.pub"): os.remove("docker_build/ssh-keys/dummy.pub") + return result.returncode == 0 + +def launch(): + port = str(args.port) if args.port else run("shuf -i 10000-65000 -n 1").stdout.strip() + result = run(f"podman run -d -p {port}:22 --privileged --name rocky_dev-{port} rocky_dev:latest") + if result.returncode == 0: + ip = run("hostname -I | awk '{print $1}'").stdout.strip() or "localhost" + print(f"🐳 SSH: ssh root@{ip} -p {port}") + print(f"🐚 Shell: podman exec -it rocky_dev-{port} /bin/bash") + print(f"💡 Tip: For direct shell without port forwarding, use: podman run -it rocky_dev:latest /bin/bash") + return result.returncode == 0 + +parser = argparse.ArgumentParser(epilog=""" +Manual build commands: + Build: podman build -f docker_build/Dockerfile -t rocky_dev:latest . + Rebuild: podman rmi rocky_dev:latest && podman build -f docker_build/Dockerfile -t rocky_dev:latest . +""", formatter_class=argparse.RawDescriptionHelpFormatter) +parser.add_argument("command", nargs="?", choices=["run", "list", "cleanup"], help="Command to execute") +parser.add_argument("-p", "--port", type=int) +args = parser.parse_args() + +if args.command == "list": print(run("podman ps --filter name=rocky_dev").stdout or "No containers") +elif args.command == "cleanup": [run(f"podman stop {c} && podman rm {c}") for c in run("podman ps -a --filter name=rocky_dev --format '{{.Names}}'").stdout.split()] +elif args.command == "run": + if run("podman images -q rocky_dev").stdout: + print("found rocky_dev container! starting with a random public port to ssh... ") + launch() + else: + print("❌ Image rocky_dev:latest not found") +else: + print("Usage: python3 podman_launch_devenv.py {run|list|cleanup} [-p PORT]") + print("🐚 Shell: podman exec -it rocky_dev-<port> /bin/bash") + print("💡 Tip: For direct shell without port forwarding, use: podman run -it rocky_dev:latest /bin/bash") |
