summaryrefslogtreecommitdiff
path: root/podman_launch_devenv.py
diff options
context:
space:
mode:
authorhc <hc@email.ch>2025-06-25 19:40:43 +0800
committerhc <hc@email.ch>2025-06-25 19:40:43 +0800
commitccdde5f4424836fc8e9cc98c204510fed9612e70 (patch)
treedf1500f00b2f0b32b8729732454585c318b51110 /podman_launch_devenv.py
parentd6eb567da3e6d2e64ebf22adf1fc6d21c47090f8 (diff)
merged setup and contaienrs
Diffstat (limited to 'podman_launch_devenv.py')
-rwxr-xr-xpodman_launch_devenv.py53
1 files changed, 0 insertions, 53 deletions
diff --git a/podman_launch_devenv.py b/podman_launch_devenv.py
deleted file mode 100755
index 3d0b5b0..0000000
--- a/podman_launch_devenv.py
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/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")