make sure resources are set up in isolated namespaces (#1)
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
20
src/main.py
20
src/main.py
@@ -1,3 +1,4 @@
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
|
||||
import typer
|
||||
@@ -8,7 +9,7 @@ from rich.progress import BarColumn, Progress, SpinnerColumn, TaskProgressColumn
|
||||
from src.aws import s3 as s3_ops
|
||||
from src.commands import infra, train
|
||||
from src.commands.utils import CONFIG_OPT, load_cfg
|
||||
from src.config import Config
|
||||
from src.config import GENERATED_STACK_PREFIX, Config, InfraConfig, S3Config
|
||||
|
||||
app = typer.Typer(
|
||||
help="qc-cli: End-to-end model managment for Qualcomm AI Hub.",
|
||||
@@ -31,18 +32,27 @@ def init(
|
||||
console.print(f"[yellow]{dest} already exists.[/yellow] Use --force to overwrite.")
|
||||
raise typer.Exit(1)
|
||||
|
||||
config = Config()
|
||||
config = _new_isolated_config()
|
||||
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||
config_data = config.model_dump(mode="json")
|
||||
config_data["sagemaker"].pop("role_name", None)
|
||||
with open(dest, "w") as f:
|
||||
yaml.safe_dump(config.model_dump(mode="json"), f, sort_keys=False)
|
||||
yaml.safe_dump(config_data, f, sort_keys=False)
|
||||
|
||||
console.print(f"[green]✓[/green] Config written to [bold]{dest}[/bold]")
|
||||
console.print(
|
||||
"Edit it (especially [cyan]s3.bucket[/cyan] and [cyan]sagemaker.training.image_uri[/cyan]) "
|
||||
"before running other commands."
|
||||
"Edit [cyan]sagemaker.training.image_uri[/cyan] before running training commands."
|
||||
)
|
||||
|
||||
|
||||
def _new_isolated_config() -> Config:
|
||||
suffix = secrets.token_hex(6)
|
||||
namespace = f"{GENERATED_STACK_PREFIX}{suffix}"
|
||||
config = Config(infra=InfraConfig(stack_name=namespace))
|
||||
config.s3 = S3Config(bucket=f"{namespace}-data")
|
||||
return config
|
||||
|
||||
|
||||
@app.command()
|
||||
def upload(
|
||||
path: Path = typer.Argument(..., help="Local file or directory to upload"),
|
||||
|
||||
Reference in New Issue
Block a user