@docker_app.command(
context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
help="Build a Docker image for the FastAgency app",
)
def build(
build_context: Annotated[
str,
typer.Argument(
...,
help="Docker build context",
),
] = ".",
*,
file: Annotated[
str,
typer.Option(
"--file",
"-f",
help="Name of the Dockerfile",
),
] = "docker/Dockerfile",
tag: Annotated[
str,
typer.Option(
"--tag",
"-t",
help='Name and optionally a tag (format: "name:tag")',
),
] = "deploy_fastagency",
progress: Annotated[
str,
typer.Option(
"--progress",
help="Set type of progress output (auto, plain, tty, rawjson).",
),
] = "plain",
ctx: typer.Context,
) -> None:
command = [
"docker",
"build",
"-t",
tag,
"-f",
file,
"--progress",
progress,
build_context,
]
command += ctx.args
typer.echo(
f"Building FastAgency Docker image with the command: {' '.join(command)}"
)
try:
# Run the docker build command
result = subprocess.run( # nosec B603
command, check=True, capture_output=True, text=True
)
typer.echo(result.stdout)
typer.echo(f"Image '{tag}' built successfully!")
except subprocess.CalledProcessError as e:
typer.echo(f"Error: {e.stderr}", err=True)
raise typer.Exit(code=1) from e