From feb7c8214e056e1a3d73a8509df20985e9bfae3e Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 30 May 2025 15:23:24 +0200 Subject: [PATCH] 4 --- localai-p2p-master/Dockerfile | 38 ++++++++++---------- localai-p2p-master/config.yaml | 6 +++- localai-p2p-master/run.sh | 66 +++++++++++----------------------- localai-p2p-worker/Dockerfile | 38 ++++++++++---------- localai-p2p-worker/config.yaml | 8 +++-- localai-p2p-worker/run.sh | 66 ++++++++++++++-------------------- 6 files changed, 94 insertions(+), 128 deletions(-) diff --git a/localai-p2p-master/Dockerfile b/localai-p2p-master/Dockerfile index f2edc24..dc60e6b 100644 --- a/localai-p2p-master/Dockerfile +++ b/localai-p2p-master/Dockerfile @@ -1,26 +1,24 @@ -FROM localai/localai:latest-cpu - +ARG BUILD_FROM +FROM $BUILD_FROM +# Installer LocalAI +RUN apk add --no-cache \ + curl \ + bash \ + && curl -Lo /usr/local/bin/local-ai \ + "https://github.com/mudler/LocalAI/releases/latest/download/local-ai-Linux-x86_64" \ + && chmod +x /usr/local/bin/local-ai +# Variables d'environnement pour LocalAI ENV LOCALAI_P2P="true" ENV LOCALAI_FEDERATED="true" +ENV LOCALAI_P2P_LISTEN_PORT="9090" +ENV LOCALAI_ADDRESS="0.0.0.0:8080" +ENV LOCALAI_CORS="true" +ENV LOCALAI_CORS_ALLOW_ORIGINS="*" -# Installer bashio pour accéder à la configuration Home Assistant -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - curl jq && \ - curl -J -L -o /tmp/bashio.tar.gz \ - "https://github.com/hassio-addons/bashio/archive/v0.16.2.tar.gz" && \ - mkdir /tmp/bashio && \ - tar zxvf /tmp/bashio.tar.gz --strip 1 -C /tmp/bashio && \ - mv /tmp/bashio/lib /usr/lib/bashio && \ - ln -s /usr/lib/bashio/bashio /usr/bin/bashio && \ - rm -rf /tmp/bashio* && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* +# Copier le script de démarrage +COPY run.sh /usr/bin/run.sh +RUN chmod +x /usr/bin/run.sh -COPY run.sh /build/custom-entrypoint.sh -RUN chmod +x /build/custom-entrypoint.sh - -# Remplacer l'entrypoint par défaut -ENTRYPOINT ["/build/custom-entrypoint.sh"] +CMD ["/usr/bin/run.sh"] diff --git a/localai-p2p-master/config.yaml b/localai-p2p-master/config.yaml index 4e344e5..3291155 100644 --- a/localai-p2p-master/config.yaml +++ b/localai-p2p-master/config.yaml @@ -1,10 +1,12 @@ name: "LocalAI P2P Master" -version: "1.0.1" +version: "1.0.2" slug: "localai-p2p-master" description: "LocalAI with P2P federation support (master node with GPU)" url: "https://git.carriere.cloud/alex/hass-addons/tree/main/localai-p2p-master" arch: - amd64 +build_from: + amd64: "ghcr.io/hassio-addons/base/amd64:15.0.7" host_network: true startup: application ingress: true @@ -36,7 +38,9 @@ options: gpu_layers: 99 debug: false models_path: "/share/localai/models" + threads: 8 schema: gpu_layers: "int(0,)" debug: "bool?" models_path: "str?" + threads: "int(1,)" diff --git a/localai-p2p-master/run.sh b/localai-p2p-master/run.sh index 524e822..46a236c 100644 --- a/localai-p2p-master/run.sh +++ b/localai-p2p-master/run.sh @@ -1,51 +1,27 @@ -#!/bin/bash +#!/usr/bin/with-contenv bashio -# Forcer l'utilisation de la configuration Home Assistant -echo "Using Home Assistant configuration" +# Les variables d'environnement sont automatiquement disponibles depuis les options +echo "Starting LocalAI P2P Master" +echo "GPU Layers: $(bashio::config 'gpu_layers')" +echo "Models Path: $(bashio::config 'models_path')" -# Vérifier que bashio est disponible -if [ -f /usr/bin/bashio ]; then - echo "DEBUG: bashio found, reading configuration" - GPU_LAYERS="$(bashio config gpu_layers 2>/dev/null || echo '99')" - TOKEN="$(bashio config master_token 2>/dev/null || echo '')" - MODELS_PATH="$(bashio config models_path 2>/dev/null || echo '/share/localai/models')" -else - echo "DEBUG: bashio not found, using defaults" - GPU_LAYERS="99" - TOKEN="" - MODELS_PATH="/share/localai/models" -fi - -echo "DEBUG: GPU_LAYERS=$GPU_LAYERS" -echo "DEBUG: TOKEN from config: '$TOKEN'" -echo "DEBUG: MODELS_PATH=$MODELS_PATH" - -# Forcer l'utilisation du token si fourni -if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ] && [ "$TOKEN" != "" ]; then - echo "DEBUG: Setting LOCALAI_P2P_TOKEN to: $TOKEN" - export LOCALAI_P2P_TOKEN="$TOKEN" - export P2P_TOKEN="$TOKEN" -else - echo "DEBUG: No valid token provided in configuration" -fi - -echo "DEBUG: LOCALAI_P2P_TOKEN is set to: '$LOCALAI_P2P_TOKEN'" -echo "DEBUG: P2P_TOKEN is set to: '$P2P_TOKEN'" - -# Créer le répertoire des modèles s'il n'existe pas +# Créer le répertoire des modèles +MODELS_PATH="$(bashio::config 'models_path')" mkdir -p "$MODELS_PATH" -# Nettoyer les fichiers de configuration corrompus -echo "DEBUG: Cleaning corrupted config files in $MODELS_PATH" -find "$MODELS_PATH" -name "*.yaml" -exec grep -l "#!/usr/bin/with-contenv bashio\|mapping values are not allowed in this context" {} \; | while read file; do - echo "DEBUG: Removing corrupted file: $file" - rm -f "$file" -done 2>/dev/null || true +# Nettoyer les fichiers corrompus +find "$MODELS_PATH" -name "*.yaml" -exec grep -l "#!/usr/bin/with-contenv bashio\|mapping values are not allowed in this context" {} \; 2>/dev/null | xargs rm -f 2>/dev/null || true -# Définir les variables d'environnement pour LocalAI -export THREADS="${THREADS:-8}" -export OMP_NUM_THREADS="${OMP_NUM_THREADS:-8}" +# Configurer les threads +export THREADS="$(bashio::config 'threads' || echo '8')" +export OMP_NUM_THREADS="$THREADS" -# Lancer LocalAI avec nos paramètres -echo "DEBUG: Starting LocalAI with models-path=$MODELS_PATH, threads=$THREADS" -exec /build/local-ai run --models-path="$MODELS_PATH" --threads="$THREADS" --address="0.0.0.0:8080" --cors --cors-allow-origins="*" +# Lancer LocalAI (master génère automatiquement un token) +echo "Starting LocalAI Master with models path: $MODELS_PATH" +echo "P2P Token will be generated automatically" +exec /usr/local/bin/local-ai run \ + --models-path="$MODELS_PATH" \ + --threads="$THREADS" \ + --address="0.0.0.0:8080" \ + --cors \ + --cors-allow-origins="*" diff --git a/localai-p2p-worker/Dockerfile b/localai-p2p-worker/Dockerfile index f2edc24..dc60e6b 100644 --- a/localai-p2p-worker/Dockerfile +++ b/localai-p2p-worker/Dockerfile @@ -1,26 +1,24 @@ -FROM localai/localai:latest-cpu - +ARG BUILD_FROM +FROM $BUILD_FROM +# Installer LocalAI +RUN apk add --no-cache \ + curl \ + bash \ + && curl -Lo /usr/local/bin/local-ai \ + "https://github.com/mudler/LocalAI/releases/latest/download/local-ai-Linux-x86_64" \ + && chmod +x /usr/local/bin/local-ai +# Variables d'environnement pour LocalAI ENV LOCALAI_P2P="true" ENV LOCALAI_FEDERATED="true" +ENV LOCALAI_P2P_LISTEN_PORT="9090" +ENV LOCALAI_ADDRESS="0.0.0.0:8080" +ENV LOCALAI_CORS="true" +ENV LOCALAI_CORS_ALLOW_ORIGINS="*" -# Installer bashio pour accéder à la configuration Home Assistant -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - curl jq && \ - curl -J -L -o /tmp/bashio.tar.gz \ - "https://github.com/hassio-addons/bashio/archive/v0.16.2.tar.gz" && \ - mkdir /tmp/bashio && \ - tar zxvf /tmp/bashio.tar.gz --strip 1 -C /tmp/bashio && \ - mv /tmp/bashio/lib /usr/lib/bashio && \ - ln -s /usr/lib/bashio/bashio /usr/bin/bashio && \ - rm -rf /tmp/bashio* && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* +# Copier le script de démarrage +COPY run.sh /usr/bin/run.sh +RUN chmod +x /usr/bin/run.sh -COPY run.sh /build/custom-entrypoint.sh -RUN chmod +x /build/custom-entrypoint.sh - -# Remplacer l'entrypoint par défaut -ENTRYPOINT ["/build/custom-entrypoint.sh"] +CMD ["/usr/bin/run.sh"] diff --git a/localai-p2p-worker/config.yaml b/localai-p2p-worker/config.yaml index d718d71..98a09d8 100644 --- a/localai-p2p-worker/config.yaml +++ b/localai-p2p-worker/config.yaml @@ -1,9 +1,11 @@ name: "LocalAI P2P Worker" -version: "1.0.3.9" # Incrémentez aussi la version -slug: "localai-p2p-worker" # ⬅️ IMPORTANT : doit correspondre au nom du dossier +version: "1.0.4" +slug: "localai-p2p-worker" description: "LocalAI P2P federation worker node" arch: - amd64 +build_from: + amd64: "ghcr.io/hassio-addons/base/amd64:15.0.7" host_network: true # OBLIGATOIRE pour P2P startup: application ingress: true @@ -32,8 +34,10 @@ options: gpu_layers: 0 debug: false models_path: "/share/localai/models" + threads: 8 schema: master_token: str gpu_layers: "int(0,)" debug: "bool?" models_path: "str?" + threads: "int(1,)" diff --git a/localai-p2p-worker/run.sh b/localai-p2p-worker/run.sh index 283febd..3d3e494 100644 --- a/localai-p2p-worker/run.sh +++ b/localai-p2p-worker/run.sh @@ -1,51 +1,37 @@ -#!/bin/bash +#!/usr/bin/with-contenv bashio -# Forcer l'utilisation de la configuration Home Assistant -echo "Using Home Assistant configuration" +# Les variables d'environnement sont automatiquement disponibles depuis les options +echo "Starting LocalAI P2P Worker" +echo "Master Token: $(bashio::config 'master_token')" +echo "GPU Layers: $(bashio::config 'gpu_layers')" +echo "Models Path: $(bashio::config 'models_path')" -# Vérifier que bashio est disponible -if [ -f /usr/bin/bashio ]; then - echo "DEBUG: bashio found, reading configuration" - GPU_LAYERS="$(bashio config gpu_layers 2>/dev/null || echo '0')" - TOKEN="$(bashio config master_token 2>/dev/null || echo '')" - MODELS_PATH="$(bashio config models_path 2>/dev/null || echo '/share/localai/models')" -else - echo "DEBUG: bashio not found, using defaults" - GPU_LAYERS="0" - TOKEN="" - MODELS_PATH="/share/localai/models" -fi - -echo "DEBUG: GPU_LAYERS=$GPU_LAYERS" -echo "DEBUG: TOKEN from config: '$TOKEN'" -echo "DEBUG: MODELS_PATH=$MODELS_PATH" - -# Forcer l'utilisation du token si fourni -if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ] && [ "$TOKEN" != "" ]; then - echo "DEBUG: Setting LOCALAI_P2P_TOKEN to: $TOKEN" +# Configurer le token P2P si fourni +TOKEN="$(bashio::config 'master_token')" +if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ]; then export LOCALAI_P2P_TOKEN="$TOKEN" export P2P_TOKEN="$TOKEN" + echo "P2P Token configured" else - echo "DEBUG: No valid token provided in configuration" + echo "No P2P token provided - will generate one" fi -echo "DEBUG: LOCALAI_P2P_TOKEN is set to: '$LOCALAI_P2P_TOKEN'" -echo "DEBUG: P2P_TOKEN is set to: '$P2P_TOKEN'" - -# Créer le répertoire des modèles s'il n'existe pas +# Créer le répertoire des modèles +MODELS_PATH="$(bashio::config 'models_path')" mkdir -p "$MODELS_PATH" -# Nettoyer les fichiers de configuration corrompus -echo "DEBUG: Cleaning corrupted config files in $MODELS_PATH" -find "$MODELS_PATH" -name "*.yaml" -exec grep -l "#!/usr/bin/with-contenv bashio\|mapping values are not allowed in this context" {} \; | while read file; do - echo "DEBUG: Removing corrupted file: $file" - rm -f "$file" -done 2>/dev/null || true +# Nettoyer les fichiers corrompus +find "$MODELS_PATH" -name "*.yaml" -exec grep -l "#!/usr/bin/with-contenv bashio\|mapping values are not allowed in this context" {} \; 2>/dev/null | xargs rm -f 2>/dev/null || true -# Définir les variables d'environnement pour LocalAI -export THREADS="${THREADS:-8}" -export OMP_NUM_THREADS="${OMP_NUM_THREADS:-8}" +# Configurer les threads +export THREADS="$(bashio::config 'threads' || echo '8')" +export OMP_NUM_THREADS="$THREADS" -# Lancer LocalAI avec nos paramètres -echo "DEBUG: Starting LocalAI with models-path=$MODELS_PATH, threads=$THREADS" -exec /build/local-ai run --models-path="$MODELS_PATH" --threads="$THREADS" --address="0.0.0.0:8080" --cors --cors-allow-origins="*" +# Lancer LocalAI +echo "Starting LocalAI with models path: $MODELS_PATH" +exec /usr/local/bin/local-ai run \ + --models-path="$MODELS_PATH" \ + --threads="$THREADS" \ + --address="0.0.0.0:8080" \ + --cors \ + --cors-allow-origins="*"