nandi/frqpublic Fork 0
5ce66d5b65a33704b80cac21d9c089bb5032953c
Commits
Clone
git clone https://git.rickub.com/nandi/frq.git
git clone ssh://git@rickub.com/nandi/frq.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

A third target, and the seam that was already waiting for it f54ca45 · on 5ce66d5b65a33704b80cac21d9c089bb5032953c · nandi · 2d ago
container.py · 44 lines · 1.7 KBPython Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Generated stub -- the container is defined by container.toml.

Edit container.toml, not this file.
"""

import os
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from _loader import Container  # noqa: E402

c = Container.from_toml(__file__)
image, app = c.image, c.app


# No @app.function here: a Sandbox runs its command as its own process and
# nothing of this module is imported into it. Registering a Function would be
# dead weight, and its kwargs are where vm_runtime would be wrongly applied.
# One entrypoint, not two: a second `@app.local_entrypoint` makes plain
# `modal run container.py` ambiguous, and Modal refuses it rather than
# picking. `--shell` is a flag on the one there is.
@app.local_entrypoint()
def main(command: str = "", shell: bool = False):
    if not shell:
        c.run_sandbox(command)
        return

    # `modal shell --image` only takes registry references, so it cannot be
    # pointed at a published Modal image like arch-nix. Attaching to a running
    # Sandbox can, and that Sandbox is this container: same image, same
    # volumes, same env.
    sb = c.open_sandbox()
    print(f"sandbox {sb.object_id} up, with {', '.join(c.volumes) or 'no volumes'}")
    print(f"  attach: modal shell {sb.object_id}   (from another terminal)")
    print("Ctrl-C here takes it down.")
    # Blocks on `sleep infinity`, which is the point: an ephemeral app stops
    # when its local entrypoint returns, and stopping the app terminates the
    # Sandbox with it -- so returning here would leave nothing to attach to.
    try:
        sb.wait()
    except KeyboardInterrupt:
        print("terminating")
        sb.terminate()