Repository navigation
Expand file tree
/
Copy pathharbor.sh
More file actions
executable file
·13591 lines (12332 loc) · 446 KB
/
Copy pathharbor.sh
File metadata and controls
executable file
·13591 lines (12332 loc) · 446 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Guard: harbor.sh requires bash. Running with sh/dash/zsh produces cryptic errors.
if [ -z "$BASH_VERSION" ]; then
echo "Error: harbor.sh must be run with bash, not sh or another shell." >&2
echo "Run as: bash $0 $*" >&2
exit 1
fi
set -eo pipefail
# ========================================================================
# == Functions
# ========================================================================
# Portable timeout: run a command with a time limit.
# Uses GNU timeout if available, falls back to perl (always on macOS).
# Returns 124 on timeout (matching GNU timeout convention).
# Usage: _with_timeout 10 docker info
_with_timeout() {
local secs="$1"; shift
if command -v timeout &>/dev/null; then
timeout "$secs" "$@"
return $?
elif command -v perl &>/dev/null; then
perl -e '
my $t=shift @ARGV;
my $pid=fork;
if(!$pid){exec @ARGV;die "exec: $!"}
$SIG{ALRM}=sub{kill 15,$pid;exit 124};
alarm $t;
waitpid $pid,0;
exit($?>>8)
' "$secs" "$@"
return $?
else
# No timeout mechanism available; run without time limit
"$@"
return $?
fi
}
# Check that Docker is installed, Compose v2 is available, and the daemon
# is reachable. Provides clear, actionable error messages for first-run
# users who may not yet have Docker set up.
# Caches the result so repeated calls in the same invocation are free.
_docker_ok=""
_check_docker() {
# Return cached result when available
if [ -n "$_docker_ok" ]; then
[ "$_docker_ok" = "1" ] && return 0 || return 1
fi
if ! command -v docker &>/dev/null; then
_docker_ok=0
log_error "Docker is not installed."
log_error "Harbor requires Docker to run services."
if [[ "$(uname)" == "Darwin" ]]; then
log_error "Install Docker Desktop: https://docs.docker.com/desktop/install/mac-install/"
else
log_error "Install Docker Engine: https://docs.docker.com/engine/install/"
fi
log_error "After installing, run 'harbor doctor' to verify your setup."
return 1
fi
# docker compose version is fast (no daemon contact) and confirms
# both the Docker CLI and the Compose plugin are installed.
if ! docker compose version &>/dev/null; then
_docker_ok=0
log_error "Docker Compose (v2) is not available."
log_error "Harbor requires the Docker Compose plugin (v2)."
log_error "If Docker is installed, ensure the Compose plugin is included."
log_error "Check: https://docs.docker.com/compose/install/"
log_error "Run 'harbor doctor' for full diagnostics."
return 1
fi
# Verify the daemon is actually running. Use docker version which is
# faster than docker info (no system enumeration) but still contacts
# the daemon. Guard with timeout to avoid hanging when daemon is
# unresponsive (e.g. Docker Desktop still loading).
# Capture exit code before the if-test consumes it ($? is always 0
# inside a then-block).
local docker_exit=0
_with_timeout 5 docker version &>/dev/null || docker_exit=$?
if [ "$docker_exit" -ne 0 ]; then
_docker_ok=0
if [ "$docker_exit" -eq 124 ]; then
log_error "Docker daemon is not responding (timed out after 5s)."
log_error "It may still be starting up. Wait a moment and try again."
else
log_error "Docker daemon is not running or not reachable."
fi
if [[ "$(uname)" == "Darwin" ]]; then
log_error "Start Docker Desktop and wait for it to finish loading."
else
log_error "Start the Docker daemon: sudo systemctl start docker"
fi
log_error "Run 'harbor doctor' for full diagnostics."
return 1
fi
_docker_ok=1
return 0
}
# Check available disk space at a given path and warn if below a threshold.
# Usage: _check_disk_space <path> [min_gb] [label]
# path - filesystem path to check (uses its mount point)
# min_gb - minimum free GB before warning (default: 10)
# label - human-readable label for log messages (default: the path)
# Returns 0 always (warning only, never blocks). Sets _disk_space_gb to
# the available space for callers that want to inspect it.
_disk_space_gb=""
_check_disk_space() {
local check_path="$1"
local min_gb="${2:-10}"
local label="${3:-$check_path}"
_disk_space_gb=""
# Resolve tilde if present
check_path="${check_path/#\~/$HOME}"
# Walk up to find the nearest existing ancestor directory
# (the target dir may not exist yet, e.g., first pull)
local probe_path="$check_path"
while [ ! -d "$probe_path" ] && [ "$probe_path" != "/" ]; do
probe_path="$(dirname "$probe_path")"
done
if [ ! -d "$probe_path" ]; then
# Cannot determine mount point -- skip silently
return 0
fi
# df -k is POSIX-portable (macOS lacks -BG); convert KB to GB
local avail_kb avail_gb
avail_kb=$(df -k "$probe_path" 2>/dev/null | awk 'NR==2 {print $4}')
if [ -z "$avail_kb" ]; then
return 0
fi
# Integer division: KB -> GB (1048576 KB = 1 GB)
avail_gb=$((avail_kb / 1048576))
_disk_space_gb="$avail_gb"
if [ "$avail_gb" -lt "$min_gb" ] 2>/dev/null; then
log_warn "Low disk space for $label: ${avail_gb}GB free (warning threshold: ${min_gb}GB)."
log_warn "LLM models are typically 4-70GB. The download may fail if space runs out."
log_warn "Free space or choose a smaller model. Run 'harbor doctor' for details."
fi
return 0
}
# Check disk space for the Docker storage backend (where Ollama stores models
# inside its container volume). Uses Docker Root Dir from "docker info" output.
# Usage: _check_docker_disk_space [min_gb]
_check_docker_disk_space() {
local min_gb="${1:-10}"
# Try to get Docker Root Dir from docker info (fast, already cached by
# _check_docker in most flows)
local docker_root_dir
docker_root_dir=$(docker info 2>/dev/null | grep "Docker Root Dir:" | sed 's/.*Docker Root Dir: *//')
if [ -n "$docker_root_dir" ]; then
_check_disk_space "$docker_root_dir" "$min_gb" "Docker storage ($docker_root_dir)"
fi
}
# Check if a specific TCP port is in use on the host.
# Uses ss (Linux), lsof (macOS/fallback), or /dev/tcp (bash builtin).
# Returns 0 if the port IS in use, 1 if free.
_is_port_in_use() {
local port="$1"
if command -v ss &>/dev/null; then
ss -tln "sport = :$port" 2>/dev/null | grep -q "LISTEN"
return $?
elif command -v lsof &>/dev/null; then
lsof -iTCP:"$port" -sTCP:LISTEN -P -n &>/dev/null
return $?
else
# Bash builtin /dev/tcp — opening a connection succeeds if port is listening
(echo >/dev/tcp/127.0.0.1/"$port") 2>/dev/null
return $?
fi
}
# Parse "docker compose config" output for host port mappings.
# Outputs lines of "service_name:host_port" for each published port.
_parse_compose_ports() {
local config_output="$1"
# Parse the YAML: find service names (top-level keys under "services:")
# and their published ports.
awk '
/^services:/ { in_services=1; next }
in_services && /^[^ ]/ { in_services=0 }
in_services && /^ [a-zA-Z0-9_-]+:/ {
gsub(/^ /, ""); gsub(/:.*/, "")
current_service=$0
next
}
in_services && /published:/ {
gsub(/.*published: *"?/, ""); gsub(/"? *$/, "")
if ($0 ~ /^[0-9]+$/) {
print current_service ":" $0
}
}
' <<< "$config_output"
}
# Check for port conflicts before starting services.
# 1. Inter-service conflicts: two services mapping the same host port
# 2. Host conflicts: a host port already in use by another process
# Returns 0 (no conflicts) or 1 (conflicts found).
# Args: same as compose_with_options (service names and flags)
_check_port_conflicts() {
local compose_cmd
compose_cmd=$(compose_with_options "$@") || return 0 # If compose resolution fails, skip check
local config_output
config_output=$($compose_cmd config 2>/dev/null) || return 0 # If config fails, skip check
local port_mappings
port_mappings=$(_parse_compose_ports "$config_output")
if [ -z "$port_mappings" ]; then
return 0
fi
local has_conflict=false
# 1. Check for inter-service duplicate ports.
# Uses a flat string of "port=service" pairs instead of associative
# arrays for bash 3.2 (macOS) compatibility.
local seen_ports=""
local conflict_ports=""
while IFS= read -r entry; do
local svc="${entry%%:*}"
local port="${entry##*:}"
# Look up which service already claimed this port
local existing=""
existing=$(printf '%s' "$seen_ports" | grep "^${port}=" | head -1 | sed 's/^[^=]*=//')
if [ -n "$existing" ] && [ "$svc" != "$existing" ]; then
has_conflict=true
conflict_ports="$conflict_ports:$port:"
local svc_upper other_upper
svc_upper=$(printf '%s' "$svc" | tr 'a-z-' 'A-Z_')
other_upper=$(printf '%s' "$existing" | tr 'a-z-' 'A-Z_')
log_error "Port conflict: ${c_g}$existing${c_nc} and ${c_g}$svc${c_nc} both map host port $port."
log_error "Change one with: harbor config set HARBOR_${svc_upper}_HOST_PORT <new_port>"
log_error " or: harbor config set HARBOR_${other_upper}_HOST_PORT <new_port>"
elif [ -z "$existing" ]; then
seen_ports="${seen_ports}${port}=${svc}"$'\n'
fi
done <<< "$port_mappings"
# 2. Check for host port conflicts (ports already in use).
# Skip ports that have inter-service conflicts (already reported).
# Also skip ports owned by already-running Harbor containers (docker
# compose will reuse them without conflict).
local harbor_ports=""
if [ -n "$default_container_prefix" ]; then
harbor_ports=$(docker ps --format '{{.Ports}}' --filter "name=${default_container_prefix}" 2>/dev/null \
| grep -oE '(0\.0\.0\.0|\[::\]):[0-9]+' | sed 's/.*://' | sort -u) || true
fi
local checked_ports=""
while IFS= read -r entry; do
local svc="${entry%%:*}"
local port="${entry##*:}"
# Skip inter-service conflict ports
case "$conflict_ports" in
*":$port:"*) continue ;;
esac
# Skip duplicate port checks (same port, multiple protocols)
case "$checked_ports" in
*":$port:"*) continue ;;
esac
checked_ports="$checked_ports:$port:"
# Skip ports already bound by Harbor's own containers
if printf '%s\n' "$harbor_ports" | grep -qx "$port" 2>/dev/null; then
continue
fi
if _is_port_in_use "$port"; then
has_conflict=true
local svc_upper
svc_upper=$(printf '%s' "$svc" | tr 'a-z-' 'A-Z_')
log_warn "Port $port needed by ${c_g}$svc${c_nc} is already in use on the host."
log_warn "Change it with: harbor config set HARBOR_${svc_upper}_HOST_PORT <new_port>"
log_warn "Or stop the process using port $port."
fi
done <<< "$port_mappings"
if $has_conflict; then
log_info "Use 'harbor up --skip-port-check' to start anyway."
return 1
fi
return 0
}
show_version() {
echo "Harbor CLI version: $version"
}
show_help() {
show_version
echo "Usage: $0 <command> [options]"
echo
echo "Start here (for AI agents):"
echo " harbor skills get harbor"
echo
echo " Skills ship with the CLI (always version-matched) and include"
echo " workflow patterns, service guides, and copy-paste examples."
echo " Prefer this over guessing commands from flag docs alone."
echo
echo " skills [list] List available skills"
echo " skills get harbor Core CLI usage guide"
echo " skills get <name> Load a specialized skill"
echo " skills path [name] Print skill directory path"
echo
echo "Compose Setup Commands:"
echo " up|u|start|s [handle(s)] - Start the service(s)"
echo " up --tail - Start and tail the logs"
echo " up --open - Start and open in the browser"
echo " up --no-defaults - Do not include default services"
echo " up --skip-port-check - Skip port conflict pre-check"
echo " down|d [handle(s)] - Stop and remove the containers"
echo " down --volumes - Also remove named volumes"
echo " down --rmi local|all - Also remove images"
echo " restart|r [handle(s)] - Down then up"
echo " ps - List the running containers"
echo " logs|l [handle] - View logs (--no-follow for non-streaming)"
echo " exec <handle> <command> - Execute a command in a running service"
echo " pull <handle> - Pull Docker images or download models"
echo " pull <service>... - Pull Docker images for service(s)"
echo " pull <model> - Download a model (alias for 'harbor models pull')"
echo " dive <handle> - Run the Dive CLI to inspect Docker images"
echo " run <alias> - Run a command defined as an alias"
echo " run <handle> [command] - Run a one-off command in a service container"
echo " shell <handle> - Load shell in the given service main container"
echo " build <handle> - Build the given service"
echo " stats - Show resource usage statistics"
echo " attach <handle> - Attach to a running service container"
echo " cmd <handle> - Print the docker compose command"
echo " launch <handle> [args] - Launch a service CLI with currently running Harbor services"
echo
echo "Setup Management Commands:"
echo " webui - Configure Open WebUI Service"
echo " llamacpp - Configure llamacpp service"
echo " ikllamacpp - Configure ik_llama.cpp service"
echo " prismml - Configure PrismML llama.cpp service"
echo " tgi - Configure text-generation-inference service"
echo " litellm - Configure LiteLLM service"
echo " langflow - Configure Langflow UI Service"
echo " openai - Configure OpenAI API keys and URLs"
echo " vllm - Configure VLLM service"
echo " dmr - Configure Docker Model Runner backend"
echo " mlx - Configure host MLX backend"
echo " omlx - Configure host oMLX backend"
echo " aphrodite - Configure Aphrodite service"
echo " tabbyapi - Configure TabbyAPI service"
echo " mistralrs - Configure mistral.rs service"
echo " cfd - Run cloudflared CLI"
echo " airllm - Configure AirLLM service"
echo " txtai - Configure txtai service"
echo " chatui - Configure HuggingFace ChatUI service"
echo " comfyui - Configure ComfyUI service"
echo " parler - Configure Parler service"
echo " sglang - Configure SGLang CLI"
echo " omnichain - Work with Omnichain service"
echo " jupyter - Configure Jupyter service"
echo " ol1 - Configure ol1 service"
echo " ktransformers - Configure ktransformers service"
echo " kobold - Configure Koboldcpp service"
echo " morphic - Configure Morphic service"
echo " modularmax - Configure Modular MAX service"
echo " boost - Configure Harbor Boost service"
echo " hermes - Configure Hermes Agent service"
echo " stt - Configure Speech-to-Text service"
echo " speaches - Configure Speaches service"
echo " webtop - Configure Webtop service"
echo " mcp - Configure MCP service"
echo " oterm - Configure oterm service"
echo
echo "Service CLIs:"
echo " ollama - Run Ollama CLI (docker). Service should be running."
echo " aider - Launch Aider CLI"
echo " aichat - Run aichat CLI"
echo " interpreter|opint - Launch Open Interpreter CLI"
echo " fabric - Run Fabric CLI"
echo " facts - Run facts CLI against the current directory"
echo " mi - Run mi agent CLI against the current directory"
echo " plandex - Launch Plandex CLI"
echo " cmdh - Run cmdh CLI"
echo " parllama - Launch Parllama - TUI for chatting with Ollama models"
echo " bench - Run and manage Harbor Bench"
echo " harbor - Run Harbor agent evaluations"
echo " lmeval|lm_eval - Run LM Evaluation Harness"
echo " openhands|oh - Run OpenHands service"
echo " repopack - Run the Repopack CLI"
echo " nexa - Run the Nexa CLI, configure the service"
echo " gptme - Run gptme CLI, configure the service"
echo " nanobot - Run nanobot CLI"
echo " promptfoo|pf - Run promptfoo CLI for LLM testing and evaluation"
echo " tokscale - Run tokscale CLI to monitor AI token usage and costs"
echo " hf - Run the Harbor's Hugging Face CLI. Expanded with a few additional commands."
echo " hf dl - HuggingFaceModelDownloader CLI"
echo " hf parse-url - Parse file URL from Hugging Face"
echo " hf token - Get/set the Hugging Face Hub token"
echo " hf cachedir - Get/set the path to Hugging Face cache"
echo " hf find <query> - Open HF Hub with a query (trending by default)"
echo " hf path <spec> - Print a folder in HF cache for a given model spec"
echo " hf * - Anything else is passed to the official Hugging Face CLI"
echo " models - Manage models across Ollama, HuggingFace, llama.cpp, DMR, MLX, and oMLX"
echo " k6 - Run K6 CLI"
echo
echo "Harbor CLI Commands:"
echo " open <handle> - Open a service in the default browser"
echo " launch <handle> [args] - Launch a service CLI with currently running Harbor services"
echo
echo " url <handle> - Get the URL for a service"
echo " url <handle> - Url on the local host"
echo " url [-a|--addressable|--lan] <handle> - (supposed) LAN URL"
echo " url [-i|--internal] <handle> - URL within Harbor's docker network"
echo
echo " qr <handle> - Print a QR code for a service"
echo
echo " t|tunnel <handle> - Expose given service to the internet"
echo " tunnel down|stop|d|s - Stop all running tunnels (including auto)"
echo " tunnels [ls|rm|add] - Manage services that will be tunneled on 'up'"
echo " tunnels rm <handle|index> - Remove, also accepts handle or index"
echo " tunnels add <handle> - Add a service to the tunnel list"
echo
echo " config [get|set|ls] - Manage the Harbor environment configuration"
echo " config ls - All config values in ENV format"
echo " config get <field> - Get a specific config value"
echo " config set <field> <value> - Set a specific config value"
echo " config reset - Reset Harbor configuration to default .env"
echo " config update - Merge upstream config changes from default .env"
echo " config search <query> - Search config keys and values"
echo
echo " env <service> [key] [value] - Manage override.env variables for a service"
echo " env <service> - List all variables for a service"
echo " env <service> <key> - Get a specific variable"
echo " env <service> <key> <value> - Set a specific variable"
echo " env <service> get <key> - Get a specific variable (explicit)"
echo " env <service> set <key> <val> - Set a specific variable (explicit)"
echo " env <service> unset <key> - Remove a specific variable"
echo " env <service> ls - List all variables"
echo " env <service> search <query> - Search variables"
echo
echo " profile|profiles|p [ls|rm|add] - Manage Harbor profiles"
echo " profile ls|list - List all profiles"
echo " profile rm|remove <name> - Remove a profile"
echo " profile add|save <name> - Add current config as a profile"
echo " profile set|use|load <name> - Use a profile"
echo
echo " alias|aliases|a [ls|get|set|rm] - Manage Harbor aliases"
echo " alias ls|list - List all aliases"
echo " alias get <name> - Get an alias"
echo " alias set <name> <command> - Set an alias"
echo " alias rm|remove <name> - Remove an alias"
echo
echo " history|h [ls|rm|add] - Harbor command history."
echo " When run without arguments, launches interactive selector."
echo " history clear - Clear the history"
echo " history size - Get/set the history size"
echo " history list|ls - List recorded history"
echo
echo " defaults [ls|rm|add] - List default services"
echo " defaults rm <handle|index> - Remove, also accepts handle or index"
echo " defaults add <handle> - Add"
echo
echo " volumes [ls|add|rm|clear] - Manage custom volume mounts for services"
echo " volumes ls - Show all services with custom volumes"
echo " volumes ls <service> - Show volumes for a specific service"
echo " volumes add <svc> <src>:<dest> - Add a volume mount (docker-style notation)"
echo " volumes rm <service> <index> - Remove by index"
echo " volumes clear <service> - Remove all custom volumes for a service"
echo
echo " find <file> - Find a file in the caches visible to Harbor"
echo " ls|list [--active|-a] - List available/active Harbor services"
echo " ln|link [--short] - Create a symlink to the CLI, --short for 'h' link"
echo " unlink|unln - Remove CLI symlinks and PATH entries"
echo " wrappers [list|add|rm|sync] - Manage opt-in command wrappers"
echo " eject - Eject resolved Compose configuration, accepts same options as 'up'"
echo " help|--help|-h - Show this help message"
echo " version|--version|-v - Show the CLI version"
echo " gum - Run the Gum terminal commands"
echo " update [-l|--latest] - Update Harbor. --latest for the dev version"
echo " info - Show system information for debug/issues"
echo " doctor - Tiny troubleshooting script"
echo " how - Ask questions about Harbor CLI, uses mi under the hood"
echo " smi - Show NVIDIA GPU information"
echo " top - Run nvtop to monitor GPU usage"
echo " size - Print the size of caches Harbor is aware of"
echo " eval - Run promptfoo evaluation"
echo " routine - Run internal Harbor routines"
echo " skills [list|get|path]- Agent-readable skill docs shipped with the CLI"
echo " completion <shell> - Generate shell completions (bash, zsh, fish)"
echo " dev <script> - Run Harbor development scripts"
echo " tools - Run Harbor development tools"
echo
echo "Harbor Workspace Commands:"
echo " home - Show path to the Harbor workspace"
echo " vscode - Open Harbor Workspace in VS Code"
echo " fixfs - Fix file ownership for service volumes and caches"
}
run_harbor_doctor() {
local check_mode=false
while [ "$#" -gt 0 ]; do
case "$1" in
--check) check_mode=true ;;
esac
shift
done
log_info "Running Harbor Doctor..."
local has_errors=false
local has_critical=false
local docker_ok=false
# Check if Docker is installed
if command -v docker &>/dev/null; then
log_info "${ok} Docker is installed"
# Check if Docker can be called without sudo (with timeout to
# avoid hanging when daemon is starting up or unresponsive)
local docker_access_output
if docker_access_output=$(_with_timeout 10 docker info 2>&1); then
log_info "${ok} Docker can be called without sudo"
log_info "${ok} Docker daemon is running"
docker_ok=true
else
local exit_code=$?
if [ "$exit_code" -eq 124 ]; then
log_error "${nok} Docker daemon is not responding (timed out after 10s). It may still be starting up - try again in a moment."
elif echo "$docker_access_output" | grep -qiE "permission denied|got permission denied while trying to connect to the docker daemon socket"; then
log_error "${nok} Docker requires sudo for this user. Add your user to the 'docker' group and re-login."
else
log_error "${nok} Docker daemon is not running or not reachable."
if [[ "$OSTYPE" == darwin* ]]; then
log_error " Start Docker Desktop from Applications, or run: open -a Docker"
elif grep -qiE "microsoft|wsl" /proc/version 2>/dev/null; then
log_error " Start Docker Desktop on Windows and enable WSL integration for this distro,"
log_error " or start the native daemon: sudo systemctl start docker"
else
log_error " Start the daemon: sudo systemctl start docker"
log_error " If using Docker Desktop: open Docker Desktop from your application menu"
fi
fi
has_errors=true
has_critical=true
fi
else
log_error "${nok} Docker is not installed."
log_error " Install Docker: https://docs.docker.com/engine/install/"
has_errors=true
has_critical=true
fi
# Only check Compose if Docker itself is working
if $docker_ok; then
# Check if Docker Compose (v2) is installed
if _with_timeout 10 docker compose version &>/dev/null; then
log_info "${ok} Docker Compose (v2) is installed"
else
log_error "${nok} Docker Compose (v2) is not installed."
log_error " Install Docker Compose: https://docs.docker.com/compose/install/"
has_errors=true
has_critical=true
fi
if ! has_modern_compose; then
local installed_compose
installed_compose=$(docker compose version --short 2>/dev/null || echo "unknown")
log_error "${nok} Docker Compose version ($installed_compose) is older than required ($desired_compose_major.$desired_compose_minor.$desired_compose_patch)."
log_error " Update Docker Compose: https://docs.docker.com/compose/install/"
has_errors=true
has_critical=true
else
log_info "${ok} Docker Compose (v2) version is newer than $desired_compose_major.$desired_compose_minor.$desired_compose_patch"
fi
# Check Docker disk space (LLM models are large, disk exhaustion is common)
local docker_root_dir data_space_gb
docker_root_dir=$(echo "$docker_access_output" | grep "Docker Root Dir:" | sed 's/.*Docker Root Dir: *//')
if [ -n "$docker_root_dir" ]; then
# df -k is POSIX-portable (macOS lacks -BG); convert KB to GB
data_space_gb=$(df -k "$docker_root_dir" 2>/dev/null | awk 'NR==2 {printf "%d", $4/1048576}')
if [ -n "$data_space_gb" ] && [ "$data_space_gb" -lt 10 ] 2>/dev/null; then
log_warn "${nok} Low disk space on Docker storage (${data_space_gb}GB free at $docker_root_dir). LLM models are large - consider freeing space or running 'docker system prune'."
elif [ -n "$data_space_gb" ]; then
log_info "${ok} Docker storage has ${data_space_gb}GB free"
fi
fi
# Report proxy config if set (helps debug pull failures)
for proxy_var in HTTP_PROXY HTTPS_PROXY http_proxy https_proxy NO_PROXY no_proxy; do
if [ -n "${!proxy_var:-}" ]; then
log_info " Proxy: $proxy_var=${!proxy_var}"
fi
done
else
log_warn " Skipping Compose, disk, and registry checks (Docker not reachable)"
fi
# Check if the Harbor workspace directory exists
if [ -d "$harbor_home" ]; then
log_info "${ok} Harbor home: $harbor_home"
else
log_error "${nok} Harbor home does not exist or is not reachable at: $harbor_home"
log_error " Reinstall Harbor or set HARBOR_HOME to the correct path."
has_errors=true
has_critical=true
fi
# Check prerequisites for 'harbor update'
if command -v git &>/dev/null; then
log_info "${ok} git is installed"
else
log_error "${nok} git is not installed. Harbor requires git for updates."
has_errors=true
fi
if command -v curl &>/dev/null; then
log_info "${ok} curl is installed"
else
log_error "${nok} curl is not installed. Harbor requires curl for version checks and updates."
has_errors=true
fi
# Check if Harbor home is a git repo (required for 'harbor update')
if [ -d "$harbor_home" ] && [ ! -d "$harbor_home/.git" ]; then
log_warn "${nok} Harbor home is not a git repository ($harbor_home/.git not found)."
log_warn " 'harbor update' will not work. If you installed via --source-path,"
log_warn " reinstall with: curl -fsSL https://github.com/raw/av/harbor/main/install.sh | bash"
fi
if $check_mode; then
if $has_critical; then
log_error "Harbor Doctor: essential checks failed."
return 1
else
log_info "Harbor Doctor: essential checks passed."
return 0
fi
fi
# WSL-specific diagnostics
if grep -qiE "microsoft|wsl" /proc/version 2>/dev/null || [ -n "${WSL_INTEROP:-}" ]; then
local wsl_ver="unknown"
if [ -n "${WSL_INTEROP:-}" ] || grep -qiE "microsoft-standard|microsoft-WSL2" /proc/version 2>/dev/null; then
wsl_ver="2"
else
wsl_ver="1"
fi
log_info "${ok} WSL${wsl_ver} environment detected"
if [ "$wsl_ver" = "1" ]; then
log_error "${nok} WSL1 does not support Docker natively. Upgrade to WSL2: wsl --set-version <distro> 2"
has_errors=true
has_critical=true
fi
# Warn if harbor_home is on a Windows-mounted filesystem (slow IO)
local home_mount
home_mount=$(df -P "$harbor_home" 2>/dev/null | awk 'NR==2 {print $6}')
if [ -n "$home_mount" ] && echo "$home_mount" | grep -q "^/mnt/[a-zA-Z]"; then
log_warn "${nok} Harbor home is on a Windows filesystem ($home_mount). File operations will be slow. Consider moving to the Linux filesystem."
fi
fi
# SELinux diagnostics (Fedora, RHEL, CentOS, Rocky, Alma)
if command -v getenforce &>/dev/null || [ -f /sys/fs/selinux/enforce ]; then
local selinux_mode="unknown"
if command -v getenforce &>/dev/null; then
selinux_mode=$(getenforce 2>/dev/null || echo "unknown")
elif [ -f /sys/fs/selinux/enforce ]; then
local enforce_val
enforce_val=$(cat /sys/fs/selinux/enforce 2>/dev/null)
case "$enforce_val" in
1) selinux_mode="Enforcing" ;;
0) selinux_mode="Permissive" ;;
*) selinux_mode="unknown" ;;
esac
fi
if [ "$selinux_mode" = "Enforcing" ]; then
log_warn "${nok} SELinux is Enforcing. Docker bind mounts may be denied silently."
log_warn " Harbor compose files do not use :z/:Z volume labels."
log_warn " If containers report 'Permission denied' on mounted files, consider:"
log_warn " 1. Install container-selinux: sudo dnf install -y container-selinux"
log_warn " 2. Check for recent denials: sudo ausearch --input-logs -m avc -ts recent --comm docker 2>/dev/null"
log_warn " 3. As a last resort: sudo setenforce 0 (temporary, resets on reboot)"
# Check if container-selinux is installed (provides base policies for containers)
if command -v rpm &>/dev/null; then
if rpm -q container-selinux &>/dev/null; then
log_info "${ok} container-selinux is installed"
else
log_error "${nok} container-selinux is not installed. Install it: sudo dnf install -y container-selinux"
has_errors=true
has_critical=true
fi
fi
# Check for recent Docker AVC denials (non-destructive, fast)
if command -v ausearch &>/dev/null; then
local avc_count
avc_count=$(ausearch --input-logs -m avc -ts recent --comm docker 2>/dev/null | grep -c "^type=AVC" 2>/dev/null || echo "0")
if [ "$avc_count" -gt 0 ] 2>/dev/null; then
log_warn "${nok} Found ${avc_count} recent SELinux AVC denial(s) for Docker."
log_warn " Run 'sudo ausearch --input-logs -m avc -ts recent --comm docker' for details."
log_warn " Run 'sudo sealert -a /var/log/audit/audit.log' for human-readable explanations (if setroubleshoot is installed)."
fi
fi
elif [ "$selinux_mode" = "Permissive" ]; then
log_info "${ok} SELinux is Permissive (not blocking Docker)"
elif [ "$selinux_mode" = "Disabled" ]; then
log_info "${ok} SELinux is Disabled"
else
log_info " SELinux status: ${selinux_mode}"
fi
fi
# Fedora/RHEL-specific Docker guidance
if [ -f /etc/os-release ]; then
local doctor_distro_id
doctor_distro_id=$(awk -F= '/^ID=/{gsub(/"/,"",$2); print tolower($2)}' /etc/os-release)
case "$doctor_distro_id" in
fedora|rhel|centos|rocky|almalinux)
# Check if using moby-engine instead of docker-ce (common misconfiguration on Fedora)
if $docker_ok && command -v rpm &>/dev/null; then
if rpm -q moby-engine &>/dev/null && ! rpm -q docker-ce &>/dev/null; then
log_warn " Using moby-engine instead of docker-ce. moby-engine was removed from Fedora 39+."
log_warn " For better compatibility, switch to Docker's official packages:"
case "$doctor_distro_id" in
centos)
log_warn " https://docs.docker.com/engine/install/centos/"
;;
rhel|rocky|almalinux)
log_warn " https://docs.docker.com/engine/install/rhel/"
;;
*)
log_warn " https://docs.docker.com/engine/install/fedora/"
;;
esac
fi
fi
# Detect immutable variants
local doctor_variant
doctor_variant=$(awk -F= '/^VARIANT_ID=/{gsub(/"/,"",$2); print tolower($2)}' /etc/os-release)
case "${doctor_variant:-}" in
silverblue|kinoite|sericea|onyx|coreos|iot)
log_info " Immutable OS variant detected: ${doctor_variant}"
log_info " Standard dnf install will not work. Use rpm-ostree or Toolbox."
;;
esac
;;
esac
fi
# Check if the default profile file exists and is readable
if [ -f "$default_profile" ] && [ -r "$default_profile" ]; then
log_info "${ok} Default profile exists and is readable"
else
log_error "${nok} Default profile is missing or not readable at: $default_profile"
log_error " This usually means the Harbor installation is incomplete. Try reinstalling: curl -fsSL https://github.com/raw/av/harbor/main/install.sh | bash"
has_errors=true
has_critical=true
fi
# Check if the .env file exists and is readable
if [ -f ".env" ] && [ -r ".env" ]; then
log_info "${ok} Current profile (.env) exists and is readable"
# Validate .env syntax: catch common issues that cause silent misbehavior
local env_issues=0
local env_line_num=0
while IFS= read -r line || [ -n "$line" ]; do
env_line_num=$((env_line_num + 1))
# Skip blank lines and comments
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
# Lines must contain '=' (KEY=VALUE format)
if [[ "$line" != *=* ]]; then
if [ "$env_issues" -eq 0 ]; then
log_warn " .env syntax issues:"
fi
log_warn " Line $env_line_num: missing '=' separator: $(printf '%.60s' "$line")"
env_issues=$((env_issues + 1))
fi
done < .env
# Check for duplicate keys (docker compose uses last value,
# but scripts that source .env use the first — silent misbehavior)
local dup_keys
dup_keys=$(grep -v '^[[:space:]]*#' .env | grep -v '^[[:space:]]*$' | grep '=' | sed 's/=.*//' | sort | uniq -d)
if [ -n "$dup_keys" ]; then
local dup_count
dup_count=$(echo "$dup_keys" | wc -l)
if [ "$env_issues" -eq 0 ]; then
log_warn " .env syntax issues:"
fi
log_warn " $dup_count duplicate key(s): $(echo "$dup_keys" | head -3 | tr '\n' ' ')"
env_issues=$((env_issues + dup_count))
fi
if [ "$env_issues" -gt 0 ]; then
log_warn " Found $env_issues .env issue(s). Run 'harbor config update' to regenerate from defaults."
fi
# Warn about stale keys: present in .env but absent from every
# default source (profiles/default.env + services/*/default.env)
if [ -f "$default_profile" ] && [ -r "$default_profile" ]; then
local stale_count=0
local stale_keys=""
local env_key
# Bash 3 compatible array fill (no bash-4 array builtins)
local doctor_defaults=()
local doctor_default_file
while IFS= read -r doctor_default_file; do
doctor_defaults+=("$doctor_default_file")
done < <(collect_default_env_files)
while IFS= read -r line || [ -n "$line" ]; do
[[ -z "$line" || "$line" =~ ^[[:space:]]*# || "$line" != *=* ]] && continue
env_key="${line%%=*}"
# Skip non-HARBOR_ keys (user-added, system, etc.)
[[ "$env_key" != HARBOR_* ]] && continue
if ! grep -qh "^${env_key}=" "${doctor_defaults[@]}" 2>/dev/null; then
stale_count=$((stale_count + 1))
if [ "$stale_count" -le 5 ]; then
stale_keys="${stale_keys:+$stale_keys, }$env_key"
fi
fi
done < .env
if [ "$stale_count" -gt 0 ]; then
local stale_msg="$stale_keys"
if [ "$stale_count" -gt 5 ]; then
stale_msg="$stale_msg, ... ($stale_count total)"
fi
log_warn " $stale_count key(s) in .env not found in default profile: $stale_msg"
log_warn " These may be from an older version or manual edits. Harmless but may indicate stale config."
fi
fi
else
log_error "${nok} Current profile (.env) is missing or not readable."
log_error " Run 'harbor config update' to regenerate it from the default profile."
has_errors=true
has_critical=true
fi
# Check Harbor home disk space (LLM models, configs, and caches live here)
local home_space_gb
home_space_gb=$(df -k "$harbor_home" 2>/dev/null | awk 'NR==2 {printf "%d", $4/1048576}')
if [ -n "$home_space_gb" ] && [ "$home_space_gb" -lt 5 ] 2>/dev/null; then
log_warn "${nok} Low disk space on Harbor home (${home_space_gb}GB free at $harbor_home). LLM models and service data require significant space."
elif [ -n "$home_space_gb" ]; then
log_info "${ok} Harbor home has ${home_space_gb}GB free"
fi
# Check if CLI is linked and symlink target is valid.
# This requires .env (for cli.path/cli.name), so skip when .env is
# missing — doctor must remain usable on broken installs.
if [ -f ".env" ] && [ -r ".env" ]; then
local cli_path cli_name
cli_path=$(env_manager get cli.path)
cli_name=$(env_manager get cli.name)
cli_path="${cli_path/#\~/$HOME}"
if [ -L "$cli_path/$cli_name" ]; then
local link_target
link_target=$(readlink "$cli_path/$cli_name")
if [ -f "$cli_path/$cli_name" ]; then
log_info "${ok} CLI is linked"
else
log_error "${nok} CLI symlink is broken: $cli_path/$cli_name -> $link_target"
log_error " The target no longer exists. Run 'harbor ln' to recreate."
has_errors=true
has_critical=true
fi
else
log_error "${nok} CLI is not linked. Run 'harbor ln' to create a symlink."
has_errors=true
has_critical=true
fi
# Verify cli_path is in PATH (symlink exists but won't be found if
# the directory isn't in PATH — e.g., shell profile not sourced)
case ":$PATH:" in
*":$cli_path:"*)
log_info "${ok} CLI directory is in PATH"
;;
*)
log_warn "${nok} CLI directory '$cli_path' is not in PATH."
log_warn " The 'harbor' command won't be found in new shells."
log_warn " Run 'harbor ln' to re-add the PATH entry, then open a new terminal."
;;
esac
else
log_warn " Skipping CLI link check (.env not available)"
fi
# GPU checks: only show results for hardware that is actually present,
# to avoid noisy warnings on systems without discrete GPUs
if has_nvidia; then
log_info "${ok} NVIDIA GPU detected"
if has_nvidia_ctk; then
log_info "${ok} NVIDIA Container Toolkit is installed"
else
log_warn "${nok} NVIDIA Container Toolkit is not installed. GPU containers won't be able to access the GPU. Install: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html"
has_errors=true
fi
fi
if has_rocm; then
log_info "${ok} AMD GPU with ROCm support detected"
elif [[ -e "/dev/kfd" ]]; then
log_warn "${nok} AMD GPU hardware found (/dev/kfd) but ROCm support is incomplete. Check that amdgpu kernel module is loaded and /dev/dri/renderD* devices exist."
fi
if $has_errors; then
log_error "Harbor Doctor checks failed. Please resolve the issues above."
return 1
else
log_info "Harbor Doctor checks completed successfully."
return 0
fi
}
has_nvidia() {
command -v nvidia-smi &>/dev/null
}
has_nvidia_ctk() {
command -v nvidia-ctk &>/dev/null || command -v nvidia-container-toolkit &>/dev/null
}
has_nvidia_cdi() {
# Check if nvidia.yaml is present in either
# /etc/cdi or /var/run/cdi
if [ -f /etc/cdi/nvidia.yaml ] || [ -f /var/run/cdi/nvidia.yaml ] || [ -f /var/run/cdi/nvidia-container-toolkit.json ]; then
return 0
else
return 1
fi
}
has_rocm() {
# 1. Hardware check - /dev/kfd is the AMD GPU compute interface
[[ -e "/dev/kfd" ]] || return 1
# 2. Verify render nodes exist (needed for container device passthrough)
ls /dev/dri/renderD* &>/dev/null || return 1
# 3. Sysfs covers both loaded and built-in modules without a pipefail/SIGPIPE race.
[[ -d /sys/module/amdgpu ]] || return 1
return 0
}
has_modern_compose() {
local compose_version_raw
compose_version_raw=$(docker compose version --short 2>/dev/null | sed -e 's/-desktop//')
if [ -z "$compose_version_raw" ]; then
log_debug "Could not detect Docker Compose version"
return 1
fi
local compose_version=${compose_version_raw#v}
if [ "$compose_version" = "dev" ]; then
log_debug "Docker Compose reports version 'dev'; assuming it is modern"
return 0
fi
local major_version minor_version patch_version
if [[ "$compose_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
major_version=${BASH_REMATCH[1]}
minor_version=${BASH_REMATCH[2]}
patch_version=${BASH_REMATCH[3]}
else
log_debug "Unrecognized Docker Compose version '$compose_version_raw'; skipping numeric comparison"
return 0
fi
if ((major_version > desired_compose_major)); then