Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --network-mode option #734

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/ramalama-bench.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ URL support means if a model is on a web site or even on your local system, you
#### **--help**, **-h**
show this help message and exit

#### **--network-mode**=*none*
set the network mode for the container

## DESCRIPTION
Benchmark specified AI Model.

Expand Down
3 changes: 3 additions & 0 deletions docs/ramalama-convert.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ The model can be from RamaLama model storage in Huggingface, Ollama, or local mo
#### **--help**, **-h**
Print usage message

#### **--network-mode**=*none*
sets the configuration for network namespaces when handling RUN instructions

#### **--type**=*raw* | *car*

type of OCI Model Image to convert.
Expand Down
3 changes: 3 additions & 0 deletions docs/ramalama-push.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ path of the authentication file for OCI registries
#### **--help**, **-h**
Print usage message

#### **--network-mode**=*none*
sets the configuration for network namespaces when handling RUN instructions

#### **--tls-verify**=*true*
require HTTPS and verify certificates when contacting OCI registries

Expand Down
3 changes: 3 additions & 0 deletions docs/ramalama-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ show this help message and exit
#### **--name**, **-n**
name of the container to run the Model in

#### **--network-mode**=*none*
set the network mode for the container

#### **--seed**=
Specify seed rather than using random seed model interaction

Expand Down
3 changes: 3 additions & 0 deletions docs/ramalama-serve.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ IP address for llama.cpp to listen on.
#### **--name**, **-n**
Name of the container to run the Model in.

#### **--network-mode**=*""*
set the network mode for the container

#### **--port**, **-p**
port for AI Model server to listen on

Expand Down
34 changes: 34 additions & 0 deletions ramalama/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,12 @@ def bench_cli(args):

def bench_parser(subparsers):
parser = subparsers.add_parser("bench", aliases=["benchmark"], help="benchmark specified AI Model")
parser.add_argument(
"--network-mode",
type=str,
default="none",
help="set the network mode for the container",
)
parser.add_argument("MODEL") # positional argument
parser.set_defaults(func=bench_cli)

Expand Down Expand Up @@ -672,6 +678,13 @@ def convert_parser(subparsers):
Model "car" includes base image with the model stored in a /models subdir.
Model "raw" contains the model and a link file model.file to it stored at /.""",
)
# https://docs.podman.io/en/latest/markdown/podman-build.1.html#network-mode-net
parser.add_argument(
"--network-mode",
type=str,
default="none",
help="sets the configuration for network namespaces when handling RUN instructions",
)
parser.add_argument("SOURCE") # positional argument
parser.add_argument("TARGET") # positional argument
parser.set_defaults(func=convert_cli)
Expand Down Expand Up @@ -702,6 +715,12 @@ def push_parser(subparsers):
default=config['carimage'],
help=argparse.SUPPRESS,
)
parser.add_argument(
"--network-mode",
type=str,
default="none",
help="set the network mode for the container",
)
parser.add_argument(
"--type",
default="raw",
Expand Down Expand Up @@ -791,6 +810,15 @@ def _run(parser):
def run_parser(subparsers):
parser = subparsers.add_parser("run", help="run specified AI Model as a chatbot")
_run(parser)
# Disable network access by default, and give the option to pass any supported network mode into
# podman if needed:
# https://docs.podman.io/en/latest/markdown/podman-run.1.html#network-mode-net
parser.add_argument(
"--network-mode",
type=str,
default="none",
help="set the network mode for the container",
)
parser.add_argument("MODEL") # positional argument
parser.add_argument(
"ARGS", nargs="*", help="Overrides the default prompt, and the output is returned without entering the chatbot"
Expand All @@ -816,6 +844,12 @@ def serve_parser(subparsers):
parser.add_argument(
"-p", "--port", default=config.get('port', "8080"), help="port for AI Model server to listen on"
)
parser.add_argument(
"--network-mode",
type=str,
default="",
help="set the network mode for the container",
)
parser.add_argument("MODEL") # positional argument
parser.set_defaults(func=serve_cli)

Expand Down
2 changes: 2 additions & 0 deletions ramalama/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def setup_container(self, args):
if k == "CUDA_VISIBLE_DEVICES":
conman_args += ["--device", "nvidia.com/gpu=all"]
conman_args += ["-e", f"{k}={v}"]
if args.network_mode != "":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and simple fix :)

conman_args += ["--network", args.network_mode]
return conman_args

def gpu_args(self, args, runner=False):
Expand Down
14 changes: 13 additions & 1 deletion ramalama/oci.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,19 @@ def build(self, source, target, args):
else:
c.write(model_raw)
imageid = (
run_cmd([self.conman, "build", "--no-cache", "-q", "-f", containerfile.name, contextdir], debug=args.debug)
run_cmd(
[
self.conman,
"build",
"--no-cache",
f"--network={args.network_mode}",
"-q",
"-f",
containerfile.name,
contextdir,
],
debug=args.debug,
)
.stdout.decode("utf-8")
.strip()
)
Expand Down
Loading