Skip to content
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
2 changes: 2 additions & 0 deletions bin/ramalama
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def main(args):
except AttributeError:
parser.print_usage()
print("ramalama: requires a subcommand")
if args.debug:
raise
except IndexError as e:
ramalama.perror("Error: " + str(e).strip("'"))
sys.exit(errno.EINVAL)
Expand Down
3 changes: 3 additions & 0 deletions docs/ramalama.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ $ cat /usr/share/ramalama/shortnames.conf
run RamaLama in the default container (default: True)
use environment variable "RAMALAMA_IN_CONTAINER=false" to change default.

#### **--debug**
print debug messages

#### **--dryrun**
show container runtime command without executing it (default: False)

Expand Down
7 changes: 6 additions & 1 deletion ramalama/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def init_cli():
help="""run RamaLama in the default container.
The RAMALAMA_IN_CONTAINER environment variable modifies default behaviour.""",
)
parser.add_argument(
"--debug",
action="store_true",
help="display debug messages",
)
parser.add_argument(
"--dryrun", dest="dryrun", action="store_true", help="show container runtime command without executing it"
)
Expand Down Expand Up @@ -674,7 +679,7 @@ def cleanup():

atexit.register(cleanup)

run_cmd(conman_args, stdout=None)
run_cmd(conman_args, stdout=None, debug=args.debug)


def dry_run(args):
Expand Down
12 changes: 6 additions & 6 deletions ramalama/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def available(cmd):
return shutil.which(cmd) is not None


def exec_cmd(args, stderr=True):
if x:
print(*args)
def exec_cmd(args, stderr=True, debug=False):
if debug:
perror("exec_cmd: ", *args)
Copy link
Member

Choose a reason for hiding this comment

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

Should probably do

    if debug:
        stderr = True
        perror("exec_cmd: ", *args)

but that can be for another PR.


if not stderr:
# Redirecting stderr to /dev/null
Expand All @@ -75,16 +75,16 @@ def exec_cmd(args, stderr=True):
raise


def run_cmd(args, cwd=None, stdout=subprocess.PIPE, ignore_stderr=False):
def run_cmd(args, cwd=None, stdout=subprocess.PIPE, ignore_stderr=False, debug=False):
"""
Run the given command arguments.

Args:
args: command line arguments to execute in a subprocess
cwd: optional working directory to run the command from
"""
if x:
print(*args)
if debug:
perror("run_cmd: ", *args)

stderr = None
if ignore_stderr:
Expand Down
7 changes: 4 additions & 3 deletions ramalama/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def pull(self, args):
# Symlink is already correct, no need to update it
return symlink_path

run_cmd(["ln", "-sf", relative_target_path, symlink_path])
run_cmd(["ln", "-sf", relative_target_path, symlink_path], debug=args.debug)

return symlink_path

Expand All @@ -79,7 +79,8 @@ def push(self, source, args):
args.store + "/repos/huggingface/.cache",
"--local-dir",
args.store + "/repos/huggingface/" + self.directory,
]
],
debug=args.debug,
)
return proc.stdout.decode("utf-8")
except FileNotFoundError as e:
Expand All @@ -95,7 +96,7 @@ def symlink_path(self, args):

def exec(self, args):
try:
exec_cmd(args)
exec_cmd(args, args.debug)
except FileNotFoundError as e:
raise NotImplementedError(
"""\
Expand Down
4 changes: 2 additions & 2 deletions ramalama/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def run(self, args):
exec_args.append("-cnv")

try:
exec_cmd(exec_args, False)
exec_cmd(exec_args, False, debug=args.debug)
except FileNotFoundError as e:
if in_container():
raise NotImplementedError(file_not_found_in_container % (exec_args[0], str(e).strip("'")))
Expand All @@ -140,7 +140,7 @@ def serve(self, args):
return self.kube(symlink_path, args, exec_args)

try:
exec_cmd(exec_args)
exec_cmd(exec_args, debug=args.debug)
except FileNotFoundError as e:
if in_container():
raise NotImplementedError(file_not_found_in_container % (exec_args[0], str(e).strip("'")))
Expand Down
9 changes: 5 additions & 4 deletions ramalama/oci.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ def login(self, args):
if args.passwordstdin:
conman_args.append("--password-stdin")
conman_args.append(args.REGISTRY.removeprefix(prefix))
print(" ".join(conman_args))
return exec_cmd(conman_args)
return exec_cmd(conman_args, debug=args.debug)

def logout(self, args):
conman_args = [self.conman, "logout"]
conman_args.append(self.model)
return exec_cmd(conman_args)
return exec_cmd(conman_args, debug=args.debug)

def _target_decompose(self, model):
# Remove the prefix and extract target details
Expand Down Expand Up @@ -83,7 +82,9 @@ def _build(self, source, target, args):
COPY {model} /{model_name}
"""
)
run_cmd([self.conman, "build", "-t", target, "-f", containerfile.name, contextdir], stdout=None)
run_cmd(
[self.conman, "build", "-t", target, "-f", containerfile.name, contextdir], stdout=None, debug=args.debug
)

def push(self, source, args):
target = self.model.removeprefix(prefix)
Expand Down
6 changes: 5 additions & 1 deletion ramalama/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ def pull(self, args):
registry = "https://registry.ollama.ai"
accept = "Accept: application/vnd.docker.distribution.manifest.v2+json"
registry_head = f"{registry}/v2/{model_name}"
return init_pull(repos, accept, registry_head, model_name, model_tag, models, symlink_path, self.model)
try:
return init_pull(repos, accept, registry_head, model_name, model_tag, models, symlink_path, self.model)
except urllib.error.HTTPError as e:
raise KeyError(f"failed to pull {registry_head}: " +str(e).strip("'"))


def symlink_path(self, args):
models = args.store + "/models/ollama"
Expand Down
2 changes: 1 addition & 1 deletion test/system/015-help.bats
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function check_help() {
# Test for regression of #7273 (spurious "--remote" help on output)
for helpopt in help --help -h; do
run_ramalama $helpopt
is "${lines[0]}" "usage: ramalama [-h] [--container] [--dryrun] [--engine ENGINE]" \
is "${lines[0]}" "usage: ramalama [-h] [--container] [--debug] [--dryrun] [--engine ENGINE]" \
"ramalama $helpopt: first line of output"
done

Expand Down
4 changes: 4 additions & 0 deletions test/system/050-pull.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ load setup_suite
run_ramalama list
is "$output" ".*ollama://tinyllama:1.1b" "image was actually pulled locally"
run_ramalama rm ollama://tinyllama ollama://tinyllama:1.1b

random_image_name=i_$(safename)
run_ramalama 1 pull ${random_image_name}
is "$output" "Error: failed to pull https://registry.ollama.ai/v2/library/${random_image_name}: HTTP Error 404: Not Found" "image does not exist"
}

# bats test_tags=distro-integration
Expand Down