diff options
Diffstat (limited to 'containers/podman_launch_devenv.py')
| -rwxr-xr-x | containers/podman_launch_devenv.py | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/containers/podman_launch_devenv.py b/containers/podman_launch_devenv.py deleted file mode 100755 index 3d0b5b0..0000000 --- a/containers/podman_launch_devenv.py +++ /dev/null | |||
| @@ -1,53 +0,0 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | """ | ||
| 3 | Rocky SSH Container Launcher | ||
| 4 | |||
| 5 | Manual build command: | ||
| 6 | podman build -f docker_build/Dockerfile -t rocky_dev:latest . | ||
| 7 | |||
| 8 | Usage: | ||
| 9 | python3 podman_launch_devenv.py # Build and launch container | ||
| 10 | python3 podman_launch_devenv.py --list # List running rocky-dev containers | ||
| 11 | python3 podman_launch_devenv.py --cleanup # Stop and remove all containers | ||
| 12 | """ | ||
| 13 | import subprocess, argparse, os, glob | ||
| 14 | |||
| 15 | def run(cmd): return subprocess.run(cmd, shell=True, capture_output=True, text=True) | ||
| 16 | |||
| 17 | def build(): | ||
| 18 | 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") | ||
| 19 | result = run("podman build -f docker_build/Dockerfile -t rocky_dev:latest .") | ||
| 20 | if os.path.exists("docker_build/ssh-keys/dummy.pub"): os.remove("docker_build/ssh-keys/dummy.pub") | ||
| 21 | return result.returncode == 0 | ||
| 22 | |||
| 23 | def launch(): | ||
| 24 | port = str(args.port) if args.port else run("shuf -i 10000-65000 -n 1").stdout.strip() | ||
| 25 | result = run(f"podman run -d -p {port}:22 --privileged --name rocky_dev-{port} rocky_dev:latest") | ||
| 26 | if result.returncode == 0: | ||
| 27 | ip = run("hostname -I | awk '{print $1}'").stdout.strip() or "localhost" | ||
| 28 | print(f"🐳 SSH: ssh root@{ip} -p {port}") | ||
| 29 | print(f"🐚 Shell: podman exec -it rocky_dev-{port} /bin/bash") | ||
| 30 | print(f"💡 Tip: For direct shell without port forwarding, use: podman run -it rocky_dev:latest /bin/bash") | ||
| 31 | return result.returncode == 0 | ||
| 32 | |||
| 33 | parser = argparse.ArgumentParser(epilog=""" | ||
| 34 | Manual build commands: | ||
| 35 | Build: podman build -f docker_build/Dockerfile -t rocky_dev:latest . | ||
| 36 | Rebuild: podman rmi rocky_dev:latest && podman build -f docker_build/Dockerfile -t rocky_dev:latest . | ||
| 37 | """, formatter_class=argparse.RawDescriptionHelpFormatter) | ||
| 38 | parser.add_argument("command", nargs="?", choices=["run", "list", "cleanup"], help="Command to execute") | ||
| 39 | parser.add_argument("-p", "--port", type=int) | ||
| 40 | args = parser.parse_args() | ||
| 41 | |||
| 42 | if args.command == "list": print(run("podman ps --filter name=rocky_dev").stdout or "No containers") | ||
| 43 | 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()] | ||
| 44 | elif args.command == "run": | ||
| 45 | if run("podman images -q rocky_dev").stdout: | ||
| 46 | print("found rocky_dev container! starting with a random public port to ssh... ") | ||
| 47 | launch() | ||
| 48 | else: | ||
| 49 | print("❌ Image rocky_dev:latest not found") | ||
| 50 | else: | ||
| 51 | print("Usage: python3 podman_launch_devenv.py {run|list|cleanup} [-p PORT]") | ||
| 52 | print("🐚 Shell: podman exec -it rocky_dev-<port> /bin/bash") | ||
| 53 | print("💡 Tip: For direct shell without port forwarding, use: podman run -it rocky_dev:latest /bin/bash") | ||
