canyonos 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: canyonos
3
+ Version: 0.1.0
4
+ Summary: CanyonOS CLI
5
+ Requires-Python: >=3.10
@@ -0,0 +1,3 @@
1
+ Lightweight CLI for CanyonOS
2
+
3
+ Serves as a thin API layer, connecting to the global controller container.
File without changes
@@ -0,0 +1,84 @@
1
+ """
2
+ Most of the commands will be executed by code in the canyonos container.
3
+ Anything executing in this CLI pertains to file/folder modification
4
+ """
5
+
6
+ import argparse
7
+
8
+ from canyonos.init import run_init
9
+
10
+
11
+ def cmd_init(args):
12
+ run_init()
13
+
14
+ def cmd_connect(args):
15
+ pass
16
+
17
+
18
+ def cmd_new_app(args):
19
+ pass
20
+
21
+ def cmd_build(args):
22
+ pass
23
+
24
+ # Executed in canyonos
25
+ def cmd_deploy(args):
26
+ pass
27
+
28
+ def cmd_clean(args):
29
+ pass
30
+
31
+ # Executed in canyonos
32
+ def cmd_sync(args):
33
+ pass
34
+
35
+ def cmd_config(args):
36
+ pass
37
+
38
+ def cmd_integrate(args):
39
+ pass
40
+
41
+ def cmd_doctor(args):
42
+ pass
43
+
44
+ # Executed in canyonos
45
+ def cmd_serve(args):
46
+ pass
47
+
48
+ # Executed in canyonos
49
+ def cmd_test(args):
50
+ pass
51
+
52
+ # Executed in canyonos
53
+ def cmd_mega_build(args):
54
+ pass
55
+
56
+
57
+ def main():
58
+ parser = argparse.ArgumentParser(prog="canyonos")
59
+ subparsers = parser.add_subparsers(dest="command")
60
+
61
+ subparsers.add_parser("new-app").set_defaults(func=cmd_new_app)
62
+ subparsers.add_parser("build").set_defaults(func=cmd_build)
63
+ subparsers.add_parser("deploy").set_defaults(func=cmd_deploy)
64
+ subparsers.add_parser("clean").set_defaults(func=cmd_clean)
65
+ subparsers.add_parser("init").set_defaults(func=cmd_init)
66
+ subparsers.add_parser("connect").set_defaults(func=cmd_connect)
67
+ subparsers.add_parser("sync").set_defaults(func=cmd_sync)
68
+ subparsers.add_parser("config").set_defaults(func=cmd_config)
69
+ subparsers.add_parser("integrate").set_defaults(func=cmd_integrate)
70
+ subparsers.add_parser("doctor").set_defaults(func=cmd_doctor)
71
+ subparsers.add_parser("serve").set_defaults(func=cmd_serve)
72
+ subparsers.add_parser("test").set_defaults(func=cmd_test)
73
+ subparsers.add_parser("mega-build").set_defaults(func=cmd_mega_build)
74
+
75
+ args = parser.parse_args()
76
+ if not getattr(args, "command", None):
77
+ parser.print_help()
78
+ return
79
+
80
+ args.func(args)
81
+
82
+
83
+ if __name__ == "__main__":
84
+ main()
@@ -0,0 +1,71 @@
1
+ """
2
+ Logic for `canyonos init`, does the following:
3
+ 1. Pull the Global Controller image
4
+ 2. Start a container from it
5
+ 3. Record where it's listening so cli knows where to send requests.
6
+ """
7
+
8
+ import json
9
+ import os
10
+ import subprocess
11
+
12
+ # Image Name, need to switch to CanyonCore Organization Namespace later
13
+ GC_IMAGE = "saakeths/canyonos:latest"
14
+ GC_CONTAINER_PORT = 8000
15
+
16
+ STATE_DIR = os.path.expanduser("~/.canyonos")
17
+ STATE_PATH = os.path.join(STATE_DIR, "state.json")
18
+
19
+
20
+ def pull_image(image=GC_IMAGE):
21
+ subprocess.run(["docker", "pull", image], check=True)
22
+
23
+
24
+ def run_container(image=GC_IMAGE, max_attempts=50):
25
+ port = GC_CONTAINER_PORT
26
+ for _ in range(max_attempts):
27
+ result = subprocess.run(
28
+ [
29
+ "docker",
30
+ "run",
31
+ "-d",
32
+ "-p",
33
+ f"127.0.0.1:{port}:{GC_CONTAINER_PORT}",
34
+ # Docker-outside-of-Docker: GC shells out to `docker` to launch
35
+ # Redis/agent containers, so it needs the host's real daemon,
36
+ # not a nested one.
37
+ "-v",
38
+ "/var/run/docker.sock:/var/run/docker.sock",
39
+ "--add-host=host.docker.internal:host-gateway",
40
+ "-e",
41
+ "VENTIS_REDIS_HOST=host.docker.internal",
42
+ image,
43
+ ],
44
+ capture_output=True,
45
+ text=True,
46
+ )
47
+ if result.returncode == 0:
48
+ return result.stdout.strip(), port
49
+ if "port is already allocated" in result.stderr:
50
+ port += 1
51
+ continue
52
+ raise RuntimeError(result.stderr)
53
+ raise RuntimeError(f"no free port found after {max_attempts} attempts starting at {GC_CONTAINER_PORT}")
54
+
55
+
56
+ def save_state(container_id, port):
57
+ os.makedirs(STATE_DIR, exist_ok=True)
58
+ with open(STATE_PATH, "w") as f:
59
+ json.dump({"container_id": container_id, "port": port}, f)
60
+
61
+
62
+ def load_state():
63
+ with open(STATE_PATH) as f:
64
+ return json.load(f)
65
+
66
+
67
+ def run_init():
68
+ pull_image()
69
+ container_id, port = run_container()
70
+ save_state(container_id, port)
71
+ print(f"Global Controller running in container {container_id[:12]} on port {port}")
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: canyonos
3
+ Version: 0.1.0
4
+ Summary: CanyonOS CLI
5
+ Requires-Python: >=3.10
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ canyonos/__init__.py
4
+ canyonos/cli.py
5
+ canyonos/init.py
6
+ canyonos.egg-info/PKG-INFO
7
+ canyonos.egg-info/SOURCES.txt
8
+ canyonos.egg-info/dependency_links.txt
9
+ canyonos.egg-info/entry_points.txt
10
+ canyonos.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ canyonos = canyonos.cli:main
@@ -0,0 +1 @@
1
+ canyonos
@@ -0,0 +1,15 @@
1
+ [project]
2
+ name = "canyonos"
3
+ version = "0.1.0"
4
+ description = "CanyonOS CLI"
5
+ requires-python = ">=3.10"
6
+
7
+ [project.scripts]
8
+ canyonos = "canyonos.cli:main"
9
+
10
+ [build-system]
11
+ requires = ["setuptools>=64"]
12
+ build-backend = "setuptools.build_meta"
13
+
14
+ [tool.setuptools.packages.find]
15
+ include = ["canyonos*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+