diff --git a/.env b/.env new file mode 100644 index 0000000..7a7c0f9 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +_APP_EMBEDDING_MODELS=embeddinggemma \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3ee539c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +--- +version: '3.8' + +services: + ollama: + build: + context: . + args: + MODELS: ${_APP_EMBEDDING_MODELS:-embeddinggemma} + # duration to keep model in memory + OLLAMA_KEEP_ALIVE: 24h + restart: unless-stopped + ports: + - "11434:11434" + volumes: + - appwrite-models:/root/.ollama + +volumes: + appwrite-models: \ No newline at end of file diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..186a014 --- /dev/null +++ b/dockerfile @@ -0,0 +1,23 @@ +FROM ollama/ollama:0.12.7 + +# Preload specific models +ARG MODELS +# needed to set in the environment +ARG OLLAMA_KEEP_ALIVE +ENV OLLAMA_KEEP_ALIVE=${OLLAMA_KEEP_ALIVE:-24h} + +# Pre-pull models at build time for Docker layer caching +RUN ollama serve & \ + sleep 5 && \ + for m in $MODELS; do \ + echo "Pulling model $m..."; \ + ollama pull $m || exit 1; \ + done && \ + pkill ollama + +# Expose Ollama default port +EXPOSE 11434 + +# On container start, quickly ensure models exist (no re-download unless missing) +ENTRYPOINT ["/bin/bash", "-c", "(sleep 2; for m in $MODELS; do ollama list | grep -q $m || ollama pull $m; done) & exec ollama $0"] +CMD ["serve"] \ No newline at end of file