Skip to content

CLI

builder

create(path='./', port=None, tag=None)

Auto-builds Docker image for chitra ModelServer

Parameters:

Name Type Description Default
path str

file-location of main.py

'./'
port Optional[str]

port to expose

None
tag Optional[str]

tag of docker image

None
Source code in chitra/cli/builder.py
@app.command()
def create(
    path: str = "./",
    port: Optional[str] = None,
    tag: Optional[str] = None,
):
    """
    Auto-builds Docker image for chitra ModelServer

    Args:

        path: file-location of main.py

        port: port to expose

        tag: tag of docker image

    """
    if not port:
        port = "8080"
    if not tag:
        tag = "chitra-server"

    path = Path(path)
    files = glob(str(path / "*"))
    file_check(files)
    style_path = typer.style(str(path), fg=typer.colors.GREEN)
    typer.echo(f"Everything under {style_path} will be added to Docker image!")
    show_files = typer.confirm("Do you wish to see the files to be added?")
    if show_files:
        typer.echo(files)

    dockerfile = get_dockerfile()
    dockerfile = dockerfile.replace("PORT", port)
    if typer.confirm("Show Dockerfile"):
        typer.echo(dockerfile)
    text_to_file(dockerfile, "Dockerfile")

    typer.echo(f"Building Docker {tag} 🐳")
    cmd = f"docker build --tag {tag} ."
    cmd = shlex.split(cmd)
    process = subprocess.run(cmd, stdout=subprocess.PIPE, universal_newlines=True)
    if process.returncode == 0:
        typer.secho(
            "Docker image has been created for your app! Check the image using ",
            nl=False,
            fg=typer.colors.GREEN,
        )
        typer.secho("docker images", fg=typer.colors.BRIGHT_BLUE)
    else:
        typer.secho("Docker build failed!", fg=typer.colors.RED)

Last update: November 27, 2021