From 97114a4380597140f1b0659f5fca7849f8f1abc6 Mon Sep 17 00:00:00 2001 From: Florian THIERRY Date: Thu, 11 Jun 2026 09:19:34 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ Dockerfile | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ compose.yml | 50 ++++++++++++++++++++++++++++++++++ local-ai.bash | 35 ++++++++++++++++++++++++ requirements.txt | 4 +++ 5 files changed, 162 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 compose.yml create mode 100644 local-ai.bash create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3055662 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +ai-models +workspace \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..04ce05c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,71 @@ +# Étape 1 : build de llama.cpp +FROM ubuntu:24.04 AS builder + +LABEL maintainer="vous" \ + description="llama.cpp + Mistral-7B-Instruct (inférence locale isolée)" + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y --no-install-recommends \ + lsb-release \ + gnupg \ + ca-certificates \ + build-essential \ + cmake \ + git \ + libopenblas-dev \ + pkg-config \ + libvulkan-dev \ + vulkan-tools \ + wget + +# Télécharge et installe le Vulkan SDK +RUN wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | apt-key add - && \ + echo "deb https://packages.lunarg.com/vulkan/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/lunarg-vulkan.list && \ + apt-get update && \ + apt-get install -y vulkan-sdk && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /build +RUN git clone --depth 1 https://github.com/ggerganov/llama.cpp . + +RUN cmake -B build \ + -DLLAMA_BUILD_TESTS=OFF \ + -DLLAMA_BUILD_EXAMPLES=ON \ + -DGGML_BLAS=ON \ + -DGGML_BLAS_VENDOR=OpenBLAS \ + -DCMAKE_INSTALL_PREFIX=/install \ + -DGGML_VULKAN=ON \ + -DVulkan_GLSLC_EXECUTABLE=/usr/bin/glslc \ + && cmake --build build --config Release -j$(nproc) \ + && cmake --install build --prefix /install + +# Étape 2 : image finale (runtime minimal) +FROM ubuntu:24.04 AS runtime + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y --no-install-recommends \ + libopenblas0-openmp \ + libgomp1 \ + libvulkan1 \ + mesa-vulkan-drivers \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /install/ /usr/local/ +RUN ldconfig + +RUN useradd -m -u 1001 -s /bin/bash llama +USER llama + +WORKDIR /home/llama +RUN mkdir -p /home/llama/models + +EXPOSE 8080 + +CMD ["llama-server", \ + "--model", "/home/llama/models/mistral-7b-instruct.gguf", \ + "--host", "0.0.0.0", \ + "--port", "8080", \ + "-c", "4096", \ + "-ngl", "33"] \ No newline at end of file diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..19a5fd9 --- /dev/null +++ b/compose.yml @@ -0,0 +1,50 @@ +name: mistral-local + +services: + local-ai: + build: + context: . + dockerfile: Dockerfile + image: local-ai + container_name: local-ai + networks: + - mistral-net + ports: + - "127.0.0.1:8080:8080" + # Limites de ressources + deploy: + resources: + limits: + memory: 12g + cpus: "8" + # Sécurité + read_only: true + security_opt: + - no-new-privileges:true + tmpfs: + - /tmp:size=256m + devices: + - /dev/dri:/dev/dri + group_add: + - video + environment: + - GGML_VK_VISIBLE_DEVICES=0 + volumes: + - ./ai-models/mistral-7b-instruct.gguf:/home/llama/models/mistral-7b-instruct.gguf:ro + - ./workspace:/home/llama/workspace + + # Health check — vérifie que le serveur répond + # healthcheck: + # test: ["CMD-SHELL", "curl -sf http://localhost:8080/health || exit 1"] + # interval: 30s + # timeout: 10s + # retries: 3 + # start_period: 60s # laisser le temps au modèle de charger + +networks: + mistral-net: + name: mistral-net + driver: bridge + internal: false # pas de passerelle vers Internet + driver_opts: + com.docker.network.bridge.name: br-mistral \ No newline at end of file diff --git a/local-ai.bash b/local-ai.bash new file mode 100644 index 0000000..e36d2af --- /dev/null +++ b/local-ai.bash @@ -0,0 +1,35 @@ +#!/bin/bash + +action=$1 +args=$2 + +build_image() { + docker build $args -t local-ai . +} + +start_container() { + # Premier démarrage (build + lancement) + docker compose up --build + + # Voir les logs en temps réel + docker compose logs -f + + # Arrêter + docker compose down + + # Vérifier l'état du health check + docker compose ps +} + +main() { + if [[ $action = 'build' ]] then + build_image + elif [[ $action = 'all' ]] then + build_image + start_container + else + start_container + fi +} + +main \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c7f392c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +torch==2.2.0 --index-url https://download.pytorch.org/whl/cpu +transformers==4.40.0 +accelerate==0.27.0 +sentencepiece \ No newline at end of file