feat: run qdrant and ollama inside thothii
This commit is contained in:
@@ -91,10 +91,10 @@ ENV PATH="/opt/venv/bin:/usr/local/bin:$PATH" \
|
||||
HOME=/home/thoth
|
||||
|
||||
COPY scripts/verify-line-endings.sh /usr/local/bin/verify-line-endings
|
||||
COPY docker/core-entrypoint.sh docker/session-migrate.sh docker/ensure-pi-trust.mjs /app/docker/
|
||||
COPY docker/core-entrypoint.sh docker/session-migrate.sh docker/ensure-pi-trust.mjs docker/embedding-model-init.sh /app/docker/
|
||||
COPY docker/smoke/core-smoke.sh /app/docker/smoke/core-smoke.sh
|
||||
RUN /usr/local/bin/verify-line-endings /app/docker \
|
||||
&& chmod +x /app/docker/core-entrypoint.sh /app/docker/session-migrate.sh /app/docker/smoke/core-smoke.sh
|
||||
&& chmod +x /app/docker/core-entrypoint.sh /app/docker/session-migrate.sh /app/docker/embedding-model-init.sh /app/docker/smoke/core-smoke.sh
|
||||
|
||||
WORKDIR /app/backend
|
||||
USER thoth
|
||||
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ollama_base_url=${OLLAMA_BASE_URL:-http://embedding:11434}
|
||||
ollama_model=${OLLAMA_MODEL:-qwen3-embedding:0.6b}
|
||||
wait_timeout_sec=${OLLAMA_WAIT_TIMEOUT_SEC:-180}
|
||||
|
||||
case "$wait_timeout_sec" in
|
||||
''|*[!0-9]*)
|
||||
echo "OLLAMA_WAIT_TIMEOUT_SEC must be an integer number of seconds" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$ollama_base_url" in
|
||||
http://*)
|
||||
host_and_path=${ollama_base_url#http://}
|
||||
;;
|
||||
*)
|
||||
echo "OLLAMA_BASE_URL must use http://" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
host_port=${host_and_path%%/*}
|
||||
ollama_host=${host_port%%:*}
|
||||
ollama_port=${host_port##*:}
|
||||
if [[ "$host_port" == "$ollama_host" ]]; then
|
||||
ollama_port=80
|
||||
fi
|
||||
|
||||
deadline=$((SECONDS + wait_timeout_sec))
|
||||
export OLLAMA_HOST="$ollama_base_url"
|
||||
|
||||
fetch_tags() {
|
||||
local response body
|
||||
response=$(
|
||||
exec 3<>"/dev/tcp/$ollama_host/$ollama_port"
|
||||
printf 'GET /api/tags HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n' "$ollama_host" >&3
|
||||
cat <&3
|
||||
) || return 1
|
||||
[[ "$response" == *$' 200 '* || "$response" == HTTP/1.1$' 200'* || "$response" == HTTP/1.0$' 200'* ]] || return 1
|
||||
body=${response#*$'\r\n\r\n'}
|
||||
if [[ "$body" == "$response" ]]; then
|
||||
body=${response#*$'\n\n'}
|
||||
fi
|
||||
printf '%s' "$body"
|
||||
}
|
||||
|
||||
model_present() {
|
||||
local compact_json
|
||||
compact_json=$(printf '%s' "$1" | tr -d '[:space:]')
|
||||
grep -Fq "\"name\":\"$ollama_model\"" <<<"$compact_json"
|
||||
}
|
||||
|
||||
wait_for_tags() {
|
||||
local tags_json
|
||||
while (( SECONDS <= deadline )); do
|
||||
if tags_json=$(fetch_tags 2>/dev/null); then
|
||||
printf '%s' "$tags_json"
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
echo "timed out waiting for Ollama tags at $ollama_base_url/api/tags" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
tags_json=$(wait_for_tags)
|
||||
if model_present "$tags_json"; then
|
||||
echo "embedding model already cached: $ollama_model"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ollama pull "$ollama_model"
|
||||
tags_json=$(fetch_tags)
|
||||
model_present "$tags_json" || {
|
||||
echo "embedding model missing after pull: $ollama_model" >&2
|
||||
exit 1
|
||||
}
|
||||
echo "embedding model ready: $ollama_model"
|
||||
Reference in New Issue
Block a user