-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_ai_dev.sh
More file actions
151 lines (134 loc) · 5.55 KB
/
run_ai_dev.sh
File metadata and controls
151 lines (134 loc) · 5.55 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
#!/bin/bash
# ==========================================================
# Script Name: run_ai_dev.sh
# Description: Launch OmniBioAI Dev Environment
# Image: ghcr.io/man4ish/omnibioai-dev-env
# Requires: NVIDIA GPU + nvidia-container-toolkit
# Usage: bash run_ai_dev.sh [OPTIONS]
# --jupyter Start JupyterLab automatically
# --ollama Start Ollama server automatically
# --build Force rebuild image from Dockerfile
# --help Show this help message
# ==========================================================
IMAGE_NAME="ghcr.io/man4ish/omnibioai-dev-env"
TAG="latest"
CONTAINER_NAME="omnibio_dev_foundry"
JUPYTER_PORT="${JUPYTER_PORT:-8888}"
OLLAMA_PORT="${OLLAMA_PORT:-11434}"
# ── Parse arguments ───────────────────────────────────────
START_JUPYTER=false
START_OLLAMA=false
FORCE_BUILD=false
for arg in "$@"; do
case $arg in
--jupyter) START_JUPYTER=true ;;
--ollama) START_OLLAMA=true ;;
--build) FORCE_BUILD=true ;;
--help)
grep "^#" "$0" | grep -v "!/bin/bash" | sed 's/^# \?//'
exit 0
;;
esac
done
echo "=========================================================="
echo " OmniBioAI Dev Environment"
echo " Image: ${IMAGE_NAME}:${TAG}"
echo "=========================================================="
# ── 1. Check NVIDIA runtime ───────────────────────────────
echo ""
echo "▶ Checking GPU availability..."
if ! command -v nvidia-smi &>/dev/null; then
echo "❌ ERROR: nvidia-smi not found."
echo " Install NVIDIA drivers + nvidia-container-toolkit:"
echo " https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html"
exit 1
fi
nvidia-smi --query-gpu=name,memory.total,driver_version \
--format=csv,noheader 2>/dev/null | while IFS=',' read -r name mem driver; do
echo " ✅ GPU: $name | Memory: $mem | Driver: $driver"
done
# ── 2. Check Docker daemon ────────────────────────────────
if ! docker info &>/dev/null; then
echo "❌ ERROR: Docker daemon not running."
echo " Start Docker: sudo systemctl start docker"
exit 1
fi
# ── 3. Get or build image ─────────────────────────────────
echo ""
echo "▶ Checking image..."
if [[ "$FORCE_BUILD" == true ]]; then
echo " Force rebuild requested..."
docker build -t ${IMAGE_NAME}:${TAG} .
elif [[ "$(docker images -q ${IMAGE_NAME}:${TAG} 2>/dev/null)" == "" ]]; then
echo " Image not found locally. Pulling from GHCR..."
if ! docker pull ${IMAGE_NAME}:${TAG}; then
echo " Pull failed. Building from Dockerfile..."
if [[ ! -f "Dockerfile" ]]; then
echo "❌ ERROR: No Dockerfile found in $(pwd)"
exit 1
fi
docker build -t ${IMAGE_NAME}:${TAG} .
fi
else
echo " ✅ Image found: ${IMAGE_NAME}:${TAG}"
fi
# ── 4. Clean up existing container ───────────────────────
echo ""
echo "▶ Cleaning up existing container..."
docker rm -f ${CONTAINER_NAME} &>/dev/null && \
echo " Removed existing container." || \
echo " No existing container to remove."
# ── 5. Build startup command ──────────────────────────────
STARTUP_CMD="echo '========================================'; \
echo ' OmniBioAI Dev Environment Ready'; \
echo '========================================'; \
echo ' Workspace : /workspace'; \
echo ' JupyterLab: http://localhost:${JUPYTER_PORT}'; \
echo ' Ollama : http://localhost:${OLLAMA_PORT}'; \
echo '========================================'"
if [[ "$START_OLLAMA" == true ]]; then
STARTUP_CMD="${STARTUP_CMD}; ollama serve &"
echo " Ollama will start automatically on port ${OLLAMA_PORT}"
fi
if [[ "$START_JUPYTER" == true ]]; then
STARTUP_CMD="${STARTUP_CMD}; jupyter lab \
--ip=0.0.0.0 \
--port=${JUPYTER_PORT} \
--allow-root \
--no-browser \
--NotebookApp.token='' \
--NotebookApp.password=''"
echo " JupyterLab will start on http://localhost:${JUPYTER_PORT}"
else
STARTUP_CMD="${STARTUP_CMD}; bash"
fi
# ── 6. Launch container ───────────────────────────────────
echo ""
echo "▶ Launching container..."
echo " Workspace : $(pwd) → /workspace"
echo " JupyterLab: http://localhost:${JUPYTER_PORT}"
echo " Ollama : http://localhost:${OLLAMA_PORT}"
echo ""
docker run --gpus all \
--ipc=host \
--ulimit memlock=-1 \
--ulimit stack=67108864 \
--name ${CONTAINER_NAME} \
--hostname omnibioai-dev \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-v ~/.ollama:/root/.ollama \
-v "$(pwd)":/workspace \
-v ~/.gitconfig:/root/.gitconfig:ro \
-p ${JUPYTER_PORT}:${JUPYTER_PORT} \
-p ${OLLAMA_PORT}:${OLLAMA_PORT} \
-e HF_HOME=/root/.cache/huggingface \
-e OLLAMA_HOST=0.0.0.0 \
-e PYTHONUNBUFFERED=1 \
-e TERM=xterm-256color \
-it ${IMAGE_NAME}:${TAG} bash -c "${STARTUP_CMD}"
# ── 7. Exit message ───────────────────────────────────────
echo ""
echo "=========================================================="
echo " Session ended. Work saved in $(pwd)"
echo " To resume: docker start -ai ${CONTAINER_NAME}"
echo "=========================================================="