fdd
This commit is contained in:
@@ -1,55 +1,18 @@
|
|||||||
# Utiliser l'image LocalAI officielle comme base
|
|
||||||
FROM localai/localai:latest-cpu
|
FROM localai/localai:latest-cpu
|
||||||
|
|
||||||
# Set shell
|
# Installer bashio pour Home Assistant
|
||||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
RUN apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
# Installer bashio et s6-overlay pour Home Assistant
|
curl jq && \
|
||||||
ARG BASHIO_VERSION="v0.17.0"
|
curl -J -L -o /tmp/bashio.tar.gz \
|
||||||
ARG S6_OVERLAY_VERSION="3.2.1.0"
|
"https://github.com/hassio-addons/bashio/archive/v0.16.2.tar.gz" && \
|
||||||
ARG BUILD_ARCH=amd64
|
mkdir /tmp/bashio && \
|
||||||
|
tar zxvf /tmp/bashio.tar.gz --strip 1 -C /tmp/bashio && \
|
||||||
RUN \
|
mv /tmp/bashio/lib /usr/lib/bashio && \
|
||||||
apt-get update \
|
ln -s /usr/lib/bashio/bashio /usr/bin/bashio && \
|
||||||
&& apt-get install -y --no-install-recommends \
|
rm -rf /tmp/bashio* && \
|
||||||
ca-certificates \
|
apt-get clean && \
|
||||||
curl \
|
rm -rf /var/lib/apt/lists/*
|
||||||
jq \
|
|
||||||
xz-utils \
|
|
||||||
\
|
|
||||||
&& S6_ARCH="${BUILD_ARCH}" \
|
|
||||||
&& if [ "${BUILD_ARCH}" = "i386" ]; then S6_ARCH="i686"; \
|
|
||||||
elif [ "${BUILD_ARCH}" = "amd64" ]; then S6_ARCH="x86_64"; \
|
|
||||||
elif [ "${BUILD_ARCH}" = "armv7" ]; then S6_ARCH="arm"; fi \
|
|
||||||
\
|
|
||||||
&& curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz" \
|
|
||||||
| tar -C / -Jxpf - \
|
|
||||||
&& curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_ARCH}.tar.xz" \
|
|
||||||
| tar -C / -Jxpf - \
|
|
||||||
&& curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz" \
|
|
||||||
| tar -C / -Jxpf - \
|
|
||||||
&& curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz" \
|
|
||||||
| tar -C / -Jxpf - \
|
|
||||||
\
|
|
||||||
&& mkdir -p /etc/fix-attrs.d \
|
|
||||||
&& mkdir -p /etc/services.d \
|
|
||||||
\
|
|
||||||
&& curl -J -L -o /tmp/bashio.tar.gz \
|
|
||||||
"https://github.com/hassio-addons/bashio/archive/${BASHIO_VERSION}.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 \
|
|
||||||
\
|
|
||||||
&& apt-get purge -y --auto-remove xz-utils \
|
|
||||||
&& apt-get clean \
|
|
||||||
&& rm -rf /tmp/* /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Variables d'environnement pour s6
|
|
||||||
ENV \
|
|
||||||
S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \
|
|
||||||
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \
|
|
||||||
S6_CMD_WAIT_FOR_SERVICES=1
|
|
||||||
|
|
||||||
# Variables d'environnement pour LocalAI
|
# Variables d'environnement pour LocalAI
|
||||||
ENV LOCALAI_P2P="true"
|
ENV LOCALAI_P2P="true"
|
||||||
@@ -59,32 +22,8 @@ ENV LOCALAI_ADDRESS="0.0.0.0:8080"
|
|||||||
ENV LOCALAI_CORS="true"
|
ENV LOCALAI_CORS="true"
|
||||||
ENV LOCALAI_CORS_ALLOW_ORIGINS="*"
|
ENV LOCALAI_CORS_ALLOW_ORIGINS="*"
|
||||||
|
|
||||||
# Créer le service s6 pour LocalAI
|
# Copier le script de démarrage
|
||||||
RUN mkdir -p /etc/services.d/localai
|
COPY run.sh /usr/bin/run.sh
|
||||||
COPY run.sh /etc/services.d/localai/run
|
RUN chmod +x /usr/bin/run.sh
|
||||||
RUN chmod +x /etc/services.d/localai/run
|
|
||||||
|
|
||||||
# Entrypoint s6
|
ENTRYPOINT ["/usr/bin/run.sh"]
|
||||||
ENTRYPOINT ["/init"]
|
|
||||||
|
|
||||||
# Build arguments
|
|
||||||
ARG BUILD_DATE
|
|
||||||
ARG BUILD_REF
|
|
||||||
ARG BUILD_VERSION
|
|
||||||
|
|
||||||
# Labels
|
|
||||||
LABEL \
|
|
||||||
io.hass.name="LocalAI P2P Worker" \
|
|
||||||
io.hass.description="LocalAI P2P federation worker node" \
|
|
||||||
io.hass.arch="${BUILD_ARCH}" \
|
|
||||||
io.hass.type="addon" \
|
|
||||||
io.hass.version=${BUILD_VERSION} \
|
|
||||||
maintainer="Alex <alex@example.com>" \
|
|
||||||
org.opencontainers.image.title="LocalAI P2P Worker" \
|
|
||||||
org.opencontainers.image.description="LocalAI P2P federation worker node" \
|
|
||||||
org.opencontainers.image.vendor="LocalAI Community" \
|
|
||||||
org.opencontainers.image.authors="Alex <alex@example.com>" \
|
|
||||||
org.opencontainers.image.licenses="MIT" \
|
|
||||||
org.opencontainers.image.created=${BUILD_DATE} \
|
|
||||||
org.opencontainers.image.revision=${BUILD_REF} \
|
|
||||||
org.opencontainers.image.version=${BUILD_VERSION}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: "LocalAI P2P Worker"
|
name: "LocalAI P2P Worker"
|
||||||
version: "1.0.4.9"
|
version: "1.0.4.10"
|
||||||
slug: "localai-p2p-worker"
|
slug: "localai-p2p-worker"
|
||||||
description: "LocalAI P2P federation worker node"
|
description: "LocalAI P2P federation worker node"
|
||||||
arch:
|
arch:
|
||||||
|
|||||||
@@ -1,64 +1,69 @@
|
|||||||
#!/command/with-contenv bashio
|
#!/bin/bash
|
||||||
# shellcheck shell=bash
|
|
||||||
# ==============================================================================
|
|
||||||
# LocalAI P2P Worker - Home Assistant Add-on
|
|
||||||
# ==============================================================================
|
|
||||||
|
|
||||||
bashio::log.info "Starting LocalAI P2P Worker"
|
echo "Starting LocalAI P2P Worker"
|
||||||
|
|
||||||
|
# Sourcer bashio pour utiliser les fonctions de configuration Home Assistant
|
||||||
|
source /usr/lib/bashio/bashio
|
||||||
|
|
||||||
# Lire la configuration Home Assistant
|
# Lire la configuration Home Assistant
|
||||||
TOKEN="$(bashio::config 'master_token')"
|
if [ -f /data/options.json ]; then
|
||||||
GPU_LAYERS="$(bashio::config 'gpu_layers')"
|
TOKEN="$(bashio::config 'master_token' 2>/dev/null || echo '')"
|
||||||
DEBUG="$(bashio::config 'debug')"
|
GPU_LAYERS="$(bashio::config 'gpu_layers' 2>/dev/null || echo '0')"
|
||||||
MODELS_PATH="$(bashio::config 'models_path')"
|
DEBUG="$(bashio::config 'debug' 2>/dev/null || echo 'false')"
|
||||||
THREADS="$(bashio::config 'threads')"
|
MODELS_PATH="$(bashio::config 'models_path' 2>/dev/null || echo '/share/localai/models')"
|
||||||
|
THREADS="$(bashio::config 'threads' 2>/dev/null || echo '8')"
|
||||||
|
|
||||||
bashio::log.info "Configuration loaded:"
|
echo "Master Token: $TOKEN"
|
||||||
bashio::log.info "- Master Token: ${TOKEN:0:20}..."
|
echo "GPU Layers: $GPU_LAYERS"
|
||||||
bashio::log.info "- GPU Layers: ${GPU_LAYERS}"
|
echo "Debug: $DEBUG"
|
||||||
bashio::log.info "- Debug: ${DEBUG}"
|
echo "Models Path: $MODELS_PATH"
|
||||||
bashio::log.info "- Models Path: ${MODELS_PATH}"
|
echo "Threads: $THREADS"
|
||||||
bashio::log.info "- Threads: ${THREADS}"
|
else
|
||||||
|
echo "No Home Assistant config found, using defaults"
|
||||||
|
TOKEN=""
|
||||||
|
GPU_LAYERS="0"
|
||||||
|
DEBUG="false"
|
||||||
|
MODELS_PATH="/share/localai/models"
|
||||||
|
THREADS="8"
|
||||||
|
fi
|
||||||
|
|
||||||
# Configurer le token P2P si fourni
|
# Configurer le token P2P si fourni
|
||||||
if bashio::var.has_value "${TOKEN}"; then
|
if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ] && [ "$TOKEN" != "" ]; then
|
||||||
export LOCALAI_P2P_TOKEN="${TOKEN}"
|
export LOCALAI_P2P_TOKEN="$TOKEN"
|
||||||
export P2P_TOKEN="${TOKEN}"
|
export P2P_TOKEN="$TOKEN"
|
||||||
bashio::log.info "P2P Token configured"
|
echo "P2P Token configured"
|
||||||
else
|
else
|
||||||
bashio::log.warning "No P2P token provided - will generate one"
|
echo "No P2P token provided - will generate one"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Créer le répertoire des modèles
|
# Créer le répertoire des modèles
|
||||||
bashio::log.info "Creating models directory: ${MODELS_PATH}"
|
mkdir -p "$MODELS_PATH"
|
||||||
mkdir -p "${MODELS_PATH}"
|
|
||||||
|
|
||||||
# Nettoyer les fichiers corrompus
|
# Nettoyer les fichiers corrompus
|
||||||
bashio::log.info "Cleaning corrupted files..."
|
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
|
||||||
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
|
|
||||||
|
|
||||||
# Configurer les variables d'environnement
|
# Configurer les variables d'environnement
|
||||||
export THREADS="${THREADS}"
|
export THREADS="$THREADS"
|
||||||
export OMP_NUM_THREADS="${THREADS}"
|
export OMP_NUM_THREADS="$THREADS"
|
||||||
|
|
||||||
# Configurer le debug si activé
|
# Configurer le debug si activé
|
||||||
if bashio::var.true "${DEBUG}"; then
|
if [ "$DEBUG" = "true" ]; then
|
||||||
export LOCALAI_DEBUG="true"
|
export LOCALAI_DEBUG="true"
|
||||||
export LOCALAI_LOG_LEVEL="debug"
|
export LOCALAI_LOG_LEVEL="debug"
|
||||||
bashio::log.info "Debug mode enabled"
|
echo "Debug mode enabled"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Configurer GPU layers si spécifié
|
# Configurer GPU layers si spécifié
|
||||||
if [ "${GPU_LAYERS}" -gt 0 ]; then
|
if [ "$GPU_LAYERS" -gt 0 ]; then
|
||||||
export LOCALAI_GPU_LAYERS="${GPU_LAYERS}"
|
export LOCALAI_GPU_LAYERS="$GPU_LAYERS"
|
||||||
bashio::log.info "GPU layers configured: ${GPU_LAYERS}"
|
echo "GPU layers configured: $GPU_LAYERS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Lancer LocalAI
|
# Lancer LocalAI
|
||||||
bashio::log.info "Starting LocalAI with models path: ${MODELS_PATH}"
|
echo "Starting LocalAI with models path: $MODELS_PATH"
|
||||||
exec /build/local-ai run \
|
exec /build/local-ai run \
|
||||||
--models-path="${MODELS_PATH}" \
|
--models-path="$MODELS_PATH" \
|
||||||
--threads="${THREADS}" \
|
--threads="$THREADS" \
|
||||||
--address="0.0.0.0:8080" \
|
--address="0.0.0.0:8080" \
|
||||||
--cors \
|
--cors \
|
||||||
--cors-allow-origins="*"
|
--cors-allow-origins="*"
|
||||||
|
|||||||
Reference in New Issue
Block a user