-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose.sh
More file actions
executable file
·73 lines (64 loc) · 1.46 KB
/
compose.sh
File metadata and controls
executable file
·73 lines (64 loc) · 1.46 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
#!/usr/bin/env bash
set -euo pipefail
use_podman=false
pull_image=false
EXEC_USER="$(id -u)"
DEFAULT_SERVICE="unmanic-dev"
while [[ "${1:-}" =~ ^-- ]]; do
case "$1" in
--podman)
use_podman=true
shift
;;
--pull)
pull_image=true
shift
;;
--root)
EXEC_USER=0
shift
;;
*)
break
;;
esac
done
compose_cmd=(docker compose)
if $use_podman; then
compose_cmd=(podman compose)
fi
compose_files=(-f docker-compose.yml)
if [[ -z "${HOST_CPU_LIMIT:-}" ]]; then
HOST_CPU_LIMIT="$(echo "$(nproc) * 0.8" | bc 2>/dev/null || echo "0")"
fi
export HOST_CPU_LIMIT
# Add support for NVIDIA GPUs
if command -v nvidia-smi >/dev/null 2>&1 || [[ -e /dev/nvidiactl ]]; then
compose_files+=(-f docker/docker-compose.nvidia.yml)
fi
# Add support for AMD/Intel GPUs
if [[ -e /dev/dri ]]; then
compose_files+=(-f docker/docker-compose.dri.yml)
fi
cmd="${1:-}"
shift || true
case "$cmd" in
start)
if $pull_image; then
"${compose_cmd[@]}" "${compose_files[@]}" pull
fi
exec "${compose_cmd[@]}" "${compose_files[@]}" up -d "$@"
;;
stop)
exec "${compose_cmd[@]}" "${compose_files[@]}" down "$@"
;;
ps)
exec "${compose_cmd[@]}" "${compose_files[@]}" ps "$@"
;;
exec)
exec "${compose_cmd[@]}" "${compose_files[@]}" exec --user="${EXEC_USER:?}" "${DEFAULT_SERVICE}" "$@"
;;
*)
exec "${compose_cmd[@]}" "${compose_files[@]}" "$cmd" "$@"
;;
esac