mirror of
https://github.com/Monadical-SAS/cubbi.git
synced 2025-12-20 20:29:06 +00:00
feat(cli): auto mount current directory as /app
This commit is contained in:
@@ -24,7 +24,14 @@ def main(ctx: typer.Context) -> None:
|
|||||||
"""Monadical Container Tool"""
|
"""Monadical Container Tool"""
|
||||||
# If no command is specified, create a session
|
# If no command is specified, create a session
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
create_session(driver=None, project=None, env=[], name=None, no_connect=False)
|
create_session(
|
||||||
|
driver=None,
|
||||||
|
project=None,
|
||||||
|
env=[],
|
||||||
|
name=None,
|
||||||
|
no_connect=False,
|
||||||
|
no_mount=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
@@ -96,6 +103,9 @@ def create_session(
|
|||||||
no_connect: bool = typer.Option(
|
no_connect: bool = typer.Option(
|
||||||
False, "--no-connect", help="Don't automatically connect to the session"
|
False, "--no-connect", help="Don't automatically connect to the session"
|
||||||
),
|
),
|
||||||
|
no_mount: bool = typer.Option(
|
||||||
|
False, "--no-mount", help="Don't mount local directory to /app"
|
||||||
|
),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create a new MC session"""
|
"""Create a new MC session"""
|
||||||
# Use default driver if not specified
|
# Use default driver if not specified
|
||||||
@@ -119,6 +129,7 @@ def create_session(
|
|||||||
project=project,
|
project=project,
|
||||||
environment=environment,
|
environment=environment,
|
||||||
session_name=name,
|
session_name=name,
|
||||||
|
mount_local=not no_mount,
|
||||||
)
|
)
|
||||||
|
|
||||||
if session:
|
if session:
|
||||||
@@ -223,10 +234,18 @@ def quick_create(
|
|||||||
no_connect: bool = typer.Option(
|
no_connect: bool = typer.Option(
|
||||||
False, "--no-connect", help="Don't automatically connect to the session"
|
False, "--no-connect", help="Don't automatically connect to the session"
|
||||||
),
|
),
|
||||||
|
no_mount: bool = typer.Option(
|
||||||
|
False, "--no-mount", help="Don't mount local directory to /app"
|
||||||
|
),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create a new MC session with a project repository"""
|
"""Create a new MC session with a project repository"""
|
||||||
create_session(
|
create_session(
|
||||||
driver=driver, project=project, env=env, name=name, no_connect=no_connect
|
driver=driver,
|
||||||
|
project=project,
|
||||||
|
env=env,
|
||||||
|
name=name,
|
||||||
|
no_connect=no_connect,
|
||||||
|
no_mount=no_mount,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -89,8 +89,17 @@ class ContainerManager:
|
|||||||
project: Optional[str] = None,
|
project: Optional[str] = None,
|
||||||
environment: Optional[Dict[str, str]] = None,
|
environment: Optional[Dict[str, str]] = None,
|
||||||
session_name: Optional[str] = None,
|
session_name: Optional[str] = None,
|
||||||
|
mount_local: bool = True,
|
||||||
) -> Optional[Session]:
|
) -> Optional[Session]:
|
||||||
"""Create a new MC session"""
|
"""Create a new MC session
|
||||||
|
|
||||||
|
Args:
|
||||||
|
driver_name: The name of the driver to use
|
||||||
|
project: Optional project repository URL
|
||||||
|
environment: Optional environment variables
|
||||||
|
session_name: Optional session name
|
||||||
|
mount_local: Whether to mount the current directory to /app
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
# Validate driver exists
|
# Validate driver exists
|
||||||
driver = self.config_manager.get_driver(driver_name)
|
driver = self.config_manager.get_driver(driver_name)
|
||||||
@@ -116,6 +125,16 @@ class ContainerManager:
|
|||||||
print(f"Pulling image {driver.image}...")
|
print(f"Pulling image {driver.image}...")
|
||||||
self.client.images.pull(driver.image)
|
self.client.images.pull(driver.image)
|
||||||
|
|
||||||
|
# Set up volume mounts
|
||||||
|
volumes = {}
|
||||||
|
if mount_local:
|
||||||
|
# Mount current directory to /app in the container
|
||||||
|
import os
|
||||||
|
|
||||||
|
current_dir = os.getcwd()
|
||||||
|
volumes[current_dir] = {"bind": "/app", "mode": "rw"}
|
||||||
|
print(f"Mounting local directory {current_dir} to /app")
|
||||||
|
|
||||||
# Create container
|
# Create container
|
||||||
container = self.client.containers.create(
|
container = self.client.containers.create(
|
||||||
image=driver.image,
|
image=driver.image,
|
||||||
@@ -125,6 +144,7 @@ class ContainerManager:
|
|||||||
tty=True,
|
tty=True,
|
||||||
stdin_open=True,
|
stdin_open=True,
|
||||||
environment=env_vars,
|
environment=env_vars,
|
||||||
|
volumes=volumes,
|
||||||
labels={
|
labels={
|
||||||
"mc.session": "true",
|
"mc.session": "true",
|
||||||
"mc.session.id": session_id,
|
"mc.session.id": session_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user